# Array Indexing

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

## 基本信息

此类别包括所有由于在处理数组索引时出现错误而可能覆盖某些数据而导致的漏洞。这是一个非常广泛的类别，没有特定的方法论，因为利用机制完全取决于漏洞的条件。

然而，您可以找到一些不错的**示例**：

* <https://guyinatuxedo.github.io/11-index/swampctf19_dreamheaps/index.html>
* 存在**2个冲突的数组**，一个用于存储数据的**地址**，另一个用于存储该数据的**大小**。可以从一个数组中覆盖另一个数组，从而可以写入任意地址并将其指定为大小。这允许将`free`函数的地址写入GOT表，然后用`system`的地址覆盖它，并从具有`/bin/sh`的内存中调用free。
* <https://guyinatuxedo.github.io/11-index/csaw18_doubletrouble/index.html>
* 64位，无nx。覆盖一个大小以获得一种缓冲区溢出，其中每个东西都将被用作双精度数，并按从小到大排序，因此需要创建一个满足该要求的shellcode，考虑到不能移动canary的位置，并最终用地址覆盖RIP以返回，满足先前的要求，并将最大的地址放在一个新地址上，指向栈的起始位置（由程序泄漏），因此可以使用ret跳转到那里。
* <https://faraz.faith/2019-10-20-secconctf-2019-sum/>
* 64位，无relro，canary，nx，无pie。栈中数组存在一个off-by-one，允许控制指针以授予WWW（它将数组中所有数字的总和写入数组中的off-by-one覆盖的地址）。控制堆栈以覆盖GOT `exit`地址为`pop rdi; ret`，并在堆栈中添加`main`的地址（回到`main`）。使用ROP链泄漏GOT中put的地址（将调用`exit`，因此将调用`pop rdi; ret`，从而在堆栈中执行此链）。最后使用新的ROP链执行ret2lib。
* <https://guyinatuxedo.github.io/14-ret_2_system/tu_guestbook/index.html>
* 32位，无relro，无canary，nx，pie。利用错误的索引来从堆栈中泄漏libc和堆的地址。利用缓冲区溢出执行ret2lib调用`system('/bin/sh')`（需要堆地址来绕过检查）。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hacktricks.xsx.tw/binary-exploitation/array-indexing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
