渗透测试方法论
约 1846 字大约 6 分钟
penetration-testingmethodology
2025-08-24
概述
渗透测试(Penetration Testing)是通过模拟真实攻击者的手法和技术,评估系统安全性的过程。它不仅仅是运行自动化扫描工具,更是一种系统性的安全评估方法论。本文将介绍主流渗透测试方法论、各阶段的关键技术和常用工具。
渗透测试流程
PTES (Penetration Testing Execution Standard)
阶段 1: 信息收集(Reconnaissance)
被动收集
# DNS 信息收集
# 子域名枚举
subfinder -d example.com -o subdomains.txt
amass enum -passive -d example.com
# DNS 记录查询
dig example.com ANY
dig example.com MX
dig example.com TXT
host -t ns example.com
# WHOIS 信息
whois example.com
# 证书透明度日志
curl -s "https://crt.sh/?q=%.example.com&output=json" | \
jq -r '.[].name_value' | sort -u
# Google Dorking
# site:example.com filetype:pdf
# site:example.com inurl:admin
# site:example.com intitle:"index of"
# Shodan / Censys 搜索
shodan search "hostname:example.com"主动收集
# 端口扫描
nmap -sS -sV -O -p- --min-rate 1000 target.example.com
# -sS: SYN 扫描(半开放)
# -sV: 服务版本探测
# -O: 操作系统识别
# -p-: 全端口扫描
# 详细扫描特定端口
nmap -sV -sC -p 80,443,8080,8443 target.example.com
# -sC: 运行默认脚本
# UDP 扫描
nmap -sU --top-ports 100 target.example.com阶段 2: 扫描与枚举
Web 应用扫描
# 目录枚举
gobuster dir -u https://example.com -w /usr/share/wordlists/dirb/common.txt -t 50
feroxbuster -u https://example.com -w /usr/share/seclists/Discovery/Web-Content/raft-medium-directories.txt
# 技术栈识别
whatweb https://example.com
wappalyzer https://example.com
# Web 服务器信息
curl -sI https://example.com | head -20
# API 端点发现
# 查看 robots.txt, sitemap.xml
# 检查 JavaScript 文件中的 API 路径
# 使用 Burp Suite 的 Spider 功能服务枚举
# HTTP 枚举
nmap --script http-enum -p 80,443 target.example.com
# SSL/TLS 检测
nmap --script ssl-enum-ciphers -p 443 target.example.com
testssl.sh https://example.com
# SMB 枚举
nmap --script smb-enum-shares,smb-enum-users -p 445 target
# SNMP 枚举
nmap --script snmp-info -p 161 -sU target阶段 3: 漏洞分析
# Nmap 漏洞扫描脚本
nmap --script vuln -p 80,443 target.example.com
# Nuclei 模板扫描
nuclei -u https://example.com -t cves/
nuclei -u https://example.com -t vulnerabilities/
# OWASP ZAP 自动扫描(命令行模式)
zap-cli quick-scan -s all -r https://example.com阶段 4: 漏洞利用
Burp Suite 手动测试
OWASP Top 10 测试清单
# 测试思路示例
# A01 - 访问控制
# IDOR: 修改 URL/参数中的 ID 访问其他用户的资源
# GET /api/users/123/orders → GET /api/users/456/orders
# 水平越权: 同级用户间互相访问
# 垂直越权: 普通用户访问管理员功能
# A02 - 加密失败
# 检查 HTTPS 配置
# 敏感数据是否明文传输/存储
# 密码是否使用强哈希
# A03 - 注入
# SQL 注入: 参数中添加 ' OR 1=1 --
# XSS: 输入 <script>alert(1)</script>
# 命令注入: 输入 ; ls -la
# LDAP 注入、模板注入 (SSTI)
# A07 - 认证缺陷
# 暴力破解: 是否有速率限制
# 默认凭证: admin/admin, root/root
# Session 管理: 登出后 session 是否失效OWASP ZAP 扫描
# ZAP 基线扫描(适合 CI/CD)
docker run -t ghcr.io/zaproxy/zaproxy:stable zap-baseline.py \
-t https://example.com \
-r report.html
# ZAP 全面扫描
docker run -t ghcr.io/zaproxy/zaproxy:stable zap-full-scan.py \
-t https://example.com \
-r full-report.html
# ZAP API 扫描
docker run -t ghcr.io/zaproxy/zaproxy:stable zap-api-scan.py \
-t https://example.com/openapi.json \
-f openapi \
-r api-report.html阶段 5: 后渗透
# Linux 权限提升检查
# 查找 SUID 文件
find / -perm -4000 -type f 2>/dev/null
# 查找可写的敏感文件
find /etc -writable -type f 2>/dev/null
# 检查 cron 任务
cat /etc/crontab
ls -la /etc/cron.*
# 内核版本(检查是否有已知提权漏洞)
uname -a
cat /etc/os-release
# 网络信息
ip addr
ss -tlnp
cat /etc/hosts阶段 6: 报告撰写
报告结构
1. 执行摘要(面向管理层)
- 测试范围和方法
- 关键发现总结
- 风险等级概览
- 优先修复建议
2. 技术细节(面向技术团队)
- 每个漏洞的详细描述
- 复现步骤(PoC)
- 影响分析
- 修复建议
- 参考资料(CVE、CWE)
3. 附录
- 测试工具列表
- 扫描报告原始数据
- 证据截图漏洞评级(CVSS)
常用工具速查
| 阶段 | 工具 | 用途 |
|---|---|---|
| 信息收集 | Nmap, Shodan, subfinder | 端口扫描、子域名枚举 |
| Web 扫描 | Burp Suite, ZAP, Nuclei | Web 漏洞扫描 |
| 目录枚举 | Gobuster, Feroxbuster | 隐藏路径发现 |
| 漏洞利用 | Metasploit, sqlmap | 自动化利用 |
| 密码破解 | Hashcat, John the Ripper | 密码哈希破解 |
| 后渗透 | LinPEAS, WinPEAS | 本地提权检查 |
| 流量分析 | Wireshark, tcpdump | 网络流量捕获 |
法律与伦理
最佳实践
- 必须获得书面授权后才能开始测试,明确范围和边界
- 从被动侦察开始,逐步升级到主动扫描,减少对目标的影响
- 所有操作留痕,详细记录每一步操作和时间戳
- 发现严重漏洞立即通报,不等到测试结束
- 不要造成实际损害,避免 DoS、数据删除等破坏性操作
- 使用 CVSS 标准化漏洞评级,便于优先级排序
- 修复建议要具体可行,不要只说"修复 XSS 漏洞",要给出具体的编码方案
- 测试完成后清理所有痕迹,删除上传的文件、创建的账户等
贡献者
更新日志
2026/3/14 13:09
查看所有更新日志
9f6c2-feat: organize wiki content and refresh site setup于