Subfinder 子域名列舉工具

使用 ProjectDiscovery Subfinder 進行被動式子域名收集,整合多個資料源快速發現攻擊面

專案簡介

Subfinder 是 ProjectDiscovery 開發的被動式子域名列舉工具。整合數十個資料源 API,能快速收集目標域名的所有子域名,是滲透測試和 Bug Bounty 的必備偵察工具。

GitHub Stars: 13K+

主要功能

  • 多資料源 - 整合 50+ 被動式資料源
  • 高效能 - Go 語言開發,支援大規模掃描
  • API 整合 - 支援付費 API 提升結果
  • 輸出格式 - JSON、純文字多種格式
  • 管道友善 - 易於與其他工具串接

安裝

Go Install

1
go install -v github.com/projectdiscovery/subfinder/v2/cmd/subfinder@latest

Homebrew

1
brew install subfinder

Docker

1
docker pull projectdiscovery/subfinder:latest

基本使用

單一域名

1
subfinder -d example.com

多個域名

1
subfinder -dL domains.txt

輸出到檔案

1
subfinder -d example.com -o subdomains.txt

JSON 輸出

1
subfinder -d example.com -json -o results.json

API 設定

設定檔位置

1
~/.config/subfinder/provider-config.yaml

設定範例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# provider-config.yaml
binaryedge:
  - your-api-key
censys:
  - your-api-id:your-api-secret
chaos:
  - your-chaos-key
github:
  - your-github-token
  - another-github-token
hunter:
  - your-hunter-key
intelx:
  - your-intelx-key
securitytrails:
  - your-securitytrails-key
shodan:
  - your-shodan-key
virustotal:
  - your-virustotal-key

免費 API 推薦

服務免費額度
VirusTotal4 requests/min
SecurityTrails50 queries/month
Shodan100 queries/month
Censys250 queries/month
GitHub5000 requests/hour

進階選項

指定資料源

1
2
3
4
5
# 只使用特定來源
subfinder -d example.com -sources crtsh,dnsdumpster,hackertarget

# 排除來源
subfinder -d example.com -exclude-sources waybackarchive

列出可用資料源

1
subfinder -ls

效能調整

1
2
# 設定超時和並行
subfinder -d example.com -timeout 30 -t 100

遞迴子域名

1
2
# 啟用遞迴模式
subfinder -d example.com -recursive -recursive-level 2

工具鏈整合

完整偵察流程

1
2
3
4
5
6
7
8
# 1. 子域名列舉
subfinder -d target.com -o subs.txt

# 2. 存活檢測
cat subs.txt | httpx -o alive.txt

# 3. 漏洞掃描
nuclei -l alive.txt -severity critical,high

搭配 httpx

1
subfinder -d target.com -silent | httpx -title -tech-detect -status-code

搭配 naabu(端口掃描)

1
subfinder -d target.com -silent | naabu -p 80,443,8080,8443

搭配 dnsx(DNS 解析)

1
subfinder -d target.com -silent | dnsx -a -resp

實戰範例

Bug Bounty 自動化

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#!/bin/bash
# recon.sh

TARGET=$1
OUTDIR="recon/${TARGET}"
mkdir -p $OUTDIR

echo "[*] Subdomain enumeration..."
subfinder -d $TARGET -all -o $OUTDIR/subdomains.txt

echo "[*] Checking alive hosts..."
cat $OUTDIR/subdomains.txt | httpx -silent -o $OUTDIR/alive.txt

echo "[*] Screenshot capture..."
cat $OUTDIR/alive.txt | gowitness file -f -

echo "[*] Vulnerability scanning..."
nuclei -l $OUTDIR/alive.txt -severity critical,high -o $OUTDIR/vulns.txt

持續監控

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#!/bin/bash
# monitor.sh

TARGET=$1
NEW_SUBS=$(mktemp)

subfinder -d $TARGET -silent > $NEW_SUBS

# 比對新發現的子域名
comm -13 <(sort old_subs.txt) <(sort $NEW_SUBS) > new_found.txt

if [ -s new_found.txt ]; then
    echo "New subdomains found:"
    cat new_found.txt
    # 發送通知
fi

mv $NEW_SUBS old_subs.txt

CI/CD 整合

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# .github/workflows/recon.yml
name: Subdomain Monitoring
on:
  schedule:
    - cron: '0 0 * * *'
jobs:
  scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Run Subfinder
        run: |
          go install github.com/projectdiscovery/subfinder/v2/cmd/subfinder@latest
          subfinder -d example.com -o subdomains.txt          
      - name: Upload Results
        uses: actions/upload-artifact@v4
        with:
          name: subdomains
          path: subdomains.txt

輸出格式

純文字

1
2
3
4
subfinder -d example.com
# api.example.com
# www.example.com
# mail.example.com

JSON

1
2
subfinder -d example.com -json
# {"host":"api.example.com","source":"crtsh"}

CSV

1
2
3
subfinder -d example.com -cs -all
# api.example.com,crtsh
# www.example.com,dnsdumpster

相關連結

延伸閱讀

comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy