> 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/common-binary-protections-and-bypasses/relro.md).

# Relro

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS Red Team Expert）</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>

## Relro

**RELRO**代表**Relocation Read-Only**，是二进制文件中使用的安全功能，用于减轻与**GOT（Global Offset Table）覆写相关的风险。让我们将这个概念分解为两种不同类型以便更清晰地理解：Partial RELRO和Full RELRO**。

### **Partial RELRO**

**Partial RELRO**采用了一种更简单的方法来增强安全性，而不会显著影响二进制文件的性能。通过**将GOT放置在程序变量的内存之上，Partial RELRO旨在防止缓冲区溢出达到并破坏GOT**。

这**不能防止GOT**被滥用**来自任意写入**漏洞。

### **Full RELRO**

**Full RELRO**通过**使GOT和.fini\_array**部分完全**只读**来加强保护。一旦二进制文件启动，所有函数地址都会被解析并加载到GOT中，然后，GOT被标记为只读，有效地防止在运行时对其进行任何修改。

然而，Full RELRO的折衷之处在于性能和启动时间。因为它需要在标记GOT为只读之前在启动时解析所有动态符号，**启用Full RELRO的二进制文件可能会经历更长的加载时间**。这种额外的启动开销是为什么并非所有二进制文件默认启用Full RELRO的原因。

可以通过以下方式查看二进制文件中是否启用了Full RELRO：

```bash
readelf -l /proc/ID_PROC/exe | grep BIND_NOW
```

## 绕过

如果启用了Full RELRO，唯一的绕过方法是找到另一种不需要写入GOT表就能获得任意执行的方式。

请注意**LIBC的GOT通常是Partial RELRO**，因此可以使用任意写入来修改它。更多信息请参阅[Targetting libc GOT entries](https://github.com/nobodyisnobody/docs/blob/main/code.execution.on.last.libc/README.md#1---targetting-libc-got-entries)**。**
