SecretScraper: 高度可配置的Web爬虫及敏感信息泄露检测工具
字数 1244 2025-08-22 12:22:42
SecretScraper 网络爬虫及敏感信息泄露检测工具教学文档
1. 工具概述
SecretScraper 是一个高度可配置的网络爬虫及敏感信息泄露检测工具,具有以下核心功能:
- 通过 DOM 结构和正则表达式两种方式从 Web 响应中提取 URL
- 使用正则表达式检测响应中的敏感信息
- 支持 Hyperscan 模式以提高正则匹配效率
- 提供丰富的配置选项和自定义功能
GitHub 仓库地址:https://github.com/PadishahIII/SecretScraper
2. 主要特性
2.1 爬虫功能
- 支持通过 DOM 层次结构和正则表达式提取链接
- 支持域名白名单和黑名单(支持通配符)
- 支持多个目标输入(从文件读取 URL)
- 支持本地文件扫描
- 可定制爬取深度和页面数量限制
2.2 配置选项
- 可自定义请求头、代理、超时、cookie 等
- 可配置是否跟随重定向
- 支持 YAML 格式配置文件
- 结果以 CSV 格式保存
2.3 敏感信息检测
- 内置多种敏感信息正则表达式规则
- 支持自定义正则表达式规则
- 可选择隐藏正则提取结果
- 支持验证 URL 状态
3. 安装与升级
3.1 安装
pip install secretscraper
3.2 升级
pip install --upgrade secretscraper
4. 基本使用
4.1 单目标爬取
secretscraper -u https://scrapeme.live/shop/
4.2 多目标爬取
secretscraper -f urls.txt
其中 urls.txt 文件内容格式为每行一个 URL。
4.3 配置文件
SecretScraper 会从当前文件夹寻找 settings.yml 文件,如果没有找到,则会自动生成一个默认配置文件。
5. 高级用法
5.1 验证 URL 状态
secretscraper -u https://scrapeme.live/shop/ --validate --max-page=10
5.2 深度爬取
# 深度为2的爬取
secretscraper -u https://scrapeme.live/shop/ -m 2
# 或使用max-depth参数
secretscraper -u https://scrapeme.live/shop/ --max-depth=2
注意:不建议设置大于2的爬取深度
5.3 保存结果到 CSV
secretscraper -u https://scrapeme.live/shop/ -o result.csv
5.4 域名黑白名单
白名单示例(只爬取匹配的域名):
secretscraper -u https://scrapeme.live/shop/ -d *scrapeme*
黑名单示例(不爬取匹配的域名):
secretscraper -u https://scrapeme.live/shop/ -D *.gov
5.5 隐藏敏感信息检测结果
secretscraper -u https://scrapeme.live/shop/ -H
5.6 扫描本地文件
secretscraper -l <目录或文件路径>
5.7 使用 Hyperscan 加速
在 settings.yml 中设置:
handler_type: hyperscan
注意:Hyperscan 不支持正则 group 和部分语法,需要为 Hyperscan 和 re 模式分别编写正则表达式
6. 配置详解
默认配置文件 settings.yml 内容及说明:
verbose: false
debug: false
loglevel: critical
logpath: log
handler_type: re # 或 hyperscan
proxy: "" # 代理设置,如 http://127.0.0.1:7890
max_depth: 1 # 0表示无限制
max_page_num: 1000 # 0表示无限制
timeout: 5 # 超时时间(秒)
follow_redirects: true # 是否跟随重定向
workers_num: 1000 # 工作线程数
# 请求头设置
headers:
Accept: "*/*"
Cookie: ""
User-Agent: "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36 SE 2.X MetaSr 1.0"
# URL 查找规则
urlFind:
- "[s{0,6}(https{0,1}:[-a-zA-Z0-9(2,250}?)\\s{0,6}"
- "=\\s{0,6}(https{0,1}:[-a-zA-Z0-9(2,250})"
- "[s{0,6}([#,.]{0,2}/[-a-zA-Z0-9(2,250}?)\\s{0,6}"
- "\"([-a-zA-Z0-9(1}[-a-zA-Z0-9("
- "href\\s{0,6}=\\s{0,6}0,1}\\s{0,6}([-a-zA-Z0-9(2,250})|action\\s{0,6}=\\s{0,6}0,1}\\s{0,6}([-a-zA-Z0-9(2,250})"
# JS 文件查找规则
jsFind:
- (https{0,1}:[-a-zA-Z0-9(2,100}?[-a-zA-Z0-9(3}[.]js)
- '[" '' '""`]\s{0,6}(/{0,1}[-a-zA-Z0-9(2,100}?[-a-zA-Z0-9(3}[.]js)'
- =\s{0,6}0,1}\s{0,6}(/{0,1}[-a-zA-Z0-9(2,100}?[-a-zA-Z0-9(3}[.]js)
# 危险路径检测
dangerousPath:
- logout
- update
- remove
- insert
- delete
# 敏感信息检测规则
rules:
- name: Swagger
regex: \b[\w/]+?((swagger-ui.html)|(\"swagger\":)|(Swagger UI)|(swaggerUi)|(swaggerVersion))\b
loaded: true
- name: ID Card
regex: \b((\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3})|(\d{6}(18|19|20)\d{2}(0[1-9]|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)))\b
loaded: true
- name: Phone
regex: "['\"](1(3([0-35-9]\\d|4[1-8])|4[14-9]\\d|5([\\d]\\d|7[1-79])|66\\d|7[2-35-8]\\d|8\\d{2}|9[89]\\d)\\d{7}
loaded: true
- name: JS Map
regex: \b([\w/]+?\.js\.map)
loaded: true
- name: URL as a Value
regex: (\b\w+?=(https?)(://|%3a%2f%2f))
loaded: false
- name: Email
regex: "[w]w]w](?:[\\w-]*[\\w]w](?:[\\w-]*[\\w]
loaded: true
- name: Internal IP
regex: '[^0-9]((127\.0\.0\.1)|(10\.\d{1,3}\.\d{1,3}\.\d{1,3})|(172\.((1[6-9])|(2\d)|(3[01]))\.\d{1,3}\.\d{1,3})|(192\.168\.\d{1,3}\.\d{1,3}))'
loaded: true
- name: Cloud Key
regex: \b((accesskeyid)|(accesskeysecret)|\b(LTAI[a-z0-9]{12,20}))\b
loaded: true
- name: Shiro
regex: (=deleteMe|rememberMe=)
loaded: true
- name: Suspicious API Key
regex: "[\"'][0-9a-zA-Z]{32}['\"]"
loaded: true
- name: Jwt
regex: "['\"](ey[A-Za-z0-9_-]{10,}\\.[A-Za-z0-9._-]{10,}|ey[A-Za-z0-9_\\/+-]{10,}\\.[A-Za-z0-9.10,
loaded: true
7. 命令行选项详解
Usage: secretscraper [OPTIONS]
Main commands
Options:
-V, --version Show version and exit.
--debug Enable debug.
-a, --ua TEXT Set User-Agent
-c, --cookie TEXT Set cookie
-d, --allow-domains TEXT Domain white list, wildcard(*) is supported, separated by commas, e.g. *.example.com, example*
-D, --disallow-domains TEXT Domain black list, wildcard(*) is supported, separated by commas, e.g. *.example.com, example*
-f, --url-file FILE Target urls file, separated by line break
-i, --config FILE Set config file, defaults to settings.yml
-m, --mode [1|2] Set crawl mode, 1(normal) for max_depth=1, 2(thorough) for max_depth=2, default 1
--max-page INTEGER Max page number to crawl, default 100000
--max-depth INTEGER Max depth to crawl, default 1
-o, --outfile FILE Output result to specified file in csv format
-s, --status TEXT Filter response status to display, seperated by commas, e.g. 200,300-400
-x, --proxy TEXT Set proxy, e.g. http://127.0.0.1:8080, socks5://127.0.0.1:7890
-H, --hide-regex Hide regex search result
-F, --follow-redirects Follow redirects
-u, --url TEXT Target url
--detail Show detailed result
--validate Validate the status of found urls
-l, --local PATH Local file or directory, scan local file/directory recursively
--help Show this message and exit.
8. 使用建议
- 爬取深度控制:对于大型网站,建议保持 max_depth=1 或 2,避免爬取过多页面
- 结果验证:使用 --validate 选项可以减少无效 URL
- 性能优化:对于大规模爬取,考虑使用 Hyperscan 模式(需注意正则语法差异)
- 敏感信息保护:使用 -H 选项可以只显示爬虫结果而不显示敏感信息检测结果
- 黑白名单:合理使用域名黑白名单可以提高爬取效率和准确性
9. 注意事项
- 请遵守目标网站的 robots.txt 协议和相关法律法规
- 避免对目标网站造成过大负载
- Hyperscan 模式不支持正则 group 和部分语法
- 深度爬取可能会消耗大量时间和资源
- 默认配置文件中的正则表达式可能需要根据实际需求调整