> 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/zh/reconnaissance/nmap.md).

# Nmap

Nmap 在侦察阶段用于识别存活主机、开放端口、服务版本、操作系统、NSE 脚本结果以及潜在攻击路径。

{% hint style="info" %}
**Nmap**，即“*网络映射器*”，是一款用于探测和审计网络，以及发现网络中的主机和服务的开源工具。它最初由 Gordon Lyon 创建，他也被称为 Fyodor Vaskovich。Nmap 提供网络扫描能力，使用户能够发现连接到网络的设备、识别这些设备上运行的服务，并获取有关网络配置的详细信息。
{% endhint %}

#### 常用命令和选项参考：

## Nmap 选项参考

### 目标与主机发现

| 选项                   | 描述                     |
| -------------------- | ---------------------- |
| `10.10.10.0/24`      | 目标网络范围。                |
| `-sL`                | 列表扫描。列出目标而不对其进行扫描。     |
| `-sn`                | 禁用端口扫描，仅执行主机发现。        |
| `-Pn`                | 将主机视为在线并跳过主机发现探测。      |
| `-n`                 | 禁用 DNS 解析。             |
| `-PE`                | 使用 ICMP Echo 请求执行主机发现。 |
| `--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`               | 运行分类为 `default`.                |
| `的 NSE 脚本`          | 运行指定的 NSE 脚本或脚本类别。              |

### 检测与规避

| 选项                                   | 描述                           |
| ------------------------------------ | ---------------------------- |
| `-O`                                 | 执行操作系统检测。                    |
| `-A`                                 | 启用操作系统检测、版本检测、NSE 默认脚本和路由跟踪。 |
| `--packet-trace`                     | 显示发送和接收的数据包。                 |
| `--reason`                           | 显示 Nmap 报告端口或主机状态的原因。        |
| `-D RND:5`                           | 使用 5 个随机诱饵进行防火墙/IDS 规避。      |
| `-e <interface>`                     | 指定用于扫描的网络接口。                 |
| `-S 10.10.10.200`                    | 指定扫描的源 IP 地址。                |
| `-g <port>` / `--source-port <port>` | 指定扫描的源端口。                    |

### 输出选项

| 选项             | 描述                                  |
| -------------- | ----------------------------------- |
| `-oA filename` | 使用 `filename` 作为基名，将结果保存为所有可用的输出格式。 |
| `-oN filename` | 将结果保存为普通格式。                         |
| `-oG filename` | 将结果保存为可 grep 的格式。                   |
| `-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>`                   | 设置时间模板，从 `0` 偏执到 `5` 疯狂。 |

## **端口扫描**

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

快速的全端口 TCP SYN 扫描，跳过 DNS 和主机发现，显示详细进度，并将结果保存为 grepable 输出。

<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 或“最大传输单元”规避技术是通过调整发送的数据包大小来避免被防火墙检测。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="/files/bff23e78765fa20e9ae89227f8837c572b51df36" alt=""><figcaption></figcaption></figure>

**使用凭据进行 Linux 枚举**

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

<figure><img src="/files/78240ee6ed9f749b5d5eec18c22366bcb31fb8f6" 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
