# Pentesting IPv6

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS红队专家）</strong></a><strong>！</strong></summary>

支持HackTricks的其他方式：

* 如果您想看到您的**公司在HackTricks中做广告**或**下载PDF格式的HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 探索[**PEASS家族**](https://opensea.io/collection/the-peass-family)，我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)
* **加入** 💬 [**Discord群组**](https://discord.gg/hRep4RUj7f) 或 [**电报群组**](https://t.me/peass) 或 **关注**我们的**Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks_live)**。**
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>

## IPv6基础理论

### 网络

IPv6地址被结构化以增强网络组织和设备交互。IPv6地址分为：

1. **网络前缀**：前48位，确定网络段。
2. **子网ID**：接下来的16位，用于定义网络中的特定子网。
3. **接口标识符**：最后的64位，唯一标识子网内的设备。

虽然IPv6省略了IPv4中的ARP协议，但引入了带有两个主要消息的**ICMPv6**：

* **邻居请求（NS）**：用于地址解析的多播消息。
* **邻居通告（NA）**：对NS的单播响应或自发公告。

IPv6还包括特殊的地址类型：

* **环回地址（`::1`）**：相当于IPv4的`127.0.0.1`，用于主机内部通信。
* **链路本地地址（`FE80::/10`）**：用于本地网络活动，不用于互联网路由。在同一本地网络上的设备可以使用此范围相互发现。

#### 在网络命令中实际使用IPv6

要与IPv6网络交互，您可以使用各种命令：

* **Ping链路本地地址**：使用`ping6`检查本地设备的存在。
* **邻居发现**：使用`ip neigh`查看在链路层发现的设备。
* **alive6**：用于在同一网络上发现设备的替代工具。

以下是一些命令示例：

```bash
ping6 –I eth0 -c 5 ff02::1 > /dev/null 2>&1
ip neigh | grep ^fe80

# Alternatively, use alive6 for neighbor discovery
alive6 eth0
```

### **从MAC地址推导Link-local IPv6地址**

给定一个MAC地址 **`12:34:56:78:9a:bc`**，您可以按照以下步骤构建Link-local IPv6地址：

1. 将MAC转换为IPv6格式：**`1234:5678:9abc`**
2. 在开头加上 `fe80::` 并在中间插入 `fffe`：**`fe80::1234:56ff:fe78:9abc`**
3. 反转从左起第七位，将 `1234` 改为 `1034`：**`fe80::1034:56ff:fe78:9abc`**

### **IPv6地址类型**

* **唯一本地地址 (ULA)**：用于本地通信，不用于公共互联网路由。前缀：**`FEC00::/7`**
* **组播地址**：用于一对多通信。传送到组播组中的所有接口。前缀：**`FF00::/8`**
* **任播地址**：用于一对最近通信。根据路由协议发送到最近的接口。属于全局单播范围 **`2000::/3`** 的一部分。

### **地址前缀**

* **fe80::/10**：链路本地地址 (类似于169.254.x.x)
* **fc00::/7**：唯一本地单播 (类似于私有IPv4范围如10.x.x.x, 172.16.x.x, 192.168.x.x)
* **2000::/3**：全局单播
* **ff02::1**：组播所有节点
* **ff02::2**：组播路由器节点

### **在网络中发现IPv6地址**

#### 方法1：使用链路本地地址

1. 获取网络中设备的MAC地址。
2. 从MAC地址推导出链路本地IPv6地址。

#### 方法2：使用组播

1. 向组播地址 `ff02::1` 发送ping以发现本地网络上的IPv6地址。

```bash
service ufw stop # Stop the firewall
ping6 -I <IFACE> ff02::1 # Send a ping to multicast address
ip -6 neigh # Display the neighbor table
```

### IPv6中间人攻击（MitM）攻击

在IPv6网络中执行MitM攻击有几种技术，例如：

* 伪造ICMPv6邻居或路由器通告。
* 使用ICMPv6重定向或“数据包太大”消息来操纵路由。
* 攻击移动IPv6（通常需要禁用IPSec）。
* 设置一个恶意的DHCPv6服务器。

## 在野外识别IPv6地址

### 探索子域

一种查找潜在链接到IPv6地址的子域的方法涉及利用搜索引擎。例如，使用类似`ipv6.*`的查询模式可能是有效的。具体来说，可以在Google中使用以下搜索命令：

```bash
site:ipv6./
```

### 利用 DNS 查询

要识别 IPv6 地址，可以查询特定的 DNS 记录类型：

* **AXFR**：请求完整的区域传输，可能会揭示各种 DNS 记录。
* **AAAA**：直接寻找 IPv6 地址。
* **ANY**：一个广泛的查询，返回所有可用的 DNS 记录。

### 使用 Ping6 进行探测

在确定与组织相关联的 IPv6 地址后，可以使用 `ping6` 实用程序进行探测。该工具有助于评估已识别的 IPv6 地址的响应性，并可能还有助于发现相邻的 IPv6 设备。

### 参考资料

* <http://www.firewall.cx/networking-topics/protocols/877-ipv6-subnetting-how-to-subnet-ipv6.html>
* <https://www.sans.org/reading-room/whitepapers/detection/complete-guide-ipv6-attack-defense-33904>

<details>

<summary><strong>从零开始学习 AWS 黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS 红队专家）</strong></a><strong>！</strong></summary>

支持 HackTricks 的其他方式：

* 如果您想看到您的 **公司在 HackTricks 中做广告** 或 **下载 PDF 版本的 HackTricks**，请查看 [**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取 [**官方 PEASS & HackTricks 商品**](https://peass.creator-spring.com)
* 探索 [**PEASS 家族**](https://opensea.io/collection/the-peass-family)，我们的独家 [**NFTs**](https://opensea.io/collection/the-peass-family)
* **加入** 💬 [**Discord 群组**](https://discord.gg/hRep4RUj7f) 或 [**电报群组**](https://t.me/peass) 或 **关注** 我们的 **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks_live)**。**
* 通过向 [**HackTricks**](https://github.com/carlospolop/hacktricks) 和 [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github 仓库提交 PR 来分享您的黑客技巧。

</details>


---

# Agent Instructions: 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:

```
GET https://hacktricks.xsx.tw/generic-methodologies-and-resources/pentesting-network/pentesting-ipv6.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
