> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/ja/reconnaissance/nmap.md).

# Nmap

ポートスキャン、サービス検出、NSEスクリプト、ホスト探索、ファイアウォール回避、脆弱性スキャンに関する偵察メモ。

Nmapは偵察の際に、稼働中のホスト、開いているポート、サービスのバージョン、オペレーティングシステム、NSEスクリプトの結果、そして潜在的な攻撃経路を特定するために使用されます。

{% hint style="info" %}
**Nmap**、これは「*Network Mapper*」は、ネットワークを探索・監査し、ネットワーク上のホストやサービスを発見するために使用されるオープンソースツールです。これは当初、Fyodor Vaskovichとしても知られるGordon Lyonによって作成されました。Nmapはネットワークスキャン機能を提供し、ユーザーがネットワークに接続されたデバイスを見つけ、それらのデバイス上で実行中のサービスを特定し、ネットワーク構成に関する詳細な情報を取得できるようにします。
{% endhint %}

#### 一般的なコマンドとオプションの参照：

## Nmapオプションリファレンス

### ターゲットとホストの検出

| オプション                | 説明                                 |
| -------------------- | ---------------------------------- |
| `10.10.10.0/24`      | 対象ネットワーク範囲。                        |
| `-sL`                | リストスキャン。スキャンせずにターゲットを一覧表示します。      |
| `-sn`                | ポートスキャンを無効にし、ホスト検出のみを実行します。        |
| `-Pn`                | ホストをオンラインとして扱い、ホスト検出プローブをスキップします。  |
| `-n`                 | DNS解決を無効にします。                      |
| `-PE`                | ICMP Echo Requestを使用してホスト検出を実行します。 |
| `--disable-arp-ping` | ローカルネットワークでのARP ping要求を無効にします。     |
| `--dns-server <ns>`  | 指定したネームサーバーを使用してDNS解決を実行します。       |

### ポート選択とスキャンタイプ

| オプション               | 説明                                        |
| ------------------- | ----------------------------------------- |
| `--open`            | 開いているポートのみを表示します。                         |
| `--top-ports <num>` | 指定された数の最も一般的なポートをスキャンします。                 |
| `-p-`               | すべてのTCPポートをスキャンします。                       |
| `-p22-110`          | 22から110までのすべてのポートをスキャンします。                |
| `-p22,25`           | 指定されたポート22と25のみをスキャンします。                  |
| `-F`                | 高速スキャン。上位100ポートをスキャンします。                  |
| `-sS`               | TCP SYNスキャンを実行します。                        |
| `-sT`               | TCP接続スキャンを実行します。SYNスキャンの権限がない場合に便利です。     |
| `-sA`               | TCP ACKスキャンを実行します。ファイアウォールルールのマッピングに便利です。 |
| `-sU`               | UDPスキャンを実行します。                            |
| `-sV`               | 検出されたサービスのサービスバージョンを検出します。                |
| `-sC`               | 以下に分類されたNSEスクリプトを実行します `default`.         |
| `--script <script>` | 指定したNSEスクリプトまたはスクリプトカテゴリを実行します。           |

### 検出と回避

| オプション                                | 説明                                             |
| ------------------------------------ | ---------------------------------------------- |
| `-O`                                 | OS検出を実行します。                                    |
| `-A`                                 | OS検出、バージョン検出、NSEのデフォルトスクリプト、tracerouteを有効にします。 |
| `--packet-trace`                     | 送受信されたパケットを表示します。                              |
| `--reason`                           | Nmapがポートまたはホストの状態を報告した理由を表示します。                |
| `-D RND:5`                           | ファイアウォール/IDS回避のために5つのランダムなデコイを使用します。           |
| `-e <interface>`                     | スキャンに使用するネットワークインターフェースを指定します。                 |
| `-S 10.10.10.200`                    | スキャンの送信元IPアドレスを指定します。                          |
| `-g <port>` / `--source-port <port>` | スキャンの送信元ポートを指定します。                             |

### 出力オプション

| オプション          | 説明                                                |
| -------------- | ------------------------------------------------- |
| `-oA filename` | を使用して、利用可能なすべての出力形式で結果を保存します `filename` をベース名として。 |
| `-oN filename` | 通常形式で結果を保存します。                                    |
| `-oG filename` | grepable形式で結果を保存します。                              |
| `-oX filename` | XML形式で結果を保存します。                                   |

### パフォーマンスオプション

| オプション                        | 説明                                           |
| ---------------------------- | -------------------------------------------- |
| `--max-retries <num>`        | ポートスキャンプローブの再試行回数を設定します。                     |
| `--stats-every=5s`           | 5秒ごとにスキャン状態を表示します。                           |
| `-v` / `-vv`                 | スキャン中に詳細な出力を表示します。                           |
| `--initial-rtt-timeout 50ms` | 初期RTTタイムアウトを設定します。                           |
| `--max-rtt-timeout 100ms`    | 最大RTTタイムアウトを設定します。                           |
| `--min-rate 300`             | 指定されたレートより遅くならないようにパケットを送信します。               |
| `-T <0-5>`                   | timingテンプレートを設定します。 `0` パラノイドから `5` インセインまで。 |

## **ポートスキャン**

```bash
nmap --open -p- -sS --min-rate 5000 -vvv -n -Pn 192.168.0.1 -oG allPorts
```

