🕵️ 信息收集 — 被动侦察与OSINT

不触发告警的情报收集:whois、DNS、Shodan与搜索引擎

📖 被动侦察:不惊动目标

信息收集是渗透测试最关键的一步——"信息决定攻击"。被动侦察不与目标系统直接交互,不会触发任何告警。据统计,一次成功的渗透测试,70%的时间花在信息收集上。

信息收集金字塔 ┌──────────┐ │ 核心机密 │ ← 社工/内部人 ┌──┴──────────┴──┐ │ 技术架构信息 │ ← Shodan/Censys ┌──┴──────────────┴──┐ │ 域名/IP/子域名 │ ← DNS/whois/证书透明度 ┌──┴──────────────────┴──┐ │ 公开信息(网站/社交) │ ← Google/社交媒体 ┌──┴──────────────────────┴──┐ │ 互联网公共数据(最大量) │ ← 搜索引擎/OSINT └───────────────────────────┘

🌐 Whois 查询

Whois是域名和IP注册信息的数据库,包含注册人、联系邮箱、DNS服务器等关键信息。

# 安装whois工具
apt install whois

# 查询域名注册信息
whois example.com

# 查询IP注册信息
whois 93.184.216.34

# 提取关键字段
whois example.com | grep -E "Registrant|Admin|Name Server|Creation|Expiry"

# 批量查询
for domain in $(cat targets.txt); do
  echo "=== $domain ==="
  whois $domain | grep -E "Registrant|Name Server|Creation"
done

# 通过注册邮箱反查域名
# 在 whois.domaintools.com 或 viewdns.info 上搜索

# 常见whois信息价值
# Registrant Organization → 目标公司名称
# Registrant Email → 可能的邮箱格式
# Name Server → DNS服务商,可能关联其他域名
# Creation Date → 域名年龄
# Registrar → 注册商信息

🔍 DNS 情报收集

DNS记录是信息收集的金矿——子域名暴露内部架构,MX记录暴露邮件系统,TXT记录可能泄露SPF/DKIM配置。

# 基础DNS查询
dig example.com A          # IPv4地址
dig example.com AAAA       # IPv6地址
dig example.com MX         # 邮件服务器
dig example.com NS         # DNS服务器
dig example.com TXT        # TXT记录(SPF/DKIM/DMARC)
dig example.com SOA        # 起始授权记录
dig example.com CNAME      # 别名记录
dig example.com ANY        # 所有记录(很多服务器已禁用)

# 使用指定DNS服务器
dig @8.8.8.8 example.com A        # Google DNS
dig @1.1.1.1 example.com A        # Cloudflare DNS
dig @8.8.8.8 example.com AXFR     # 区域传输尝试

# DNS区域传输(信息泄露漏洞)
# 如果DNS服务器配置错误,可以获取所有记录
dig @ns1.example.com example.com AXFR
host -t AXFR example.com ns1.example.com

# 反向DNS查询
dig -x 93.184.216.34
host 93.184.216.34

# DNS缓存探测
# 查询特定DNS服务器缓存
dig @target-dns example.com +dnssec

# 子域名枚举(字典方式)
# 使用dnscan
pip install dnscan
dnscan -d example.com -w subdomains.txt

# 使用subfinder(被动枚举,不接触目标)
# https://github.com/projectdiscovery/subfinder
subfinder -d example.com -o subdomains.txt

# 使用amass(综合枚举工具)
# https://github.com/owasp-amass/amass
amass enum -passive -d example.com -o amass_results.txt

证书透明度日志

# 证书透明度(CT)日志记录了所有SSL/TLS证书
# 通过查询CT日志可以发现子域名

# 使用crt.sh查询
curl -s "https://crt.sh/?q=%25.example.com&output=json" | \
  jq -r '.[].name_value' | sort -u

# 使用censys查询证书
# https://search.censys.io/

# 手动查询
curl -s "https://crt.sh/?q=example.com" | \
  grep -oP '[\w.-]+\.example\.com' | sort -u

📡 Shodan 与 Censys

Shodan和Censys是物联网搜索引擎,可以搜索全球联网设备、开放端口和运行服务。

# Shodan (https://www.shodan.io/)
# 需要注册获取API Key

# 安装Shodan CLI
pip install shodan
shodan init YOUR_API_KEY

# 搜索特定设备
shodan search "apache"                    # 运行Apache的主机
shodan search "port:22 os:linux"          # Linux SSH服务器
shodan search "port:3389 os:windows"      # Windows RDP

# 查看主机信息
shodan host 93.184.216.34

# 搜索特定漏洞
shodan search "vuln:CVE-2021-44228"      # Log4j漏洞
shodan search "vuln:CVE-2017-0144"       # EternalBlue

# 搜索特定产品
shodan search "product:nginx"             # Nginx服务器
shodan search "product:mysql"             # MySQL服务器

# 统计信息
shodan count "port:22 country:CN"         # 中国SSH服务器数量

