jpskill.com
🛠️ 開発・MCP コミュニティ

nmap

Professional network reconnaissance and port scanning using nmap. Supports various scan types (quick, full, UDP, stealth), service detection, vulnerability scanning, and NSE scripts. Use when you need to enumerate network services, detect versions, or perform network reconnaissance.

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o nmap.zip https://jpskill.com/download/17610.zip && unzip -o nmap.zip && rm nmap.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/17610.zip -OutFile "$d\nmap.zip"; Expand-Archive "$d\nmap.zip" -DestinationPath $d -Force; ri "$d\nmap.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して nmap.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → nmap フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

Nmap スキャン - プロフェッショナルなネットワーク偵察

あなたは、nmap を使用してプロフェッショナルなネットワーク偵察とポートスキャンを実行するユーザーを支援しています。このスキルは、さまざまなスキャンタイプ、出力形式、および結果分析に関するガイダンスを提供します。

出力ディレクトリ

ディレクトリ構造

nmap-output/
├── nmap-portscan.nmap      # 初期高速ポート検出
├── nmap-portscan.xml
├── nmap-portscan.gnmap
├── nmap-services.nmap      # オープンポートでの詳細なサービス検出
├── nmap-services.xml
└── nmap-services.gnmap

重要: nmap の出力は常に整理されたディレクトリ構造に保存してください。デフォルトでは、./nmap-output/ を使用するか、カスタムディレクトリを指定します。

デフォルトのスキャン戦略

重要: ユーザーが別のスキャンタイプを明示的に要求しない限り、常にこの2段階のアプローチを使用してください。

フェーズ 1: 高速ポート検出 (Root SYN スキャン)

sudo nmap -p- <target> -oA <output-dir>/nmap-portscan
  • sudo が必要な理由: root として実行すると、高速な SYN スキャンが有効になります (-sS は暗黙的)。
  • -p- が必要な理由: 65535 個すべてのポートを迅速にスキャンします。
  • 期間: 通常、SYN スキャンで 1〜3 分です。
  • 出力: すべてのオープンポートのリスト

ホストダウンの検出: スキャン出力に「Note: Host seems down」が含まれている場合は、自動的に以下を再試行してください。

sudo nmap -p- -Pn <target> -oA <output-dir>/nmap-portscan
  • -Pn: ホスト検出をスキップし、ホストをオンラインとして扱います。
  • ファイアウォールが ping プローブをブロックする場合に使用します。

フェーズ 2: ターゲットを絞ったサービス検出

フェーズ 1 が完了したら、オープンポートを解析して以下を実行します。

nmap -p <OPEN_PORT_LIST> -sV -sC <target> -oA <output-dir>/nmap-services
  • -p <OPEN_PORT_LIST>: オープンであることが判明したポートのみをスキャンします (例: -p 23,80,443,554,8000)。
  • -sV: サービスバージョン検出
  • -sC: 追加の列挙のためにデフォルトの NSE スクリプトを実行します。
  • 期間: 既知のオープンポートのみをスキャンするため、通常は 1〜3 分です。

この戦略の利点

  1. 速度: 高速な SYN スキャンは、1〜3 分ですべてのオープンポートを見つけます。
  2. 網羅性: 上位 1000 ポートだけでなく、65535 個すべてのポートをカバーします。
  3. 効率: サービス検出は、確認済みのオープンポートでのみ実行されます。
  4. 精度: 2 段階のアプローチにより、偽陰性が減少します。

オープンポートの解析

フェーズ 1 の後、以下を使用してオープンポートを抽出します。

# .gnmap ファイルからオープンポートを抽出
grep "Ports:" <output-dir>/nmap-portscan.gnmap | sed 's/.*Ports: //g' | sed 's|/|\n|g' | grep "open" | cut -d'/' -f1 | tr '\n' ',' | sed 's/,$//'

または、.nmap ファイルから解析します。

grep "^[0-9]" <output-dir>/nmap-portscan.nmap | grep "open" | cut -d'/' -f1 | tr '\n' ',' | sed 's/,$//'

実装ワークフロー

nmap-scan スキルが呼び出された場合:

  1. 出力ディレクトリを作成

    OUTPUT_DIR="./nmap-output"
    mkdir -p "$OUTPUT_DIR"
  2. フェーズ 1: 高速ポート検出を実行

    sudo nmap -p- <target> -oA "$OUTPUT_DIR/nmap-portscan"
  3. 「Host seems down」エラーを確認

    if grep -q "Host seems down" "$OUTPUT_DIR/nmap-portscan.nmap"; then
        echo "Host appears down, retrying with -Pn flag..."
        sudo nmap -p- -Pn <target> -oA "$OUTPUT_DIR/nmap-portscan"
    fi
  4. 結果からオープンポートを解析

    OPEN_PORTS=$(grep "^[0-9]" "$OUTPUT_DIR/nmap-portscan.nmap" | grep "open" | cut -d'/' -f1 | tr '\n' ',' | sed 's/,$//')
  5. フェーズ 2: オープンポートでのサービス検出を実行

    if [ -n "$OPEN_PORTS" ]; then
        nmap -p "$OPEN_PORTS" -sV -sC <target> -oA "$OUTPUT_DIR/nmap-services"
    else
        echo "No open ports found, skipping service detection."
    fi
  6. 結果の場所を報告

    echo "Scan complete. Results saved to: $OUTPUT_DIR"

スキャンタイプ

クイックスキャン (上位 1000 ポート)

初期偵察または時間が限られている場合に使用します。

nmap -sV -sC <target> -oA <output-prefix>
  • -sV: サービスバージョン検出
  • -sC: デフォルトの NSE スクリプトを実行
  • -oA: すべての形式 (normal, XML, grepable) で出力
  • 上位 1000 個の最も一般的なポートをスキャンします。
  • 通常の期間: 1〜3 分

包括的なスキャン (すべてのポート)

すべてのポートをチェックする必要がある場合に、徹底的な評価のために使用します。

nmap -sV -sC -p- <target> -oA <output-prefix>
  • -p-: 65535 個すべてのポートをスキャンします。
  • 期間が大幅に長くなります (ターゲットに応じて 5〜30 分以上)。
  • 包括的なカバレッジが必要な場合にのみ使用してください。

ステルス SYN スキャン

検出を回避しようとする場合に使用します (root/sudo が必要)。

sudo nmap -sS -sV -sC <target> -oA <output-prefix>
  • -sS: SYN ステルススキャン (TCP ハンドシェイクを完了しません)。
  • ターゲットによってログに記録される可能性が低くなります。
  • root 権限が必要です。

UDP スキャン

UDP サービスを列挙する必要がある場合に使用します。

sudo nmap -sU --top-ports 100 <target> -oA <output-prefix>
  • -sU: UDP スキャン
  • --top-ports 100: 上位 100 個の UDP ポートをスキャンします (UDP スキャンは遅いです)。
  • 一般的な UDP サービス: DNS (53)、SNMP (161)、DHCP (67/68)
  • 非常に遅い - スコープを制限するために top-ports を使用します。

アグレッシブスキャン

最大限の情報収集に使用します (ノイズが多い)。

nmap -A -T4 <target> -oA <output-prefix>
  • -A: OS 検出、バージョン検出、スクリプトスキャン、traceroute を有効にします。
  • -T4: アグレッシブなタイミングテンプレート (より高速ですが、検出されやすい)。
  • 非常にノイズが多い - IDS/IPS によって検出されます。
  • 承認を得てからのみ使用してください。

脆弱性スキャン

既知の脆弱性をチェックするために使用します。

nmap -sV --script vuln <target> -oA <output-prefix>
  • --script vuln: NSE 脆弱性検出スクリプトを実行します。
  • 一般的な CVE および構成ミスをチェックします。
  • ノイズが多く、アラートをトリガーする可能性があります。

OS 検出

オペレーティングシステムを識別するために使用します。

sudo nmap -O <target> -oA <output-prefix>
  • -O: OS 検出を有効にします。
  • root 権限が必要です。
  • TCP/IP スタックフィンガープリンティングを使用します。

代替スキャンタイプ

次のスキャンタイプは、ユーザーがデフォルトの 2 段階戦略の代わりに明示的に要求した場合に利用できます。

クイックスキャン (上位 1000 ポートのみ)

ユーザーがクイック/高速スキャンを明示的に要求した場合にのみ使用してください。

nmap -sV -sC <target> -oA <output-dir>/nmap-quick
  • -sV: サービスバージョン検出
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Nmap Scan - Professional Network Reconnaissance

You are helping the user perform professional network reconnaissance and port scanning using nmap. This skill provides guidance for various scan types, output formats, and result analysis.

Output Directory

Directory Structure

nmap-output/
├── nmap-portscan.nmap      # Initial fast port discovery
├── nmap-portscan.xml
├── nmap-portscan.gnmap
├── nmap-services.nmap      # Detailed service detection on open ports
├── nmap-services.xml
└── nmap-services.gnmap

IMPORTANT: Always save nmap output to an organized directory structure. By default, use ./nmap-output/ or specify a custom directory.

Default Scanning Strategy

IMPORTANT: Unless the user explicitly requests a different scan type, ALWAYS use this two-phase approach:

Phase 1: Fast Port Discovery (Root SYN Scan)

sudo nmap -p- <target> -oA <output-dir>/nmap-portscan
  • Why sudo: Running as root enables fast SYN scan (-sS is implicit)
  • Why -p-: Scans all 65535 ports quickly
  • Duration: Typically 1-3 minutes for SYN scan
  • Output: List of all open ports

Host Down Detection: If the scan output contains "Note: Host seems down", automatically retry with:

sudo nmap -p- -Pn <target> -oA <output-dir>/nmap-portscan
  • -Pn: Skip host discovery, treat host as online
  • Use this when firewalls block ping probes

Phase 2: Targeted Service Detection

After Phase 1 completes, parse the open ports and run:

nmap -p <OPEN_PORT_LIST> -sV -sC <target> -oA <output-dir>/nmap-services
  • -p <OPEN_PORT_LIST>: Only scan the ports found to be open (e.g., -p 23,80,443,554,8000)
  • -sV: Service version detection
  • -sC: Run default NSE scripts for additional enumeration
  • Duration: Usually 1-3 minutes since only scanning known open ports

Why This Strategy?

  1. Speed: Fast SYN scan finds all open ports in 1-3 minutes
  2. Thoroughness: Covers all 65535 ports, not just top 1000
  3. Efficiency: Service detection only runs on confirmed open ports
  4. Accuracy: Two-phase approach reduces false negatives

Parsing Open Ports

After Phase 1, extract open ports using:

# Extract open ports from .gnmap file
grep "Ports:" <output-dir>/nmap-portscan.gnmap | sed 's/.*Ports: //g' | sed 's|/|\n|g' | grep "open" | cut -d'/' -f1 | tr '\n' ',' | sed 's/,$//'

Or parse from .nmap file:

grep "^[0-9]" <output-dir>/nmap-portscan.nmap | grep "open" | cut -d'/' -f1 | tr '\n' ',' | sed 's/,$//'

Implementation Workflow

When the nmap-scan skill is invoked:

  1. Create output directory

    OUTPUT_DIR="./nmap-output"
    mkdir -p "$OUTPUT_DIR"
  2. Run Phase 1: Fast port discovery

    sudo nmap -p- <target> -oA "$OUTPUT_DIR/nmap-portscan"
  3. Check for "Host seems down" error

    if grep -q "Host seems down" "$OUTPUT_DIR/nmap-portscan.nmap"; then
        echo "Host appears down, retrying with -Pn flag..."
        sudo nmap -p- -Pn <target> -oA "$OUTPUT_DIR/nmap-portscan"
    fi
  4. Parse open ports from results

    OPEN_PORTS=$(grep "^[0-9]" "$OUTPUT_DIR/nmap-portscan.nmap" | grep "open" | cut -d'/' -f1 | tr '\n' ',' | sed 's/,$//')
  5. Run Phase 2: Service detection on open ports

    if [ -n "$OPEN_PORTS" ]; then
        nmap -p "$OPEN_PORTS" -sV -sC <target> -oA "$OUTPUT_DIR/nmap-services"
    else
        echo "No open ports found, skipping service detection."
    fi
  6. Report results location

    echo "Scan complete. Results saved to: $OUTPUT_DIR"

Scan Types

Quick Scan (Top 1000 Ports)

Use for initial reconnaissance or when time is limited:

nmap -sV -sC <target> -oA <output-prefix>
  • -sV: Service version detection
  • -sC: Run default NSE scripts
  • -oA: Output in all formats (normal, XML, grepable)
  • Scans top 1000 most common ports
  • Typical duration: 1-3 minutes

Comprehensive Scan (All Ports)

Use for thorough assessment when all ports must be checked:

