示例#1
0
def target_register(args):

    # init target queue
    conf.target = set()

    # single target to queue
    if args.target_single:
        msg = '[+] Load target : {}'.format(args.target_single)
        colorprint.green(msg)
        conf.target.add(args.target_single)

    # file target to queue
    if args.target_file:
        if not os.path.isfile(args.target_file):
            msg = '[-] TargetFile not found: {}'.format(args.target_file)
            colorprint.red(msg)
            sys.exit()
        msg = '[+] Load targets from : {}'.format(args.target_file)
        colorprint.green(msg)
        with open(args.target_file, 'r', encoding='utf8') as f:
            targets = f.readlines()
            for target in targets:
                conf.target.add(target.strip('\n'))

    # range of ip target to queue .e.g. 192.168.1.1-192.168.1.100
    if args.target_range:
        try:
            lists = gen_ip(args.target_range)
            if (len(lists)) > 100000:
                warn_msg = "[*] Loading {} targets, Maybe it's too much, continue? [y/N]".format(
                    (len(lists)))
                colorprint.cyan(warn_msg, end='')
                flag = input()
                if flag in ('Y', 'y', 'yes', 'YES', 'Yes'):
                    pass
                else:
                    msg = '[-] User quit!'
                    colorprint.cyan(msg)
                    sys.exit()

            msg = '[+] Load targets from : {}'.format(args.target_range)
            colorprint.green(msg)

            # save to conf
            for target in lists:
                conf.target.add(target)

        except:  # Exception as e:
            # colorprint.red(e)
            err_msg = "Invalid input in [-iR], Example: -iR 192.168.1.1-192.168.1.100"
            colorprint.red(err_msg)
            sys.exit()

    # ip/mask e.g. 192.168.1.2/24
    if args.target_network:
        try:
            ip_range = ipaddress.ip_network(args.target_network, strict=False)
            for ip in ip_range.hosts():
                conf.target.add(ip)

        except:  #  Exception as e:
            # colorprint.red(e)
            msg = "[-] Invalid input in [-iN], Example: -iN 192.168.1.0/24"
            colorprint.red(msg)
            sys.exit()

        msg = '[+] Load targets from : {}'.format(args.target_network)
        colorprint.green(msg)

    # set search limit of api
    if args.api_limit <= 0:
        err_msg = 'Invalid input in [-limit] (can not be negative number)'
        colorprint.red(err_msg)
        sys.exit()
    if args.api_limit > 10000:
        warn_msg = "Loading {} targets, Maybe it's too much, continue? [y/N]".format(
            args.api_limit)
        colorprint.cyan(warn_msg)
        flag = input()
        if flag in ('Y', 'y', 'yes', 'YES', 'Yes'):
            pass
        else:
            msg = 'User quit!'
            colorprint.cyan(msg)
            sys.exit()
    conf.limit = args.api_limit

    # set search offset of api
    if args.api_offset < 0:
        warn_msg = "Wrong offset setting, would you like to set it to 0? [y/N]".format(
            args.api_limit)
        colorprint.cyan(warn_msg)
        flag = input()
        if flag in ('Y', 'y', 'yes', 'YES', 'Yes'):
            args.api_offset = 0
        else:
            msg = 'User quit!'
            colorprint.cyan(msg)
            sys.exit()
    conf.offset = args.api_offset

    if args.zoomeye_dork:
        from lib.api.zoomeye.zoomeye import handle_zoomeye
        # verify search_type for zoomeye
        if args.search_type not in ['web', 'host']:
            msg = '[-] Invalid value in [--search-type], show usage with [-h]'
            colorprint.red(msg)
            sys.exit()
        conf.search_type = args.search_type
        handle_zoomeye(query=args.zoomeye_dork,
                       limit=conf.limit,
                       type=conf.search_type,
                       offset=conf.offset)

    if args.fofa_dork:
        from lib.api.fofa.fofa import handle_fofa
        handle_fofa(query=args.fofa_dork, limit=conf.limit, offset=conf.offset)

    if args.shodan_dork:
        from lib.api.shodan.shodan import handle_shodan
        handle_shodan(query=args.shodan_dork,
                      limit=conf.limit,
                      offset=conf.offset)

    if args.censys_dork:
        from lib.api.censys.censys import handle_censys
        handle_censys(query=args.censys_dork,
                      limit=conf.limit,
                      offset=conf.offset)

    # verify targets number
    if len(conf.target) == 0:
        err_msg = 'No targets found\nPlease load targets with [-iU|-iF|-iR|-iN] or use API with [-aZ|-aS|-aG|-aF]'
        colorprint.red(err_msg)
        sys.exit()
