httpx内置实战配方:批量探测security.txt、robots.txt等10类well-known文件
【免费下载链接】httpxhttpx is a fast and multi-purpose HTTP toolkit that allows running multiple probes using the retryablehttp library.项目地址: https://gitcode.com/gh_mirrors/htt/httpx
httpx 是一款快速、多功能的 HTTP 探测工具(probing toolkit),基于 retryablehttp 库支持多线程批量探测。它的内置实战配方让你可以一行命令批量探测 security.txt、robots.txt 等 10 类 well-known 文件,快速完成安全信息与资产侦察。本文整理这套完整配方清单与原理,新手也能直接上手。
为什么需要批量探测 well-known 文件
Web 应用中有一批约定俗成的"标准路径"文件,它们往往藏着高价值信息:
- security.txt(RFC 9116):声明漏洞报送渠道,是 SRC 和安全测试的起点
- robots.txt / sitemap.xml:暴露站点结构,常含有敏感目录的 Disallow 规则
- ads.txt / humans.txt:运营与团队信息的"名片"
- openid-configuration、assetlinks.json等:揭示应用的认证体系与 App 关联配置
这些路径单个探测很简单,但面对成百上千个目标时,需要批量探测 + 精准过滤:既要探测多个路径,又要排除"软 404"(服务器对不存在的路径返回 200 状态码和 HTML 错误页)。httpx 的配方正好解决了这个问题。
配方原理:三个参数组合
所有 well-known 配方都基于同一个模式,组合使用三个参数:
| 参数 | 作用 |
|---|---|
-path | 指定一个或多个探测路径,逗号分隔即可一次探测多个 |
-mc 200 | 只保留返回 200 状态码的结果 |
-mdc | 用 DSL 表达式匹配响应字段,如contains(content_type, ...)、contains(body, ...) |
关键在-mdc(match-condition)参数:它可以在结构化字段上做匹配,而不是简单地在原始响应里找字符串。以 security.txt 配方为例,它同时校验:
- Content-Type 是
text/plain(排除返回 HTML 软 404 的服务器) - 正文包含
Contact:字段 - 正文包含
mailto:或https://联系信息
这三条全部满足才判定"真正存在 security.txt",大幅减少误报。参数定义见 options.go。
10类well-known文件配方完整清单
以下配方定义在 wellknown_recipes.go 中,并在 wellknown_recipes_test.go 中通过单元测试逐条验证,与 README 官方文档 完全一致。
| # | 目标 | 探测路径 | 匹配条件 |
|---|---|---|---|
| 1 | security.txt | /.well-known/security.txt、/security.txt | text/plain +Contact:+ mailto/https |
| 2 | robots.txt | /robots.txt | text/plain |
| 3 | sitemap.xml | /sitemap.xml | XML 类型 +<urlset |
| 4 | humans.txt | /humans.txt | text/plain |
| 5 | ads.txt | /ads.txt | text/plain +google.com |
| 6 | OpenID 配置 | /.well-known/openid-configuration | JSON +"issuer" |
| 7 | Apple Universal Links | /.well-known/apple-app-site-association(含 .json 变体) | JSON +"applinks" |
| 8 | Android App Links | /.well-known/assetlinks.json | JSON +"android_app" |
| 9 | crossdomain.xml | /crossdomain.xml | XML +cross-domain-policy |
| 10 | well-known 批量探测 | security.txt、change-password、openid-configuration 三条路径 | 仅匹配 200 |
配方示例:一键探测 security.txt
echo target.com | httpx -path '/.well-known/security.txt,/security.txt' \ -mc 200 \ -mdc 'contains(content_type, "text/plain") && contains(body, "Contact:") && contains_any(body, "mailto:", "https://")'命令含义拆解:
echo target.com:目标列表通过管道传入,批量探测时改用httpx -l hosts.txt即可-path同时探测新旧两个标准路径,任一命中即输出-mc 200+-mdc双重过滤,只保留"真 security.txt"
配方示例:批量探测多类 well-known URI
第 10 条配方是"轻量批量模式"——不做内容校验,只看哪些路径返回 200:
echo target.com | httpx -path '/.well-known/security.txt,/.well-known/change-password,/.well-known/openid-configuration' -mc 200适合先用它扫出"有哪些路径活着",再对感兴趣的返回加上-mdc内容校验深挖。
批量实战技巧
- 目标列表输入:
-l hosts.txt读取主机清单;Burp Suite 导出的 XML 也能用-l burp-export.xml -im burp直接作为输入 - 限速与并发:默认 50 线程、150 QPS(
-t、-rl可调),批量扫生产环境时建议调低速率 - 结果落盘:
-o result.txt保存文本结果,-j -o result.jsonl输出 JSON 便于后续脚本处理 - 自动降级:httpx 默认探测 HTTPS,失败自动降级 HTTP,无需额外配置
配方从哪来?源码里就能查
所有配方的"单一事实来源"是 runner/wellknown_recipes.go:每个配方的路径、匹配状态码、匹配条件都以结构体形式声明。测试文件 runner/wellknown_recipes_test.go 还专门验证了"拒绝软 404""security.txt 必须含 Contact 字段""ads.txt 必须含授权广告商"等边界情况——这正是配方可靠的原因。
常见问题
Q:为什么有的目标明明返回 200,配方却没匹配上?A:多半是"软 404"——服务器对任意路径都返回 200 + HTML 页面。-mdc对 Content-Type 的校验就是用来排除这种情况的,这也是为什么配方要同时看状态码和响应内容。
Q:可以只探测某一个路径吗?A:可以,-path传单个路径即可,比如只查 robots.txt 的极简命令:httpx -u target.com -path /robots.txt -mc 200。
Q:-mdc和-ms(match-string)有什么区别?A:-ms/-mr在整个原始响应上匹配字符串/正则,而-mdc在content_type、body等结构化字段上做表达式匹配,写起来更精确、不易误匹配。
总结
httpx 的内置实战配方把"批量探测 well-known 文件"这件事标准化了:-path多路径并发、-mc状态码过滤、-mdcDSL 内容校验三层组合,10 类配方开箱即用且有单测背书。掌握这套模式后,你也可以照葫芦画瓢,为自己的场景(比如探测某个私有接口)写出专属探测配方。
【免费下载链接】httpxhttpx is a fast and multi-purpose HTTP toolkit that allows running multiple probes using the retryablehttp library.项目地址: https://gitcode.com/gh_mirrors/htt/httpx
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考