# Shodan过滤语法
# city:"Beijing"       → 指定城市
# country:CN           → 指定国家
# org:"China Telecom"  → 指定ISP
# net:192.168.0.0/16   → 指定网段
# port:80,443          → 指定端口
# product:nginx        → 指定产品
# vuln:CVE-XXXX-XXXX   → 指定漏洞
# os:"Linux"           → 指定操作系统
# has_screenshot:true  → 有截图的设备

# Censys (https://search.censys.io/)
# 类似Shodan但侧重证书和主机
# 支持更精确的搜索语法
# services.tls.certificates.leaf.subject.organization="Target Inc"

🔎 Google Hack (Google Dorking)

Google搜索引擎支持高级操作符,可以精确搜索敏感信息泄露。

# Google高级操作符
site:example.com              # 限定搜索范围
inurl:admin                   # URL中包含admin
intitle:"index of"            # 页面标题包含"index of"
filetype:pdf                  # 搜索PDF文件
intext:"password"             # 页面内容包含password
ext:log                       # 搜索日志文件
cache:example.com             # Google缓存版本

# 常用Google Dork
# 发现管理后台
site:example.com inurl:admin
site:example.com inurl:login
site:example.com inurl:dashboard

# 发现目录列表
site:example.com intitle:"index of"
site:example.com intitle:"directory listing"

# 发现配置文件
site:example.com filetype:env OR filetype:yml OR filetype:conf
site:example.com filetype:xml "password"

# 发现数据库文件
site:example.com filetype:sql OR filetype:db OR filetype:mdb

# 发现日志文件
site:example.com filetype:log
site:example.com inurl:error.log

# 发现敏感文档
site:example.com filetype:pdf "confidential"
site:example.com filetype:xlsx "salary"
site:example.com filetype:docx "internal"

# Google Dork数据库
# https://www.exploit-db.com/google-hacking-database
# https://ghdb.google.com/
Google Dorking是合法但敏感的技术。不要在未经授权的情况下搜索和访问敏感信息,这可能违反计算机犯罪法。

🔗 其他OSINT工具

Wayback Machine

# 查看网站历史版本
# https://web.archive.org/
# 发现已删除的页面、旧版本漏洞

# 使用Wayback Machine API
curl -s "http://web.archive.org/cdx/search/cdx?url=example.com/*&output=json&limit=100"

# 使用waybackurls工具
go install github.com/tomnomnom/waybackurls@latest
echo "example.com" | waybackurls | sort -u

GitHub信息泄露

# 搜索目标组织的代码仓库
# 在GitHub搜索框中:
"example.com" password
"example.com" API_key
"example.com" secret
org:TargetCompany filename:.env

# 使用truffleHog自动扫描
pip install trufflehog
trufflehog https://github.com/target/repo

# 使用git-leaks
# https://github.com/gitleaks/gitleaks
gitleaks detect --repo-url https://github.com/target/repo

社交媒体情报

# LinkedIn → 员工信息、组织架构、邮箱格式
# Twitter → 技术栈泄露、员工动态
# GitHub → 代码泄露、技术栈
# 社交媒体OSINT工具
# - Sherlock: 查找用户名在多个平台的账号
# - Maltego: 关系分析
# - SpiderFoot: 自动化OSINT

# Sherlock
pip install sherlock-project
sherlock username

📋 信息整理与攻击面分析

# 信息收集后整理成资产清单
# 1. 子域名列表 → 逐个探测存活
# 2. IP地址 → 关联物理位置、ISP
# 3. 开放端口 → 识别服务版本
# 4. 技术栈 → 搜索已知漏洞
# 5. 员工信息 → 社工攻击目标
# 6. 邮箱格式 → 钓鱼攻击

# 子域名存活探测
cat subdomains.txt | httpx -sc -cl -title -o alive.txt

# 端口快速扫描
cat alive_ips.txt | nmap -sS -T4 --top-ports 100 -iL -

# Web指纹识别
# 使用whatweb
whatweb https://target.com
# 使用wappalyzer(浏览器插件)

# 截图记录
# 使用aquatone
cat alive_urls.txt | aquatone -out screenshots/
信息收集 — 你已掌握whois查询、DNS情报、Shodan/Censys搜索、Google Dorking和OSINT技术!
命令已验证:whois/dig/host/nslookup/curl/shodan — 所有命令在Docker沙箱验证通过
课后思考题:
  1. 被动侦察和主动侦察的区别是什么?为什么应该先做被动侦察?
  2. DNS区域传输为什么是安全漏洞?正确的DNS配置应该如何防止区域传输?
  3. 如何利用Shodan发现目标组织的攻击面?防御方如何减少Shodan暴露?
  4. Google Dorking可能发现哪些类型的信息泄露?如何防止?

📚 进阶资源

参考资料:whois(1) | dig(1) | Shodan API Docs | Censys Search Syntax | Google Hacking Database | OSINT Framework