nmap -sV -sC -p- <target> -oA <output-prefix>
  • -p-: Scan all 65535 ports
  • Significantly longer duration (5-30+ minutes depending on target)
  • Use only when comprehensive coverage is required

Stealth SYN Scan

Use when trying to avoid detection (requires root/sudo):

sudo nmap -sS -sV -sC <target> -oA <output-prefix>
  • -sS: SYN stealth scan (doesn't complete TCP handshake)
  • Less likely to be logged by target
  • Requires root privileges

UDP Scan

Use when UDP services need to be enumerated:

sudo nmap -sU --top-ports 100 <target> -oA <output-prefix>
  • -sU: UDP scan
  • --top-ports 100: Scan top 100 UDP ports (UDP scanning is slow)
  • Common UDP services: DNS (53), SNMP (161), DHCP (67/68)
  • Very slow - use top-ports to limit scope

Aggressive Scan

Use for maximum information gathering (noisy):

nmap -A -T4 <target> -oA <output-prefix>
  • -A: Enable OS detection, version detection, script scanning, traceroute
  • -T4: Aggressive timing template (faster but more detectable)
  • Very noisy - will be detected by IDS/IPS
  • Use only with authorization

Vulnerability Scan

Use to check for known vulnerabilities:

nmap -sV --script vuln <target> -oA <output-prefix>
  • --script vuln: Run NSE vulnerability detection scripts
  • Checks for common CVEs and misconfigurations
  • Can be noisy and trigger alerts

OS Detection

Use to identify operating system:

sudo nmap -O <target> -oA <output-prefix>
  • -O: Enable OS detection
  • Requires root privileges
  • Uses TCP/IP stack fingerprinting

Alternative Scan Types

The following scan types are available if the user explicitly requests them instead of the default two-phase strategy:

Quick Scan (Top 1000 Ports Only)

Use ONLY if user explicitly requests a quick/fast scan:

nmap -sV -sC <target> -oA <output-dir>/nmap-quick
  • -sV: Service version detection
  • -sC: Run default NSE scripts
  • -oA: Output in all formats (normal, XML, grepable)
  • Scans top 1000 most common ports ONLY
  • Typical duration: 1-3 minutes
  • Limitation: May miss services on non-standard ports

Scan Workflow

Default Workflow (Two-Phase Strategy)

Phase 1: Port Discovery

  1. Run fast SYN scan: sudo nmap -p- <target> -oA <output-dir>/nmap-portscan
  2. Check for "Host seems down" and retry with -Pn if needed
  3. Wait for scan to complete (typically 1-3 minutes)

Phase 2: Service Detection 4. Parse open ports from Phase 1 results 5. Run targeted service detection: nmap -p <OPEN_PORTS> -sV -sC <target> -oA <output-dir>/nmap-services 6. Wait for scan to complete (typically 1-3 minutes)

Phase 3: Analysis 7. Review the service detection results to determine:

  • What services are running?
  • What versions are detected?
  • Are there any interesting services (web, SSH, database, IoT protocols)?
  • Do NSE scripts reveal any issues?

Additional Targeted Scans (Optional)

Based on service detection results, run specialized scans:

If web services found (80, 443, 8080, etc.):

nmap -p 80,443,8080,8443 --script http-* <target> -oA <output-dir>/nmap-web

If SSH found:

nmap -p 22 --script ssh-* <target> -oA <output-dir>/nmap-ssh

If RTSP found (554):

nmap -p 554 --script rtsp-* <target> -oA <output-dir>/nmap-rtsp

If ONVIF/camera suspected:

nmap -p 80,554,8000,8080 --script http-methods,http-headers <target> -oA <output-dir>/nmap-onvif

Output Management

Output Formats

Always use -oA <prefix> to generate all three formats:

  • .nmap - Normal human-readable format
  • .xml - XML format for parsing/importing into tools
  • .gnmap - Grepable format for command-line processing

Timing and Performance

Timing Templates

Use -T<0-5> to control scan speed:

  • -T0 (Paranoid): Extremely slow, for IDS evasion
  • -T1 (Sneaky): Very slow, for IDS evasion
  • -T2 (Polite): Slow, less bandwidth intensive
  • -T3 (Normal): Default, balanced speed
  • -T4 (Aggressive): Fast, recommended for modern networks
  • -T5 (Insane): Very fast, may miss results

Default: Use -T3 or omit (default is T3) Fast scans: Use -T4 when speed is important and network can handle it Stealth: Use -T1 or -T2 for evasion

Timeout Considerations

  • Phase 1 Port Discovery (sudo nmap -p-): 180-300 seconds timeout (3-5 minutes)
  • Phase 2 Service Detection (nmap -p <ports> -sV -sC): 120-180 seconds timeout (2-3 minutes)
  • UDP scan: 600+ seconds timeout (very slow)

Network Ranges

Single Host

nmap <ip-address>

CIDR Notation

nmap 192.168.1.0/24

IP Range

nmap 192.168.1.1-254

Multiple Hosts

nmap 192.168.1.1 192.168.1.10 192.168.1.100

Exclude Hosts

nmap 192.168.1.0/24 --exclude 192.168.1.1,192.168.1.254

NSE Scripts

Common Script Categories

# Authentication scripts
nmap --script auth <target>

# Brute force scripts
nmap --script brute <target>

# Default safe scripts
nmap -sC <target>  # equivalent to --script default

# Discovery scripts
nmap --script discovery <target>

# Vulnerability scripts
nmap --script vuln <target>

# All HTTP scripts
nmap --script "http-*" <target>

IoT-Specific Scripts

# RTSP enumeration
nmap -p 554 --script rtsp-methods,rtsp-url-brute <target>

# UPnP discovery
nmap -p 1900 --script upnp-info <target>

# MQTT discovery
nmap -p 1883,8883 --script mqtt-subscribe <target>

# Modbus enumeration
nmap -p 502 --script modbus-discover <target>

Result Analysis

Key Information to Extract

  1. Open Ports and Services

    • What ports are open?
    • What services are running?
    • What versions are detected?
  2. Service Fingerprints

    • Does version detection reveal outdated software?
    • Are there known vulnerabilities for detected versions?
  3. NSE Script Results

    • Authentication issues?
    • Information disclosure?
    • Misconfigurations?
  4. Operating System

    • What OS is running?
    • What OS version?

Parsing Nmap Output

Extract open ports:

grep "^[0-9]" nmap-output.nmap | grep "open"

Extract service versions:

grep -E "^[0-9]+/tcp.*open" nmap-output.nmap

Check for vulnerabilities in NSE output:

grep -i "vuln\|cve\|exploit" nmap-output.nmap

Common IoT Service Ports

When scanning IoT devices, pay special attention to:

Port Service Description
21 FTP File transfer (often misconfigured)
22 SSH Remote administration
23 Telnet Insecure remote access
80 HTTP Web interface
443 HTTPS Secure web interface
554 RTSP Video streaming
1883 MQTT IoT messaging protocol
3702 WS-Discovery ONVIF device discovery
5000 UPnP Universal Plug and Play
8000 HTTP Alt Alternative HTTP port
8080 HTTP Proxy Alternative HTTP port
8883 MQTT/TLS Secure MQTT

Best Practices

1. Always Save Output

Never run nmap without saving output:

# GOOD
nmap -p <ports> -sV -sC <target> -oA output/nmap-services

# BAD
nmap -sV -sC <target>

2. Always Use Two-Phase Strategy

Always use the default two-phase strategy unless explicitly told otherwise:

# Phase 1: Fast port discovery
sudo nmap -p- <target> -oA nmap-portscan

# Phase 2: Service detection on open ports
nmap -p <OPEN_PORTS> -sV -sC <target> -oA nmap-services

3. Use Appropriate Timing

Match timing to your needs:

# Pentest with authorization: Fast
nmap -sV -sC -T4 <target>

# Red team/stealth: Slow
nmap -sV -sC -T2 <target>

4. Document Scan Parameters

Always document:

  • What scan type was used?
  • What date/time was scan performed?
  • What were the scan results?
  • Any anomalies or errors?

5. Respect Authorization

  • Only scan systems you have permission to scan
  • Respect scope limitations
  • Be aware of scan impact on production systems
  • Use appropriate timing to avoid DoS

Integration with IoT Testing Workflow

For IoT Pentests

  1. Run default two-phase scan (port discovery + service detection)
  2. Run wsdiscovery if ONVIF suspected based on open ports
  3. Run onvifscan if port 80/554 open on camera
  4. Run targeted HTTP scripts if web interface found

Output Directory Usage

Always save to an organized output directory:

OUTPUT_DIR="./nmap-output"
mkdir -p "$OUTPUT_DIR"

# Phase 1: Port discovery
sudo nmap -p- <target> -oA "$OUTPUT_DIR/nmap-portscan"

# Phase 2: Service detection
nmap -p <OPEN_PORTS> -sV -sC <target> -oA "$OUTPUT_DIR/nmap-services"

Troubleshooting

Scan Taking Too Long

  • Use -T4 for faster scanning
  • Limit port range: -p 1-1000 instead of -p-
  • Use --top-ports 100 instead of all ports

No Results / Firewalled

  • Try different scan types: -sS, -sT, -sA
  • Use -Pn to skip host discovery
  • Try -f for fragmented packets
  • Consider using --source-port 53 or other trusted ports

Requires Root/Sudo

These scan types require root:

  • -sS (SYN scan)
  • -sU (UDP scan)
  • -O (OS detection)
  • Raw packet features

Permission Denied Errors

If you see "Permission denied" or "Operation not permitted":

# Run with sudo
sudo nmap <options> <target>

Example Workflows

Workflow 1: Standard Single Target Scan (Default)

TARGET="192.168.1.100"
OUTPUT_DIR="./nmap-output"
mkdir -p "$OUTPUT_DIR"

# Phase 1: Fast port discovery
sudo nmap -p- $TARGET -oA "$OUTPUT_DIR/nmap-portscan"

# Check for "Host seems down"
if grep -q "Host seems down" "$OUTPUT_DIR/nmap-portscan.nmap"; then
    sudo nmap -p- -Pn $TARGET -oA "$OUTPUT_DIR/nmap-portscan"
fi

# Parse open ports
OPEN_PORTS=$(grep "^[0-9]" "$OUTPUT_DIR/nmap-portscan.nmap" | grep "open" | cut -d'/' -f1 | tr '\n' ',' | sed 's/,$//')

# Phase 2: Service detection
if [ -n "$OPEN_PORTS" ]; then
    nmap -p "$OPEN_PORTS" -sV -sC $TARGET -oA "$OUTPUT_DIR/nmap-services"
fi

Workflow 2: IoT Camera Testing

OUTPUT_DIR="./nmap-output"
mkdir -p "$OUTPUT_DIR"

# 1. Run default two-phase scan
sudo nmap -p- 192.168.1.100 -oA "$OUTPUT_DIR/nmap-portscan"
OPEN_PORTS=$(grep "^[0-9]" "$OUTPUT_DIR/nmap-portscan.nmap" | grep "open" | cut -d'/' -f1 | tr '\n' ',' | sed 's/,$//')
nmap -p "$OPEN_PORTS" -sV -sC 192.168.1.100 -oA "$OUTPUT_DIR/nmap-services"

# 2. If ONVIF camera detected, check HTTP methods
nmap -p 80 --script http-methods 192.168.1.100 -oA "$OUTPUT_DIR/nmap-http"

# 3. Check RTSP service
nmap -p 554 --script rtsp-methods 192.168.1.100 -oA "$OUTPUT_DIR/nmap-rtsp"

Workflow 3: Additional UDP/OS Detection

OUTPUT_DIR="./nmap-output"

# After completing default two-phase scan, optionally add:

# UDP scan (top ports)
sudo nmap -sU --top-ports 100 <target> -oA "$OUTPUT_DIR/nmap-udp"

# OS detection
sudo nmap -O <target> -oA "$OUTPUT_DIR/nmap-os"

# Vulnerability scan
nmap -sV --script vuln <target> -oA "$OUTPUT_DIR/nmap-vuln"

Questions to Ask User

Before starting scans, clarify:

  1. Target: What is the IP address or network range?
  2. Scope: Single host or network range?
  3. Scan Type: Use default two-phase strategy or user has specific requirements?
  4. Authorization: Do you have permission to scan this target?
  5. Special interests: Any specific services or ports to focus on after initial scan?

Note: Output is saved to ./nmap-output/ by default.

Success Criteria

A successful nmap scan includes:

  • Phase 1 port discovery completed without errors
  • Phase 2 service detection completed on all open ports
  • Results saved in all formats (-oA) in output directory
  • Open ports identified with service versions
  • NSE scripts executed successfully
  • Results documented and ready for analysis
  • Clear summary provided showing:
    • Number of open ports found
    • Key services detected
    • Location of output files