> For the complete documentation index, see [llms.txt](https://hacktricks.xsx.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacktricks.xsx.tw/binary-exploitation/write-what-where-2-exec/aw2exec-__malloc_hook.md).

# WWW2Exec - \_\_malloc\_hook

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

## **Malloc Hook**

正如您可以在[GNU官方网站](https://www.gnu.org/software/libc/manual/html_node/Hooks-for-Malloc.html)中看到的，变量\*\*`__malloc_hook`**是一个指针，指向**将在调用`malloc()`时调用的函数的地址\*\*，存储在libc库的数据段中。因此，如果将此地址覆盖为例如**One Gadget**，并调用`malloc`，则将调用**One Gadget**。

要调用malloc，可以等待程序调用它，也可以通过**调用`printf("%10000$c")`**，这会分配太多字节，使得`libc`调用malloc在堆中分配它们。

有关One Gadget的更多信息，请参见：

{% content-ref url="/pages/hMN26nDJfPq1mKoWI7qN" %}
[One Gadget](/binary-exploitation/rop-return-oriented-programing/ret2lib/one-gadget.md)
{% endcontent-ref %}

{% hint style="warning" %}
请注意，对于GLIBC >= 2.34，挂钩是**禁用**的。现代GLIBC版本可以使用其他技术。请参阅：<https://github.com/nobodyisnobody/docs/blob/main/code.execution.on.last.libc/README.md>。
{% endhint %}

## References

* <https://ir0nstone.gitbook.io/notes/types/stack/one-gadgets-and-malloc-hook>
* <https://github.com/nobodyisnobody/docs/blob/main/code.execution.on.last.libc/README.md>.

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