python基于字典多线程目录枚举工具

基于字典多线程目录枚举工具

整体思路

  • 命令行参数获取
  • 字典文件的读取
  • 多线程访问

命令行参数获得:

使用模块:sys,getopt
		sys.argv获取命令行执行的数据
参数获得:opt, args =  getopt.getopt(sys.argv[1:],"u:t:d:")

字典文件读取:

python文件读取:with open(filename,mode") as f
			  f.readlines()
多线程:一个线程读取固定数目的字典内容

多线程:

python多线程:threading.Thread(target,args=())
			 start()

扫描给定URL是否存在字典中的目录
-u url -t 线程数 -d 字典名称

import getopt
import sys
import math
import threading
import requests


def banner():
    print("*"*51)
    print("*"*2 + " "*11 + "Clay0x7779 DirTools v1.0" + " "*12 + "*"*2)
    print("*"*51)
banner()

# python dirtools.py -u url -t thread -d dictionary

def usage():
    print("This is the tools usage")
    print("python dirtools.py -u url -t thread -d dictionary")

# opts, args = getopt.getopt(sys.argv[1:], "u:t:d:")

# print(opts)
# print(args)

def start():
    if len(sys.argv) == 7 :
        #Trun len
        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
        print("url:" +url)
        print("threads:" +threads)
        print("dic:" +dic)
        multi_scan(url,threads,dic)
    else:
        print("Error Argument!")
        usage()
        sys.exit()
#
def multi_scan(url,threads,dic):
    # 字典文件
    # 读取行数
    # 制作每一个线程读取的字典列表
    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:
        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+'/'+line)
        if r.status_code == 200:
            print(r.url + ":" + str(r.status_code))
start()
测试

在这里插入图片描述
在这里插入图片描述

人生漫漫其修远兮,网安无止境。
一同前行,加油!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值