recon-port-scan について
ポートスキャンと偵察を扱うスキルで、nmapと任意のmasscan、rustscanの利用方法を説明します。許可されたセキュリティテスト向けに、サービスやOSの検出と結果処理の資料を提供します。
主な機能
- 01一般的なポートと全ポートのスキャン
- 02サービスとOSの検出
- 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 スキャン(コネクトスキャンよりステルス性が高い)-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:OS フィンガープリンティング
オペレーティングシステムを特定する必要がある場合:
sudo nmap -O <target>
パラメーター:
-O- OS 検出を有効化
例:
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- 1 秒あたりのパケット数(帯域幅に応じて調整)-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 | Paranoid | 非常に低速、IDS 回避 |
-T1 | Sneaky | 低速、IDS 回避 |
-T2 | Polite | 中~低速、負荷を軽減 |
-T3 | Normal | デフォルトの速度 |
-T4 | Aggressive | 高速、推奨 |
-T5 | Insane | 非常に高速、精度が低下する可能性あり |
例:
nmap -T4 <target> # Fast scan (recommended)
nmap -T2 <target> # Slower, more stealthy
nmap -T5 <target> # Maximum speed (may miss ports)
スクリプトのカテゴリ
NSE(Nmap Scripting Engine)のスクリプトカテゴリ:
# 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 - データのクエリ、レポートの生成