关于 recon-port-scan
用于端口扫描与侦察的技能,介绍 nmap 以及可选的 masscan 和 rustscan。内容涵盖经授权的安全测试、服务与系统检测,并提供结果处理资源。
主要功能
- 01常用端口与全端口扫描
- 02服务与操作系统检测
- 03TCP 和 UDP 扫描
- 04masscan 与 rustscan 使用指南
- 05扫描结果解析与合并
适用场景
- 01检查获准测试主机的开放端口
- 02识别暴露的服务及版本
- 03扫描大型地址范围
- 04合并并查看扫描结果
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ crazymarky/ pentest-skills --skill recon-port-scan安装后在 Claude Code 中输入/recon-port-scan确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
assets/common-services.txttop-100-ports.txttop-1000-ports.txtreferences/masscan_guide.mdnmap_cheatsheet.mdrustscan_guide.mdscanning_techniques.mdscripts/masscan_to_nmap.pymerge_scan_results.pyparse_nmap_xml.pyport_scan_storage.py详细介绍
端口扫描 / 侦察
授权警告
重要: 未经适当授权进行端口扫描是违法的。请务必确保已获得:
- 目标系统所有者的书面许可
- 明确的授权测试范围
- 符合当地法规
前提条件
系统上必须安装以下工具:
- nmap -
sudo apt install nmap(Debian/Ubuntu)或brew install nmap(macOS)
可选工具:
- masscan - 高速端口扫描器
- rustscan - 集成 nmap 的现代快速扫描器
快速开始
最常用的端口扫描命令:
快速扫描常见端口
nmap -T4 -F <target>
快速扫描排名前 100 的常见端口。
全端口扫描并检测服务
nmap -sV -sC -p- <target>
扫描全部 65535 个端口,并检测版本及运行默认脚本。
隐蔽 SYN 扫描
sudo nmap -sS -T2 -p- <target>
隐蔽扫描(需要 root 权限)。
高速扫描大范围目标
masscan -p1-65535 <target/CIDR> --rate=10000
快速扫描大范围 IP 地址段。
常见场景
场景 1:快速侦察
需要快速获取常见端口的扫描结果时:
nmap -T4 -F <target>
参数:
-T4- 激进的时间模板(速度更快)-F- 快速模式,扫描排名前 100 的端口<target>- IP 地址、主机名或 CIDR 地址段
示例:
nmap -T4 -F 192.168.1.100
nmap -T4 -F example.com
nmap -T4 -F 192.168.1.0/24
场景 2:发现完整端口范围
需要查找所有开放端口(1-65535)时:
nmap -p- <target>
参数:
-p-- 扫描全部 65535 个端口
示例:
nmap -p- 192.168.1.100
启用版本检测:
nmap -sV -p- <target>
场景 3:检测服务版本
需要识别正在运行的服务版本时:
nmap -sV -sC <target>
参数:
-sV- 探测开放端口以获取服务/版本信息-sC- 运行默认 NSE 脚本
示例:
nmap -sV -sC 192.168.1.100
更激进的版本检测:
nmap -sV --version-intensity 7 <target>
场景 4:隐蔽扫描
需要避免被检测到时:
sudo nmap -sS -T2 -f --data-length 24 <target>
参数:
-sS- SYN 扫描(比 connect 扫描更隐蔽)-T2- 礼貌的时间设置(速度较慢,不太可疑)-f- 对数据包进行分片--data-length 24- 向数据包附加随机数据
示例:
sudo nmap -sS -T2 -f 192.168.1.100
诱饵扫描:
sudo nmap -D RND:10 -sS <target>
场景 5:UDP 端口扫描
需要发现 UDP 服务时:
nmap -sU --top-ports 100 <target>
参数:
-sU- UDP 扫描--top-ports 100- 扫描最常见的 100 个 UDP 端口
示例:
nmap -sU --top-ports 100 192.168.1.100
同时扫描 TCP 和 UDP:
nmap -sS -sU <target>
场景 6:操作系统指纹识别
需要识别操作系统时:
sudo nmap -O <target>
参数:
-O- 启用操作系统检测
示例:
sudo nmap -O 192.168.1.100
同时进行版本检测:
sudo nmap -sV -O <target>
场景 7:高速大规模扫描
扫描大范围 IP 地址段时:
masscan -p1-65535 <CIDR> --rate=10000 -oL output.txt
参数:
-p1-65535- 端口范围--rate=10000- 每秒发送的数据包数(请根据带宽调整)-oL output.txt- 将结果保存到文件
示例:
masscan -p1-65535 192.168.1.0/24 --rate=10000 -oL scan_results.txt
后续使用 nmap 进行详细扫描:
# First, masscan to find open ports
masscan -p1-65535 192.168.1.0/24 --rate=10000 -oL - | grep open > open_ports.txt
# Then, nmap for service details on discovered ports
nmap -sV -p 80,443,22,3306 192.168.1.100
场景 8:RustScan(现代快速扫描器)
rustscan -a <target> -- -sV
参数:
-a- 目标地址--- nmap 参数分隔符(参数会传递给 nmap)
示例:
rustscan -a 192.168.1.100 -- -sV -sC
场景 9:输出格式
以不同格式保存结果:
# All formats (normal, XML, grepable)
nmap -oA output <target>
# XML only (for parsing)
nmap -oX output.xml <target>
# Grepable format
nmap -oG output.gnmap <target>
# Normal output to file
nmap -oN output.txt <target>
示例:
nmap -sV -p- -oA scan_results 192.168.1.100
# Creates: scan_results.nmap, scan_results.xml, scan_results.gnmap
工具选择指南
| 场景 | 推荐工具 | 命令 |
|---|---|---|
| 快速扫描常用端口 | nmap | nmap -T4 -F <target> |
| 扫描完整端口范围 | nmap | nmap -p- <target> |
| 检测服务版本 | nmap | nmap -sV -sC <target> |
| 大型网络/速度至关重要 | masscan | masscan -p1-65535 <target> --rate=10000 |
| 需要隐蔽扫描 | nmap | sudo nmap -sS -T2 <target> |
| 发现 UDP 服务 | nmap | nmap -sU --top-ports 100 <target> |
| OS 指纹识别 | nmap | sudo nmap -O <target> |
| 现代快速工作流 | rustscan | rustscan -a <target> -- -sV |
工具对比:
| 工具 | 速度 | 准确性 | 功能 | 用途 |
|---|---|---|---|---|
| nmap | 中等 | 高 | 功能最全面 | 通用 |
| masscan | 非常快 | 中等 | 基本端口扫描 | 大型网络 |
| rustscan | 快 | 高 | 集成 nmap | 现代工作流 |
时间模板
使用时间模板调整扫描速度(0-5):
| 级别 | 名称 | 描述 |
|---|---|---|
-T0 | 偏执 | 非常慢,用于规避 IDS |
-T1 | 隐蔽 | 慢速,用于规避 IDS |
-T2 | 礼貌 | 中慢速,降低负载 |
-T3 | 正常 | 默认速度 |
-T4 | 激进 | 快速,推荐 |
-T5 | 疯狂 | 非常快,可能不准确 |
示例:
nmap -T4 <target> # Fast scan (recommended)
nmap -T2 <target> # Slower, more stealthy
nmap -T5 <target> # Maximum speed (may miss ports)
脚本类别
NSE(Nmap 脚本引擎)脚本类别:
# Vulnerability detection
nmap --script=vuln <target>
# Auth bypass detection
nmap --script=auth <target>
# Brute force
nmap --script=brute <target>
# Information gathering
nmap --script=discovery,info <target>
常见端口列表
常见服务端口参考:
| 端口 | 服务 |
|---|---|
| 21 | FTP |
| 22 | SSH |
| 23 | Telnet |
| 25 | SMTP |
| 53 | DNS |
| 80, 8080, 8443 | HTTP |
| 110 | POP3 |
| 135, 139, 445 | SMB |
| 143, 993 | IMAP |
| 443, 8443 | HTTPS |
| 3306 | MySQL |
| 3389 | RDP |
| 5432 | PostgreSQL |
| 5900 | VNC |
| 6379 | Redis |
| 27017 | MongoDB |
资源
脚本
scripts/parse_nmap_xml.py- 将 nmap XML 输出解析为结构化 JSON 格式scripts/masscan_to_nmap.py- 将 masscan 结果转换为兼容 nmap 的格式scripts/merge_scan_results.py- 合并多个扫描结果文件
参考资料
references/nmap_cheatsheet.md- 全面的 nmap 参考指南references/masscan_guide.md- 详细的 masscan 使用文档references/rustscan_guide.md- RustScan 快速参考references/scanning_techniques.md- 高级扫描技术和规避方法
资源文件
assets/top-1000-ports.txt- 1000 个常见端口列表assets/top-100-ports.txt- 100 个常见端口列表assets/common-services.txt- 常见服务指纹数据
场景 10:扫描结果的持久化存储
如果需要将端口扫描结果持久化到数据库,以便进行跨会话分析和报告:
# Generate XML scan output
nmap -sV -p- 192.168.1.0/24 -oX scan.xml
# Store to database (flat hierarchy - no subsystem)
python .claude/skills/recon-port-scan/scripts/port_scan_storage.py \
--xml-file scan.xml
# Store to database with subsystem
python .claude/skills/recon-port-scan/scripts/port_scan_storage.py \
--xml-file scan.xml \
--subsystem "External Network"
# Or pipe directly (flat hierarchy)
nmap -sV -p- target.com -oX - | \
python .claude/skills/recon-port-scan/scripts/port_scan_storage.py
# Or pipe directly (with subsystem)
nmap -sV -p- target.com -oX - | \
python .claude/skills/recon-port-scan/scripts/port_scan_storage.py \
--subsystem "DMZ"
参数:
--subsystem- 子系统名称(可选;省略则使用扁平层级结构)--scan-tool- 使用的扫描工具(默认:nmap)--xml-file- nmap XML 文件的路径(可选;未提供时从标准输入读取)
数据库位置: ./data/results.db
相关技能: results-storage - 查询数据、生成报告
评论
支持 Markdown