> 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/www2exec-atexit.md).

# WWW2Exec - atexit()

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

## **\_\_atexit 结构**

{% hint style="danger" %}
现在很**奇怪去利用这个！**
{% endhint %}

**`atexit()`** 是一个函数，**其他函数被作为参数传递给它。** 这些**函数**将在执行\*\*`exit()`**或**main**的**返回**时执行。**\
**如果您可以**修改**其中任何一个**函数**的**地址\*\*，使其指向一个shellcode，例如，您将**控制**该**进程**，但目前这更加复杂。\
目前要执行的**函数的地址**被隐藏在几个结构后面，最终指向的地址不是函数的地址，而是使用**XOR加密**和**随机密钥**进行位移。因此，目前这种攻击向量在至少在x86和x64\_86上**不太有用**。\
**加密函数**是\*\*`PTR_MANGLE`**。其他架构，如m68k、mips32、mips64、aarch64、arm、hppa... 不实现加密函数，因为它**返回\*\*与输入相同的内容。因此，这些架构可以通过这种向量进行攻击。

您可以在<https://m101.github.io/binholic/2017/05/20/notes-on-abusing-exit-handlers.html>找到关于这个工作原理的深入解释。

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