DNSRecon 是我在2007年初为了学习Ruby语言和DNS知识而编写的一个Ruby脚本的Python移植版本。这次我想学习Python并扩展原始工具的功能,同时重新学习DNS的工作原理以及如何在安全评估和网络故障排查中使用它。
此脚本提供以下功能:
DNSRecon需要Python 3.12或更高版本。
如果尚未安装uv,请先安装:
curl -LsSf https://astral.sh/uv/install.sh | sh
克隆仓库:
git clone https://github.com/darkoperator/dnsrecon.git
cd dnsrecon
安装依赖并创建虚拟环境:
uv sync
运行DNSRecon:
uv run dnsrecon
安装开发依赖:
uv sync --extra dev
运行测试:
uv run pytest
运行代码检查和格式化:
uv run ruff check
uv run ruff format
DNSRecon 可以使用 Shodan 来扩展在标准枚举过程中从 SPF(-s)和/或 WHOIS(-w)数据中发现的网段。
被动 Shodan 增强(使用 SPF + WHOIS 网段):
uv run dnsrecon -d example.com -t std -s -w --shodan --shodan-key "$SHODAN_API_KEY"
主动验证 Shodan 结果(重新解析主机并确认它们仍然匹配查询的网段):
uv run dnsrecon -d example.com -t std -s -w --shodan --shodan-active --shodan-key "$SHODAN_API_KEY"
你也可以通过环境变量设置 API 密钥,而不是使用 --shodan-key:
export SHODAN_API_KEY="your-shodan-api-key"
uv run dnsrecon -d example.com -t std -s -w --shodan
启动 REST API:
uv run restdnsrecon
调用 /general_enum 并启用 Shodan 扩展:
curl -s \
-H "X-Shodan-Api-Key: $SHODAN_API_KEY" \
"http://127.0.0.1:5000/general_enum?domain=example.com&do_spf=true&do_whois=true&do_shodan=true"
在 API 中启用主动验证:
curl -s \
-H "X-Shodan-Api-Key: $SHODAN_API_KEY" \
"http://127.0.0.1:5000/general_enum?domain=example.com&do_spf=true&do_whois=true&do_shodan=true&shodan_active=true"
REST API 的 thread_num 值限制在 1..100 范围内。API 的 wordlist 参数可以引用 dnsrecon/data 中的捆绑文件,或者引用 DNSRECON_WORDLIST_DIRS 列出的目录下的文件,使用平台路径分隔符。仅配置专门的字典目录;不要将 DNSRECON_WORDLIST_DIRS 指向宽泛的路径,如 /、主目录或其他包含敏感文件的位置。
export DNSRECON_WORDLIST_DIRS="/opt/dnsrecon-wordlists:/srv/shared-wordlists"