Beispiel #1
0
def main():
    is_web = False
    ut_list = ''
    target = ''
    url = ''
    lnumber = 10
    productname = {}
    script = []
    output = 'output.txt'

    try:
        opts, args = getopt.getopt(sys.argv[1:], 'wc:u:t:l:p:s:f:o:h', [
            'web', 'cookie', 'url', 'target', 'lnumber', 'port', 'script',
            'file', 'output', 'help'
        ])
    except getopt.GetoptError as err:
        print str(err)
        usage()

    for o, a in opts:
        if o in ('-h', '--help'):
            usage()
        elif o in ('-o', '--output'):
            output = str(a).strip()
        elif o in ('-f', '--file'):
            ut_list = str(a).strip()
        elif o in ('-s', '--script'):
            script = str(a).strip().split(' ')
        elif o in ('-t', '--target'):
            target = str(a).strip()
        elif o in ('-l', '--lnumber'):
            try:
                lnumber = string.atoi(str(a), 10)
            except:
                print "lnumber wrong"
                sys.exit(1)
        elif o in ('-u', '--url'):
            url = str(a).strip()
        elif o in ('-c', '--cookie'):
            productname['cookie'] = str(a).strip()
        elif o in ('-w', '--web'):
            is_web = True
        else:
            assert False, "Unhandled Option"

    if script == []:
        for one in os.listdir('script'):
            if '__init__.py' != one:
                script.append(str(one))

    result = []
    print '[***] start.'
    if ut_list != '':
        que = Queue.Queue()
        lock = threading.Lock()
        lthreads = []
        f = open(ut_list, 'r')
        utlist = f.readlines()
        f.close()
        for item in utlist:
            if item == '\n':
                continue
            que.put(item[:-1], True, None)
        for i in xrange(lnumber):
            lthreads.append(ScanThread(result, que, is_web, script, lock))
        for l in lthreads:
            l.start()
        for l in lthreads:
            l.join()
    elif url != '' and is_web:
        target_ip, target_port, productname['path'] = handle_url(url)
        print '[**] test', target_ip
        result = scan(script, target_ip, target_port, productname)
    else:
        if target == '':
            print '[^] please use -t, or use -w and -u.'
            sys.exit(1)
        target_ip, target_port = handle_target(target)
        print '[**] test', target_ip
        result = scan(script, target_ip, target_port)

    print '[***] done.'
    out(output, result)
    print '[****] result is in {output}.'.format(output=output)
    return