# PIE

<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>

## 基本信息

作为PIE（Position Independent Executable）编译的二进制文件意味着**程序每次执行时可以在不同的内存位置加载**，从而防止硬编码地址。

利用这些二进制文件的技巧在于利用**相对地址**，即使绝对位置发生变化，程序部分之间的偏移量仍然保持不变。要**绕过PIE，只需泄漏一个地址**，通常是从**栈**中使用格式字符串攻击等漏洞泄漏。一旦获得一个地址，您可以通过它们的**固定偏移量**计算其他地址。

在利用PIE二进制文件时的一个有用提示是，它们的**基地址通常以000结尾**，因为内存页面是随机化的单位，大小为0x1000字节。这种对齐可以是一个关键的**检查是否工作正常**的指标，指示是否已识别出正确的基地址。\
或者您可以将其用于您的利用，如果您泄漏了一个地址位于\*\*`0x649e1024`**，则您知道**基地址为`0x649e1000`**，然后您可以**计算函数和位置的偏移量\*\*。

## 绕过方式

为了绕过PIE，需要**泄漏加载的**二进制文件的一些地址，有一些选项可以实现这一点：

* **禁用ASLR**：如果ASLR被禁用，使用PIE编译的二进制文件始终会**在相同的地址加载**，因此**PIE将变得无效**，因为对象的地址始终会在相同的位置。
* **获得**泄漏（在简单的CTF挑战中很常见，[**查看此示例**](https://ir0nstone.gitbook.io/notes/types/stack/pie/pie-exploit)）
* 在栈中**暴力破解EBP和EIP值**，直到泄漏正确的值：

{% content-ref url="/pages/JL6xNtBNxPvcnpcZB7Gn" %}
[BF Addresses in the Stack](/binary-exploitation/common-binary-protections-and-bypasses/pie/bypassing-canary-and-pie.md)
{% endcontent-ref %}

* 使用**任意读取**漏洞，如[**格式字符串**](/binary-exploitation/format-strings.md)泄漏二进制文件的地址（例如从栈中，就像前一种技术中那样）以获取二进制文件的基地址，并从那里使用偏移量。[**在此处找到示例**](https://ir0nstone.gitbook.io/notes/types/stack/pie/pie-bypass)。

## 参考资料

* <https://ir0nstone.gitbook.io/notes/types/stack/pie>

<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/binary-exploitation/common-binary-protections-and-bypasses/pie.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.
