def analysis(targets): range_flag = True if (sys.argv[2] == '--range' or sys.argv[2] == '-r') else False tmp = open('tmp_target', 'w') tmp.write('') tmp.close() for target in targets: if targets[target] == 'SINGLE_IPv4': attack(target,range_flag) elif targets[target] == 'RANGE_IPv4' or targets[target] == 'CIDR_IPv4': IPs = IPRange(target) if len(IPs) is 1: for IP in IPs: attack(IP, range_flag) else: for IPR in IPs: for IP in IPR: attack(IP, range_flag) elif targets[target] == 'DOMAIN': print 'finding subdomains ...' tmp = open('tmp', 'w') tmp.write('') tmp.close() tmp = os.popen('lib\\sublist3r\\sublist3r.py -d ' + target + ' -o tmp').read() subs = open('tmp').read().rsplit() for sub in subs: attack(sub, range_flag,True) else: pass return 0
def attack_ip(IP): IPs = IPRange(getIPRange(IP)) if len(IPs) is 1: for IP in IPs: scan_flag = scan_check(IP) if scan_flag is True: log_it(IP) start_attack(IP, False) else: for IPR in IPs: for IP in IPR: scan_flag = scan_check(IP) if scan_flag is True: log_it(IP) start_attack(IP, False)
def analysis( targets, check_ranges, check_subdomains, subs_temp, range_temp, log_in_file, time_sleep, language, verbose_level, retries, socks_proxy, enumerate_flag, ): """ analysis and calulcate targets. Args: targets: targets check_ranges: check IP range flag check_subdomains: check subdomain flag subs_temp: subdomain temp filename range_temp: IP range tmp filename log_in_file: output filename time_sleep: time to sleep language: language verbose_level: verbose level number retries: retries number socks_proxy: socks proxy enumerate_flag: enumerate flag Returns: a generator """ __log_into_file(range_temp, "a", "", language) __log_into_file(subs_temp, "a", "", language) for target in targets: if target_type(target) == "SINGLE_IPv4": if check_ranges: if not enumerate_flag: info(messages(language, "checking_range").format(target)) IPs = IPRange(getIPRange(target), range_temp, language) if type(IPs) == netaddr.ip.IPNetwork: for IPm in IPs: yield IPm elif type(IPs) == list: for IPm in IPs: for IP in IPm: yield IP else: if not enumerate_flag: info(messages(language, "target_submitted").format(target)) yield target elif target_type(target) == "SINGLE_IPv6": yield target elif (target_type(target) == "RANGE_IPv4" or target_type(target) == "CIDR_IPv4"): IPs = IPRange(target, range_temp, language) if not enumerate_flag: info(messages(language, "checking").format(target)) if type(IPs) == netaddr.ip.IPNetwork: for IPm in IPs: yield IPm elif type(IPs) == list: for IPm in IPs: for IP in IPm: yield IP elif target_type(target) == "DOMAIN": if check_subdomains: if check_ranges: if enumerate_flag: info(messages(language, "checking").format(target)) sub_domains = (json.loads(open(subs_temp).read()) if len(open(subs_temp).read()) > 2 else __get_subs(target, 3, "", 0, language, 0, socks_proxy, 3, 0, 0)) if len(open(subs_temp).read()) == 0: __log_into_file(subs_temp, "a", json.dumps(sub_domains), language) if target not in sub_domains: sub_domains.append(target) for target in sub_domains: if not enumerate_flag: info( messages(language, "target_submitted").format(target)) yield target n = 0 err = 0 IPs = [] while True: try: IPs.append(socket.gethostbyname(target)) err = 0 n += 1 if n == 12: break except Exception: err += 1 if err == 3 or n == 12: break IPz = list(set(IPs)) for IP in IPz: if not enumerate_flag: info( messages(language, "checking_range").format(IP)) IPs = IPRange(getIPRange(IP), range_temp, language) if type(IPs) == netaddr.ip.IPNetwork: for IPm in IPs: yield IPm elif type(IPs) == list: for IPm in IPs: for IPn in IPm: yield IPn else: if enumerate_flag: info(messages(language, "checking").format(target)) sub_domains = (json.loads(open(subs_temp).read()) if len(open(subs_temp).read()) > 2 else __get_subs(target, 3, "", 0, language, 0, socks_proxy, 3, 0, 0)) if len(open(subs_temp).read()) == 0: __log_into_file(subs_temp, "a", json.dumps(sub_domains), language) if target not in sub_domains: sub_domains.append(target) for target in sub_domains: if not enumerate_flag: info( messages(language, "target_submitted").format(target)) yield target else: if check_ranges: if not enumerate_flag: info(messages(language, "checking").format(target)) yield target n = 0 err = 0 IPs = [] while True: try: IPs.append(socket.gethostbyname(target)) err = 0 n += 1 if n == 12: break except Exception: err += 1 if err == 3 or n == 12: break IPz = list(set(IPs)) for IP in IPz: if not enumerate_flag: info( messages(language, "checking_range").format(IP)) IPs = IPRange(getIPRange(IP), range_temp, language) if type(IPs) == netaddr.ip.IPNetwork: for IPm in IPs: yield IPm elif type(IPs) == list: for IPm in IPs: for IPn in IPm: yield IPn else: if not enumerate_flag: info( messages(language, "target_submitted").format(target)) yield target elif target_type(target) == "HTTP": if not enumerate_flag: info(messages(language, "checking").format(target)) yield target if check_ranges: if "http://" == target[:7].lower(): target = target[7:].rsplit("/")[0] if "https://" == target[:8].lower(): target = target[8:].rsplit("/")[0] yield target IPs = [] while True: try: IPs.append(socket.gethostbyname(target)) err = 0 n += 1 if n == 12: break except Exception: err += 1 if err == 3 or n == 12: break IPz = list(set(IPs)) for IP in IPz: if not enumerate_flag: info(messages(language, "checking_range").format(IP)) IPs = IPRange(getIPRange(IP), range_temp, language) if type(IPs) == netaddr.ip.IPNetwork: for IPm in IPs: yield IPm elif type(IPs) == list: for IPm in IPs: for IPn in IPm: yield IPn else: __die_failure(messages(language, "unknown_target").format(target))