0

我试图--verbose在我的脚本中实现该选项。这个想法是打开额外的错误打印等以进行调试,但由于某种原因它似乎不起作用。我尝试了该if verbose声明的一些变体,但没有任何乐趣。我希望有人能指出我正确的方向吗?

命令行示例

./attack2.py -f wordfile.txt -d google.com --verbose 1

命令行输出

unknown@ubuntu:~$ ./attack2.py -f wordfile.txt -d google.com --verbose 1
173.194.34.149
173.194.34.130
unknown@ubuntu:~$

ARG 打印

{'--domain': 'google.com',
 '--file': 'wordfile.txt',
 '--help': False,
 '--thread': False,
 '--verbose': True,
 '10': False,
 '<1>': '1'}

代码

#!/usr/bin/python

"""
Description:

Basic Domain bruteforcer

Usage:
  attack2.py (-f <file>) (-d <domain>) [-t 10] [-v <1>]
  attack2.py -h | --help

Arguments:
  -f --file File to read potential Sub-domains from. (Required)
  -d --domain Domain to bruteforce. (Required)
Options:
  -h --help     Show this screen.
  -p --proxy    Proxy address and port. [default: http://127.0.0.1:8080] (Optional)
  -t --thread   Thread count. (Optional)
  -v --verbose  Turn debug on. (Optional)
"""
import socket
from docopt import docopt


def fread(dwords):
        flist = open(dwords).readlines()
        return [s.replace('\n', '.') for s in flist]


def subcheck(subdomain, domain, verbose):

        vdomain = {}
        for sub in subdomain:
                try:
                        check = socket.gethostbyname(sub + domain)
                        vdomain[sub + domain] = check

                except socket.gaierror, e:
                        if verbose == True:
                                print arguments
                                print e, sub + domain
                        else:
                                pass
        return vdomain

if __name__ == "__main__":
        arguments = docopt(__doc__, version='0.1a')

        fread(arguments['--file'])
        returned_list = fread(arguments['--file'])
        returned_domains = subcheck(returned_list, arguments['--domain'], ['--verbose'])
4

2 回答 2

1

函数中的以下行subcheck

returned_domains = subcheck(returned_list, arguments['--domain'], ['--verbose'])

应该

returned_domains = subcheck(returned_list, arguments['--domain'], arguments['--verbose'])

您忘记verbose从参数传递参数,而是传递了一个list

于 2014-03-07T12:05:07.983 回答
0

看来我错误地调用了子检查。

代码应该是这样的

工作代码

if __name__ == "__main__":
        arguments = docopt(__doc__, version='0.1a')

        fread(arguments['--file'])
        returned_list = fread(arguments['--file'])
        returned_domains = subcheck(returned_list, arguments['--domain'], arguments['--verbose'])
        print returned_domains
于 2014-03-07T12:11:57.057 回答