我试图从与参数值连接的子域列表中执行socket.gethostbyname
但是收到错误。我不确定循环是否正常工作,第一次尝试不是一个有效的子域+域。或者它根本不起作用?
错误
Traceback (most recent call last):
File "./attack2.py", line 40, in <module>
print subcheck(returned_list, arguments['--domain'])
File "./attack2.py", line 31, in subcheck
socket.gethostbyname(sub + domain)
socket.gaierror: [Errno -2] Name or service not known
CODE
#!/usr/bin/python
"""
Description:
Basic Domain bruteforcer
Usage:
attack2.py (-f <file>) (-d <domain>) [-t 10] [-v]
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):
for sub in subdomain:
socket.gethostbyname(sub + domain)
return output
if __name__ == "__main__":
arguments = docopt(__doc__, version='0.1a')
print arguments
print fread(arguments['--file'])
returned_list = fread(arguments['--file'])
print subcheck(returned_list, arguments['--domain'])
新的def子检查代码
def subcheck(subdomain, domain):
for sub in subdomain:
try:
#print "%s %d" % (sub+domain,len(sub+domain))
print socket.gethostbyname(sub + domain)
except:
print "Some error"
新输出
173.194.34.150
173.194.34.137
Some error
Some error
None
答案 0 :(得分:0)
“[Errno -2]名称或服务未知”听起来像您的程序无法访问DNS服务器。你能用其他方式解析这些名字吗?例如用'挖'。我认为如果socket.gethostbyname无法解析名称,则会返回不同的错误;当我尝试它时,我得到:“没有与主机名相关的地址”。
答案 1 :(得分:0)
domain.google.com
和stuff.google.com
是无效的域名。摆脱这些将解决问题。
没有返回,因为您没有在subcheck
函数中返回任何内容。所以当你这样调用它时:
print subcheck(returned_list, arguments['--domain'])
它将被强制返回,并打印无。取下前面的打印件,你将看不到。