MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / connect_sql

Method connect_sql

actions/steal_data_sql.py:34–48  ·  view source on GitHub ↗

Establish a MySQL connection using SQLAlchemy.

(self, ip, username, password, database=None)

Source from the content-addressed store, hash-verified

32
33 def connect_sql(self, ip, username, password, database=None):
34 """
35 Establish a MySQL connection using SQLAlchemy.
36 """
37 try:
38 # Si aucune base n'est spécifiée, on se connecte sans base
39 db_part = f"/{database}" if database else ""
40 connection_str = f"mysql+pymysql://{username}:{password}@{ip}:3306{db_part}"
41 engine = create_engine(connection_str, connect_args={"connect_timeout": 10})
42 self.sql_connected = True
43 logger.info(f"Connected to {ip} via SQL with username {username}" + (f" to database {database}" if database else ""))
44 return engine
45 except Exception as e:
46 logger.error(f"SQL connection error for {ip} with user '{username}' and password '{password}'" + (f" to database {database}" if database else "") + f": {e}")
47 return None
48
49 def find_tables(self, engine):
50 """
51 Find all tables in all databases, excluding system databases.

Callers 1

executeMethod · 0.95

Calls 2

infoMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected