mcpField
R
recon-port-scan

recon-port-scan

github.com/crazymarky安全34985 次安装21 周前更新
代码仓库

关于 recon-port-scan

用于端口扫描与侦察的技能,介绍 nmap 以及可选的 masscan 和 rustscan。内容涵盖经授权的安全测试、服务与系统检测,并提供结果处理资源。

主要功能

  1. 01常用端口与全端口扫描
  2. 02服务与操作系统检测
  3. 03TCP 和 UDP 扫描
  4. 04masscan 与 rustscan 使用指南
  5. 05扫描结果解析与合并

适用场景

  1. 01检查获准测试主机的开放端口
  2. 02识别暴露的服务及版本
  3. 03扫描大型地址范围
  4. 04合并并查看扫描结果

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/crazymarky/pentest-skills --skill recon-port-scan

安装后在 Claude Code 中输入/recon-port-scan确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

assets/
common-services.txt
top-100-ports.txt
top-1000-ports.txt
references/
masscan_guide.md
nmap_cheatsheet.md
rustscan_guide.md
scanning_techniques.md
scripts/
masscan_to_nmap.py
merge_scan_results.py
parse_nmap_xml.py
port_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

工具选择指南

场景推荐工具命令
快速扫描常用端口nmapnmap -T4 -F <target>
扫描完整端口范围nmapnmap -p- <target>
检测服务版本nmapnmap -sV -sC <target>
大型网络/速度至关重要masscanmasscan -p1-65535 <target> --rate=10000
需要隐蔽扫描nmapsudo nmap -sS -T2 <target>
发现 UDP 服务nmapnmap -sU --top-ports 100 <target>
OS 指纹识别nmapsudo nmap -O <target>
现代快速工作流rustscanrustscan -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>

常见端口列表

常见服务端口参考:

端口服务
21FTP
22SSH
23Telnet
25SMTP
53DNS
80, 8080, 8443HTTP
110POP3
135, 139, 445SMB
143, 993IMAP
443, 8443HTTPS
3306MySQL
3389RDP
5432PostgreSQL
5900VNC
6379Redis
27017MongoDB

资源

脚本
  • 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