示例#2
0
def TargetRegister(args):
    msg = '[*] Initialize targets...'
    outputscreen.warning(msg)

    # init target queue
    conf.target = queue.Queue()

    # single target to queue
    if args.target_single:
        msg = '[+] Load target : %s' % args.target_single
        outputscreen.success(msg)
        conf.target.put(args.target_single)

    # file target to queue
    elif args.target_file:
        if not os.path.isfile(args.target_file):
            msg = '[-] TargetFile not found: %s' % args.target_file
            outputscreen.error(msg)
            sys.exit()
        msg = '[+] Load targets from : %s' % args.target_file
        outputscreen.success(msg)
        with open(args.target_file, 'r', encoding='utf8') as f:
            targets = f.readlines()
            for target in targets:
                conf.target.put(target.strip('\n'))

    # range of ip target to queue .e.g. 192.168.1.1-192.168.1.100
    elif args.target_range:
        try:
            lists = gen_ip(args.target_range)
            if (len(lists)) > 100000:
                warnmsg = "[*] Loading %d targets, Maybe it's too much, continue? [y/N]" % (
                    len(lists))
                outputscreen.warning(warnmsg)
                flag = input()
                if flag in ('Y', 'y', 'yes', 'YES', 'Yes'):
                    pass
                else:
                    msg = '[-] User quit!'
                    outputscreen.warning(msg)
                    sys.exit()

            msg = '[+] Load targets from : %s' % args.target_range
            outputscreen.success(msg)

            # save to conf
            for target in lists:
                conf.target.put(target)
        except:
            helpmsg = "Invalid input in [-iR], Example: -iR 192.168.1.1-192.168.1.100"
            outputscreen.error(helpmsg)
            sys.exit()

    # ip/mask e.g. 192.168.1.2/24
    elif args.target_network:
        try:
            # get 192.168.1.2 -->192.168.1.0
            ip_format = args.target_network.split('/')
            ip_str = IP(ip_format[0]).strBin()
            ip_str = ip_str[0:int(ip_format[1])] + '0' * (32 -
                                                          int(ip_format[1]))
            ip = "%s.%s.%s.%s" % (
                str(int(ip_str[0:8], 2)), str(int(ip_str[8:16], 2)),
                str(int(ip_str[16:24], 2)), str(int(ip_str[24:32], 2)))

            ip_range = IP('%s/%s' % (ip, ip_format[1]))

            msg = '[+] Load targets from : %s' % args.target_network
            outputscreen.success(msg)

            for i in ip_range:
                conf.target.put(i)
        except:
            msg = "[-] Invalid input in [-iN], Example: -iN 192.168.1.0/24"
            outputscreen.error(msg)
            sys.exit()

    else:
        # set search limit of api
        if args.api_limit <= 0:
            errormsg = 'Invalid input in [-limit] (can not be negative number)'
            outputscreen.error(errormsg)
            sys.exit()
        elif args.api_limit > 100000:
            warnmsg = "Loading %d targets, Maybe it's too much, continue? [y/N]" % (
                len(lists))
            outputscreen.warning(warnmsg)
            flag = input()
            if flag in ('Y', 'y', 'yes', 'YES', 'Yes'):
                pass
            else:
                msg = 'User quit!'
                outputscreen.warning(msg)
                sys.exit()
        conf.limit = args.api_limit

        # set search offset of api
        conf.offset = args.api_offset

        if args.zoomeye_dork:
            # verify search_type for zoomeye
            if args.search_type not in ['web', 'host']:
                msg = '[-] Invalid value in [--search-type], show usage with [-h]'
                outputscreen.error(msg)
                sys.exit()
            conf.search_type = args.search_type
            handle_zoomeye(query=args.zoomeye_dork,
                           limit=conf.limit,
                           type=conf.search_type,
                           offset=conf.offset)

        elif args.fofa_dork:
            handle_fofa(query=args.fofa_dork,
                        limit=conf.limit,
                        offset=conf.offset)

        elif args.shodan_dork:
            handle_shodan(query=args.shodan_dork,
                          limit=conf.limit,
                          offset=conf.offset)

        elif args.google_dork:
            conf.google_proxy = args.google_proxy
            handle_google(query=args.google_dork,
                          limit=conf.limit,
                          offset=conf.offset)

    # verify targets number
    if conf.target.qsize() == 0:
        errormsg = msg = 'No targets found\nPlease load targets with [-iU|-iF|-iR|-iN] or use API with [-aZ|-aS|-aG|-aF]'
        outputscreen.error(errormsg)
        sys.exit()