python多线程扫描_python实现多线程扫描网站目录

该博客介绍了一个使用Python编写的网站目录扫描工具。它利用getopt和sys模块接收命令行参数,通过多线程处理扫描任务,并使用requests模块执行HTTP请求。工具功能包括打印Banner信息、显示使用方法、接收并验证参数、分组线程任务以及输出扫描结果。在给定的例子中,工具成功扫描了本地URL的多个目录,并打印了响应状态码为200或302的路径。
摘要由CSDN通过智能技术生成

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$

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值