扫描web目录的Python小脚本
webscan.py:
import argparse
import requests
from concurrent.futures import ThreadPoolExecutor
from multiprocessing import cpu_count
from fake_useragent import UserAgent
from threading import Lock
def read_file():
""" 读取撞库文件 """
with open(file=args.scan_dict, mode='r', encoding='utf-8') as f:
return f.readlines()
def write_file(content):
""" 将撞库成功的url写入到文件中 """
lock = Lock()
lock.acquire()
with open(file=args.scan_output, mode='a', encoding='utf-8') as f:
f.write(content)
lock.release()
def send_msg(line):
""" 整理url并发送请求 """
# http://www.baidu.com/match_result.php
url = "{}{}".format(args.scan_site, line) if "://" in args.scan_site else "{}{}{}".format("http://", args.scan_site, line)
try:
response = requests.get(url=url, timeout=60, allow_redirects=False, headers={"User-Agent": UserAgent().random})
if response.status_code == 200:
write_file('{}\n'.format(response.url))
print(response.url, response.status_code)
except Exception as e:
print(e, url)
def run():
# 开启线程池,读取任务列表
# 任务列表:撞库文件
t = ThreadPoolExecutor(args.thread_num)
for i in read_file():
t.submit(send_msg, i)
if name == 'main':
parse = argparse.ArgumentParser()
parse.add_argument('--site', dest='scan_site', help='要扫描的服务器', type=str)
parse.add_argument('--dict', dest='scan_dict', help="撞库文件", default='webdict.txt', type=str)
parse.add_argument('--output', dest='scan_output', help="存储撞库成功的路径", default='./output.txt', type=str)
parse.add_argument('--thread', dest='thread_num', help='设置线程数量', default=cpu_count() * 5, type=int)
args = parse.parse_args()
run()
"""
D:\dazhu\Python.toos\note>python "09 web目录扫描.py" --site www.7k7k.com
"""
webdict.txt:
网上有很多这样的字典,可以搜索下载。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· DeepSeek 解答了困扰我五年的技术问题。时代确实变了!
· PPT革命!DeepSeek+Kimi=N小时工作5分钟完成?
· What?废柴, 还在本地部署DeepSeek吗?Are you kidding?
· DeepSeek企业级部署实战指南:从服务器选型到Dify私有化落地
· 程序员转型AI:行业分析