DNS解決とホスト検出を省略し、詳細な進行状況を表示し、grepable出力を保存する高速な全ポートTCP SYNスキャン。

<figure><img src="https://hacking-notes.jord4n.pro/~gitbook/image?url=https%3A%2F%2F3467118603-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FwJ00xYl3QY03Wq54i4By%252Fuploads%252Fe6BGuXp1hLil6uT3Jtic%252Fimage.png%3Falt%3Dmedia%26token%3D96d46423-ca25-4471-a563-42daeae3be1e&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=bcba8a61&#x26;sv=1" alt=""><figcaption></figcaption></figure>

## **ポートバージョンスキャン**

```bash
nmap -p22,80,443 -sCV 192.168.0.1 -oN targeted
```

選択したポートに対する対象サービスとデフォルトスクリプトのスキャンで、通常形式の出力として保存されます。

<figure><img src="https://hacking-notes.jord4n.pro/~gitbook/image?url=https%3A%2F%2F3467118603-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FwJ00xYl3QY03Wq54i4By%252Fuploads%252F2MsfGLpxVpuiWEE7sRjJ%252Fimage.png%3Falt%3Dmedia%26token%3D767e772a-f3ea-4fee-b266-0c73398b7a4f&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=b468a586&#x26;sv=1" alt=""><figcaption></figcaption></figure>

## **ネットワークに接続されたデバイスの識別**

```bash
nmap -sn 192.168.0.1/24
```

ポートをスキャンせずに、ネットワーク範囲内の稼働中システムを特定するためのホスト検出スキャン。

<figure><img src="https://hacking-notes.jord4n.pro/~gitbook/image?url=https%3A%2F%2F3467118603-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FwJ00xYl3QY03Wq54i4By%252Fuploads%252FEFDeAo8BSjtTrsirRHC8%252Fimage.png%3Falt%3Dmedia%26token%3D679e4610-aa84-4b59-80e0-1a08f0c9140b&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=753ed2d0&#x26;sv=1" alt=""><figcaption></figcaption></figure>

## Nmapでファイアウォールを回避する

{% hint style="info" %}
Nmapツールを使用してファイアウォールを回避する方法はいくつかあります。以下は、この目的で最もよく使われる、効果的な手法です。
{% endhint %}

### 送信パケットのサイズを調整する

> MTU（Maximum Transmission Unit）回避手法は、ファイアウォールによる検出を避けるために送信パケットのサイズを調整するものです。Nmapでは最大パケットサイズを手動で設定できるため、パケットがファイアウォールを検出されずに通過できるほど小さくなるようにできます。

```bash
nmap 192.168.0.1 --mtu 8
```

### パディングデータを追加する

> この手法は、送信するデータの長さを変更して、ファイアウォールに検出されないほど短くするものです。Nmapでは、検出を回避するために送信データの長さを手動で設定できます。

```bash
nmap -p22 192.168.0.1 --data-length 21
```

### 送信元ポート番号を手動で設定する

> この手法は、検出を避けるために送信パケットの送信元ポート番号を手動で設定するものです。Nmapでは、ユーザーがランダムな送信元ポートまたは特定のポートを指定してファイアウォールを回避できます。

```bash
nmap -p22 192.168.0.1 --source-port 53
```

### ネットワークに偽パケットを送信する

> この回避手法では、侵入検知システムを混乱させ、ファイアウォールによる検出を避けるために、なりすましパケットをネットワーク全体に送信できます。 `-D` このオプションを使うと、Nmapは実パケットと偽装パケットを混在させてユーザーの活動を隠します。

```bash
nmap -p22 192.168.0.1 -D 192.168.0.100,192.168.0.152
```

### 送信パケットの断片化

> この手法は、送信パケットを断片化して、ファイアウォールがその通信をスキャンとして識別できないようにするものです。Nmapの `-f` オプションを使うと、パケットを断片化して分割送信し、検出を回避できます。

```bash
nmap -p22 192.168.0.1 -f
```

### パケットのMACアドレスを変更する

> この回避手法は、ファイアウォールによる検出を避けるためにパケットのMACアドレスを変更するものです。Nmapでは、トラフィックを偽装するためにMACアドレスを手動で設定できます。

```bash
nmap -p22 192.168.0.1 --spoof-mac f4:69:42:f4:a7:d0
```

## Nmapスクリプトによる脆弱性スキャン

```bash
nmap --script "vuln and safe" -p445 10.10.10.10 -oN vulnScan
```

> このNmapスクリプトを使うと、特定のホストの脆弱性を分析できます。 **vuln** （脆弱性）および **safe** （安全なスキャン）カテゴリのスクリプトを実行することで、可能性のあるセキュリティ脆弱性を特定します。結果は **vulnScan** という名前のファイルに保存され、後で分析できます。

**Linux列挙（認証情報なし）**

```bash
enum4linux -a 10.10.10.10
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fce72ab9ffa72b4149e4e03a00e2fef1cef79467%2Fimage%20(600).png?alt=media" alt=""><figcaption></figcaption></figure>

**認証情報ありのLinux列挙**

```bash
enum4linux -a 10.10.10.10 -u admin -p password1
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-729956858769d747348cf1bc4f10825b000854d4%2Fimage%20(601).png?alt=media" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/ja/reconnaissance/nmap.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
