python多线程扫描_python实现多线程扫描网站目录
python實現網站目錄掃描
st=>start: 程序開始
op=>operation: 打印banner信息
op2=>operation: 打印使用方法
op3=>operation: 接收傳遞過來的參數
cond=>condition: 判斷參數是否接收完整(是或否?)
op6=>operation: 將傳遞過來的參數傳遞給指定變量
sub1=>subroutine: 沒有接收完整
sub2=>subroutine: 打印錯誤信息
sub3=>subroutine: 直接退出程序
jieshu=>end: 直接退出程序
op4=>operation: 確定線程數,將字典按照線程數進行分組
op5=>operation: 執行掃描模塊
io=>inputoutput: 輸出掃描結果
e=>end: 程序執行完退出
st->op->op2->op3->cond
cond(yes)->op6->op4->op5->io->e
cond(no)->sub1(right)->sub2(right)-->sub3(right)
根據流程圖確定使用getopt,sys模塊來接受參數,并進行處理, threading模塊來處理多線程, requests模塊來執行掃描功能, math線程的向上取整.
打印工具的banner信息
def banner():
print ("*" * 57)
print ("*" * 3 + " " * 19 + "DirBrute v 1.0" + " " * 18 + "*" * 3)
print ("*" * 3 + " " * 12 + "This tool just develop fun!" + " " * 12 + "*" * 3)
print ("*" * 57)
聲明使用方法
# python Dirbrute.py -u url -t thread -d dictionary
def usage():
print ("*" * 57)
print ("*" * 3 + " " * 13 + "This is the tool's usage" + " " * 14 + "*" * 3)
print ("*" * 3 + "python Dirbrute.py -u url -t threads -d dictionary!" + "*" * 3)
print ("*" * 57)
判斷接收參數是否完整如果完整了傳遞給特定的變量
def start():
if len(sys.argv) == 7:
# This is true length
opts, args = getopt.getopt(sys.argv[1:], "u:t:d:")
for k, v in opts:
if k == "-u":
url =v
elif k == "-t":
threads = v
elif k == "-d":
dic = v
multi_scan(url, threads, dic)
else:
print ("Error Argument!")
sys.exit()
多線程的實現
第一步讀字典文件
第二步 確定讀取的行數 len(dic_list) / threads 向上去取整
第三步 確定每個線程讀取的列表[[t1],[t2],[t3],...]
def multi_scan(url,threads,dic):
# 第一步讀字典文件
# 第二步 確定讀取的行數 len(dic_list) / threads 向上去取整
# 第三步 確定每個線程讀取的列表[[t1],[t2],[t3],...]
result_list = []
threads_list = []
with open(dic, "r") as f:
dic_list = f.readlines()
if len(dic_list) % int(threads) == 0:
thread_read_line_num = len(dic_list) / int(threads)
else:
thread_read_line_num = math.ceil(len(dic_list) / int(threads))
i = 0
temp_list = []
for line in dic_list:
i += 1
if i % thread_read_line_num == 0:
temp_list.append(line.strip())
result_list.append(temp_list)
temp_list = []
else:
temp_list.append(line.strip())
for i in result_list:
# print (i)
threads_list.append(threading.Thread(target = scan, args = (url,i)))
for t in threads_list:
t.start()
掃描功能
def scan(url, dic):
# 實現掃描功能 requests
for line in dic:
r = requests.get(url = url + '/' + line)
if r.status_code == 200 or r.status_code == 302:
print (r.url + " : " + str(r.status_code))
調用程序
if __name__ == "__main__":
banner()
suage()
start()
程序結果:
pig@deep:~/Desktop$ python3 Dirbrute.py -u http://127.0.0.1/ -t 1 -d dic.txt
*********************************************************
*** DirBrute v 1.0 ***
*** This tool just develop fun! ***
*********************************************************
*********************************************************
*** This is the tool's usage ***
***python Dirbrute.py -u url -t threads -d dictionary!***
*********************************************************
http://127.0.0.1//readme.txt : 200
http://127.0.0.1//images/ : 200
http://127.0.0.1//index.html : 200
http://127.0.0.1/images/ : 200
pig@deep:~/Desktop$
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的python多线程扫描_python实现多线程扫描网站目录的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql peferences_MyS
- 下一篇: mysql聚合函数不存在的数据_SELE