多线程目录爆破工具(源码+分析)

6 篇文章 0 订阅
# -*- coding: UTF-8 -*-
import math
import threading
import sys
import getopt
import requests

#工具初始化之版本号与名称
def banner():
    print("*"*51)
    print("*"*2+" "*17+"DirScan  v1.0"+" "*17+"*"*2)
    print("*"*51)
    print()

#工具初始化之用法
def usage():
    print("This is the tool's usage")
    print("python DirScan.py -u url -t thread -d dictionary")
    print()
    print("*"*51 )

#定义一个多线程执行函数
def multi_scan(url,threads,dic):
    result_list = []  # 定义一个存放最终字典的空列表

    with open(dic,"r") as f:
        dic_list = f.readlines()
        lenth = len(dic_list)

        #确定一个线程读取几行字典内容
        thread_read_line_num = math.ceil(len(dic_list) / int(threads))        #对线程数向上取整,即16/5=3.2 --> 4

        i=0
        temp_list = []              #新建一个临时列表
        for line in dic_list:       #依次从加载的字典中取数据
            i = i + 1
            if i % thread_read_line_num == 0:           #如果够一个线程取得数量了
                temp_list.append(line.strip())
                result_list.append(temp_list)           #将当前线程创建的临时列表  存放到最终空列表中
                temp_list = []
            elif i == lenth:                            #防止不够整除,少了最后一个数组。
                temp_list.append(line.strip())          #可以将这三行注释掉传入5个线程,17个数据试试就明白了。
                result_list.append(temp_list)
            else:
                temp_list.append(line.strip())          #放一个数据到临时列表

    #print(result_list)               #打印输出最终列表


    threads_list = []                 #定义一个空的多线程列表
    #制作一个多线程列表
    for i in result_list:
        threads_list.append(threading.Thread(target=scan,args=(url,i)))     #url由命令行传入
    #启动多线程
    for t in threads_list:
        t.start()

#定义一个目录扫描功能的函数
def scan(url,dic):
    headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0"}

    for line in dic:
        r = requests.get(url+'/'+line,headers=headers)
        if r.status_code == 200:
            print(r.url+ " : "+ str(r.status_code))


#定义获取命令行参数的函数,也是程数开始的地方
def start():
    banner()
    if len(sys.argv)  == 7:
        opts,args = getopt.getopt(sys.argv[1:],"u:t:d:")        #从命令行获取参数
        for k,v in opts:
            #print(k,v)
            if k == '-u':               #这个  “ - ”不要忘了
                url = v
            elif k == '-t':
                threads = v
            elif k == '-d':
                dic = v
            else:
                print("你传输的参数有误")
                usage()
                sys.exit()  # 结束当前程序

        multi_scan(url,threads,dic)     #将获取到的参数传入多线程函数,并执行。
    else:
        print("你传输的参数有误")
        usage()
        sys.exit()              #结束当前程序

if __name__ =="__main__":
    start()

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值