python编写web目录扫描器

#!/usr/bin/python3
import requests
import sys
import queue
import threading
class Dirscan(threading.Thread):
    def __init__(self,q):
        super(Dirscan, self).__init__()
        self.q=q
    def run(self):
        while not self.q.empty():
            url=self.q.get()
            try:
                headers={'User-Agent':'xixi scan for web ver=1.0'

                }
                r=requests.get(url=url,headers=headers)
                if r.status_code==200:
                    print(url)
            except :
                pass
def start(url,ext,count):
    q=queue.Queue()
    threads=[]
    threads_count=int(count)
    f=open('C:/Users/18910/Desktop/%s.txt'% ext,'r')
    for i in f:
        q.put(url+i.rstrip('\n'))
    for i in range(threads_count):
        threads.append(Dirscan(q))
    for t in threads:
        t.start()
    for t in threads:
        t.join()
if __name__ == '__main__':
    url='http://www.qiduyy.com'
    ext='asp'
    count=10
    start(url,ext,count)
。。。扫描结果如下:

D:\untitled2\venv\Scripts\python.exe D:/untitled2/venv/1.py
http://www.qiduyy.com/down.htm
http://www.qiduyy.com/star.asp
http://www.qiduyy.com/index.asp
http://www.qiduyy.com/index.html
http://www.qiduyy.com/get.htm
http://www.qiduyy.com/moban.asp
http://www.qiduyy.com/changepwd.asp
http://www.qiduyy.com/admin_index.asp
http://www.qiduyy.com/book.asp
http://www.qiduyy.com/productcn.asp
http://www.qiduyy.com/aspadmin.asp
http://www.qiduyy.com/admin.htm
http://www.qiduyy.com/2006.asp
http://www.qiduyy.com/admin.asp


Process finished with exit code 0

 如果想要自己输入网址文件格式线程数,将函数入口内容更改一下即可
if __name__ == '__main__':
    if len(sys.argv)!=4:
        sys.exit(-1)
    else:
        start(sys.argv[1],sys.argv[2],sys.argv[3])

脚本运行结果如下:


 

 

posted @ 2020-09-21 21:51  bsde  阅读(354)  评论(0)    收藏  举报