我正在用 python 编写自己的目录破坏程序,并在安全可靠的环境中针对我的 Web 服务器进行测试。该脚本基本上尝试从给定网站检索常见目录,并查看响应的 HTTP 状态代码,它能够确定页面是否可访问。
首先,该脚本读取一个包含所有要查找的有趣目录的文件,然后按以下方式发出请求:
for dir in fileinput.input('utils/Directories_Common.wordlist'):
try:
conn = httplib.HTTPConnection(url)
conn.request("GET", "/"+str(dir))
toturl = 'http://'+url+'/'+str(dir)[:-1]
print ' Trying to get: '+toturl
r1 = conn.getresponse()
response = r1.read()
print ' ',r1.status, r1.reason
conn.close()
然后,解析响应,如果返回等于“200”的状态代码,则该页面可以访问。我通过以下方式实现了这一切:
if(r1.status == 200):
print '\n[!] Got it! The subdirectory '+str(dir)+' could be interesting..\n\n\n'
对我来说一切似乎都很好,除了脚本标记为可访问的页面,但实际上并非如此。事实上,该算法收集唯一返回“200 OK”的页面,但当我手动浏览检查这些页面时,我发现它们已被永久移动或访问权限受到限制。出了问题,但我无法确定应该在哪里修复代码,非常感谢任何帮助。
我没有发现你的代码有任何问题,只是它几乎不可读。我已将其重写为这个工作片段:
import httplib
host = 'www.google.com'
directories = ['aosicdjqwe0cd9qwe0d9q2we', 'reader', 'news']
for directory in directories:
conn = httplib.HTTPConnection(host)
conn.request('HEAD', '/' + directory)
url = 'http://{0}/{1}'.format(host, directory)
print ' Trying: {0}'.format(url)
response = conn.getresponse()
print ' Got: ', response.status, response.reason
conn.close()
if response.status == 200:
print ("[!] The subdirectory '{0}' "
"could be interesting.").format(directory)
Outputs:
$ python snippet.py
Trying: http://www.google.com/aosicdjqwe0cd9qwe0d9q2we
Got: 404 Not Found
Trying: http://www.google.com/reader
Got: 302 Moved Temporarily
Trying: http://www.google.com/news
Got: 200 OK
[!] The subdirectory 'news' could be interesting.
另外,我确实使用了HEADHTTP 请求而不是 GET,因为如果您不需要内容并且只对状态代码感兴趣,那么它会更有效。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)