> 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/hacking-wifi/wpa-wpa2-psk-network-attacks/precomputed-attacks/pyrit-installation-compilation-and-handshake-validation.md).

# Pyrit 安装、编译与握手验证

安全构建旧版 Pyrit，并使用它验证 WPA/WPA2 握手捕获。

Pyrit 可以帮助验证 WPA/WPA2 握手抓包并减少误报。请仅在已获批准的抓包和已记录范围内使用。

{% embed url="<https://github.com/JPaulMora/Pyrit>" %}

{% hint style="warning" %}
Pyrit 已被废弃。它依赖于 Python 2.7 和已到生命周期终点的 OpenSSL 1.1.1。不要将其安装在生产系统上。
{% endhint %}

### 构建概览

此构建需要单独安装 OpenSSL、Python 2.7 以及兼容性补丁。请使用一次性虚拟机或容器。

1. 安装构建依赖项。
2. 编译 OpenSSL 1.1.1w 和 Python 2.7.18。
3. 修补并编译 Pyrit。
4. 配置运行时库路径并验证结果。

### 前提条件

安装以下构建依赖项：

`build-essential git libssl-dev libpcap-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev libncurses5-dev libgdbm-dev libffi-dev libnss3-dev wget`

`python2-dev` 已不再提供。请改为从源代码构建 Python 2.7.18。

### 构建旧版依赖项

#### OpenSSL 1.1.1w

系统自带的 OpenSSL 3.x 与此 Python 2 工作流不兼容。请单独构建 OpenSSL 1.1.1w：

```bash
./config --prefix=/opt/openssl-1.1.1w --openssldir=/opt/openssl-1.1.1w shared zlib
make && sudo make install_sw
```

#### Python 2.7.18

使用上面的 OpenSSL 安装来构建 Python：

```bash
CPPFLAGS="-I/opt/openssl-1.1.1w/include" LDFLAGS="-L/opt/openssl-1.1.1w/lib -Wl,-rpath=/opt/openssl-1.1.1w/lib" ./configure --enable-optimizations
make && sudo make altinstall
```

这将安装 `python2.7` ，且不会更改系统 Python 版本。

### 准备并编译 Pyrit

#### 安装 pip2

运行 `get-pip.py` 替换为 `python2.7`.

#### 修补 `setup.py`

Pyrit 使用旧式 Python 类。请将 `super().build_extension(ext)` 替换为 `build_ext.build_extension(self, ext)`.

添加 `include_dirs` 和 `library_dirs` 中指向 OpenSSL 安装位置的条目。

#### 使用兼容 GCC 14 的标志进行编译

旧版 C 代码会在现代 GCC 版本上触发严格的编译错误：

```bash
CFLAGS="-Wno-error=implicit-int -Wno-error=implicit-function-declaration -Wno-error=int-conversion -Wno-error=incompatible-pointer-types" python2.7 setup.py build/install
```

#### 修补混合的 Python 语法

某些文件包含不兼容的 Python 3 语法。请应用以下兼容性更改：

* 将 f-string 替换为 `%` 格式化。
* 替换 `print(..., file=sys.stderr)` 替换为 `print >> sys.stderr`.
* 移除 `from e` from `raise` 语句。
* 替换 `import queue` 替换为 `import Queue as queue`.
* 替换 `xmlrpc.client` 和 `xmlrpc.server` 替换为 `xmlrpclib` 和 `SimpleXMLRPCServer`.

### 配置运行时库路径

设置 `LD_LIBRARY_PATH=/opt/openssl-1.1.1w/lib` 位于 `.zshrc`。然后 Pyrit 就能在运行时找到所需的 OpenSSL 库。

### 验证安装

确认 Pyrit 能检测到可用的处理核心。然后运行其基准测试：

```bash
pyrit list_cores
pyrit benchmark
```

### 推荐替代方案

对于新的评估，优先使用仍在维护的工具：

* `hashcat`
* `aircrack-ng`

它们避免了 Python 2 和旧版 OpenSSL 的依赖链。

### 捕获并验证握手

请在您拥有或获授权评估的无线网络上使用此工作流。

#### 捕获目标流量

在已知信道上捕获目标网络的流量：

{% code overflow="wrap" %}

```bash
airodump-ng --channel 1 -w CAPTURE --essid WIFI wlan0mon
```

{% endcode %}

#### 生成验证流量

在明确获得范围批准的情况下，向指定客户端发送去认证帧。这可能会促使其重新连接并生成新的握手：

{% code overflow="wrap" %}

```bash
aireplay-ng --deauth 0 -e WIFI -c FF:FF:FF:FF:FF:FF wlan0mon
```

{% endcode %}

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FY0DLasTq31XPJXAolpiV%2F%7B3632C541-1951-464D-8587-E548F8772AC4%7D.png?alt=media&amp;token=9cd47df5-667a-4607-80a4-345c7b748081" alt=""><figcaption></figcaption></figure>

#### 验证捕获到的握手

使用 Pyrit 分析抓包。它会报告从所观察到的站点获得的握手：

{% code overflow="wrap" %}

```bash
pyrit -r CAPTURE-01.cap analyze
```

{% endcode %}

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F1BDYkAbZzJcwBmMIZ9O1%2F%7BD80376D6-C44D-4F8C-BCD0-9C8BF854C729%7D.png?alt=media&amp;token=533d329d-00cf-4bbd-baa6-942c5ca21be1" 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/zh/hacking-wifi/wpa-wpa2-psk-network-attacks/precomputed-attacks/pyrit-installation-compilation-and-handshake-validation.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.
