| 84 | """ |
| 85 | def __init__(self, shared_data): |
| 86 | self.shared_data = shared_data |
| 87 | |
| 88 | # self.scan is (re)built by load_scan_file() before every use, so it is |
| 89 | # not built here. That keeps pandas off the startup path: the connector |
| 90 | # is instantiated at boot by the orchestrator, but pandas is only imported |
| 91 | # when an attack action actually runs (saves ~44 MB RSS; measured 111MB->67MB startup on this box). |
| 92 | self.scan = None |
| 93 | |
| 94 | self.users = open(shared_data.usersfile, "r").read().splitlines() |
| 95 | self.passwords = open(shared_data.passwordsfile, "r").read().splitlines() |
| 96 | |
| 97 | self.sshfile = shared_data.sshfile |
| 98 | if not os.path.exists(self.sshfile): |
| 99 | logger.info(f"File {self.sshfile} does not exist. Creating...") |
| 100 | with open(self.sshfile, "w") as f: |
| 101 | f.write("MAC Address,IP Address,Hostname,User,Password,Port\n") |
| 102 | self.results = [] # Successful credentials for the current bruteforce run |
| 103 | self._pending_results = [] # Entries waiting to be flushed to disk |
| 104 | self.console = Console() |
| 105 | |
| 106 | def load_scan_file(self): |
| 107 | """ |
| 108 | Load from SQLite database and filter for SSH ports. |
| 109 | """ |
| 110 | import pandas as pd # lazy: keeps ~44MB pandas out of RAM until an attack action runs |
| 111 | data = self.shared_data.read_data() |
| 112 | self.scan = pd.DataFrame(data) |
| 113 | if "Ports" not in self.scan.columns: |
| 114 | self.scan["Ports"] = None |
| 115 | # Ensure Ports column is string type before using .str accessor |