hacktricks/binary-exploitation/libc-heap/overwriting-a-freed-chunk.md

50 lines
3.6 KiB
Markdown
Raw Normal View History

2024-06-13 00:45:08 +00:00
# Overwriting a freed chunk
2024-07-18 16:04:36 +00:00
{% hint style="success" %}
Learn & practice AWS Hacking:<img src="/.gitbook/assets/image.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/image.png" alt="" data-size="line">\
Learn & practice GCP Hacking: <img src="/.gitbook/assets/image (2).png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/image (2).png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
2024-06-13 00:45:08 +00:00
2024-07-18 16:04:36 +00:00
<details>
2024-06-13 00:45:08 +00:00
2024-07-18 16:04:36 +00:00
<summary>Support HackTricks</summary>
2024-06-13 00:45:08 +00:00
2024-07-18 16:04:36 +00:00
* Check the [**subscription plans**](https://github.com/sponsors/carlospolop)!
2024-06-13 00:45:08 +00:00
* **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
2024-07-18 16:04:36 +00:00
* **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2024-06-13 00:45:08 +00:00
</details>
2024-07-18 16:04:36 +00:00
{% endhint %}
2024-06-13 00:45:08 +00:00
Several of the proposed heap exploitation techniques need to be able to overwrite pointers inside freed chunks. The goal of this page is to summarise the potential vulnerabilities that could grant this access:
### Simple Use After Free
2024-07-11 13:10:36 +00:00
If it's possible for the attacker to **write info in a free chunk**, they could abuse this to overwrite the needed pointers.
2024-06-13 00:45:08 +00:00
### Double Free
If the attacker can **`free` two times the same chunk** (free other chunks in between potentially) and make it be **2 times in the same bin**, it would be possible for the user to **allocate the chunk later**, **write the needed pointers** and then **allocate it again** triggering the actions of the chunk being allocated (e.g. fast bin attack, tcache attack...)
### Heap Overflow
It might be possible to **overflow an allocated chunk having next a freed chunk** and modify some headers/pointers of it.
2024-07-11 13:10:36 +00:00
### Off-by-one overflow
2024-06-13 00:45:08 +00:00
2024-07-11 13:10:36 +00:00
In this case it would be possible to **modify the size** of the following chunk in memory. An attacker could abuse this to **make an allocated chunk have a bigger size**, then **`free`** it, making the chunk been **added to a bin of a different** size (bigger), then allocate the **fake size**, and the attack will have access to a **chunk with a size which is bigger** than it really is, **granting therefore an overlapping chunks situation**, which is exploitable the same way to a **heap overflow** (check previous section).
2024-06-13 00:45:08 +00:00
2024-07-18 16:04:36 +00:00
{% hint style="success" %}
Learn & practice AWS Hacking:<img src="/.gitbook/assets/image.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/image.png" alt="" data-size="line">\
Learn & practice GCP Hacking: <img src="/.gitbook/assets/image (2).png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/image (2).png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
2024-06-13 00:45:08 +00:00
2024-07-18 16:04:36 +00:00
<details>
2024-06-13 00:45:08 +00:00
2024-07-18 16:04:36 +00:00
<summary>Support HackTricks</summary>
2024-06-13 00:45:08 +00:00
2024-07-18 16:04:36 +00:00
* Check the [**subscription plans**](https://github.com/sponsors/carlospolop)!
2024-06-13 00:45:08 +00:00
* **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
2024-07-18 16:04:36 +00:00
* **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2024-06-13 00:45:08 +00:00
</details>
2024-07-18 16:04:36 +00:00
{% endhint %}