DNS 枚举脚本
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
在更改 CLI 选项后重新生成手册页(man/dnsrecon.1):
uv run python tools/generate_manpage.py
CI 还会在发布标签以及推送到 master 且更改了 CLI 时自动重新生成它。
运行代码检查和格式化:
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"