# Ret2ret & Reo2pop

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

## Ret2ret

这种技术的主要**目标**是尝试通过滥用栈中现有指针来**绕过ASLR**。

基本上，栈溢出通常是由字符串引起的，而**字符串在内存中以空字节结尾**。这使得可以尝试减少栈中现有指针指向的位置。因此，如果栈包含`0xbfffffdd`，这种溢出可以将其转换为`0xbfffff00`（请注意最后一个为零的字节）。

如果该地址指向我们在栈中的shellcode，就可以通过**向`ret`指令添加地址**，直到达到该地址。

因此，攻击将如下进行：

* NOP滑梯
* Shellcode
* 用**指向`ret`的地址**（RET滑梯）覆盖EIP的栈
* 由字符串添加的0x00修改栈中的地址，使其指向NOP滑梯

通过[**此链接**](https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/ASLR%20Smack%20and%20Laugh%20reference%20-%20Tilo%20Mueller/ret2ret.c)您可以看到一个易受攻击的二进制文件的示例，以及[**在这里**](https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/ASLR%20Smack%20and%20Laugh%20reference%20-%20Tilo%20Mueller/ret2retexploit.c)攻击。

## Ret2pop

如果您可以在栈中找到一个**完美的指针，您不想修改**（在`ret2ret`中，我们将最终的最低字节更改为`0x00`），则可以执行相同的`ret2ret`攻击，但是**RET滑梯的长度必须减少1**（因此最终的`0x00`将覆盖完美指针之前的数据），并且**RET滑梯的最后一个**地址必须指向\*\*`pop <reg>; ret`**。**\
**这样，完美指针之前的数据将从栈中删除（这是受`0x00`影响的数据），并且**最终的`ret`将指向栈中的完美地址\*\*，而不会有任何更改。

通过[**此链接**](https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/ASLR%20Smack%20and%20Laugh%20reference%20-%20Tilo%20Mueller/ret2pop.c)您可以看到一个易受攻击的二进制文件的示例，以及[**在这里**](https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/ASLR%20Smack%20and%20Laugh%20reference%20-%20Tilo%20Mueller/ret2popexploit.c)攻击。

## 参考资料

* <https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/NOTES.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>
