# One Gadget

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

## 基本信息

[**One Gadget**](https://github.com/david942j/one_gadget)允许在不使用**system**和\*\*"/bin/sh"**的情况下获得一个shell。One Gadget将在libc库中找到一种方法来使用只一个**地址**获得一个shell（`execve("/bin/sh")`）。**\
**然而，通常会有一些限制条件，最常见且易于避免的是像`[rsp+0x30] == NULL`这样的限制条件。由于您可以控制**RSP\*\*中的值，因此您只需发送更多的NULL值以避免这种限制条件。

![](/files/miGAmAp7DSN8ZgVXgnuE)

```python
ONE_GADGET = libc.address + 0x4526a
rop2 = base + p64(ONE_GADGET) + "\x00"*100
```

要找到 One Gadget 指示的地址，您需要**加上 `libc` 加载的基地址**。

{% hint style="success" %}
One Gadget 对于任意写入执行技术非常有帮助，可能会**简化 ROP 链**，因为您只需要调用一个地址（并满足要求）。
{% endhint %}

### ARM64

github 仓库提到该工具支持**ARM64**，但在 Kali 2023.3 的 libc 中运行时**找不到任何 gadget**。

## Angry Gadget

来自[**github 仓库**](https://github.com/ChrisTheCoolHut/angry_gadget)：受 [OneGadget](https://github.com/david942j/one_gadget) 启发，这个工具用 Python 编写，并使用 [angr](https://github.com/angr/angr) 来测试执行 `execve('/bin/sh', NULL, NULL)` 的 gadget 的约束条件。\
如果您已经尝试过 One Gadget 中的所有 gadget，Angry Gadget 提供了更多带有复杂约束条件的 gadget！

```bash
pip install angry_gadget

angry_gadget.py examples/libc6_2.23-0ubuntu10_amd64.so
```

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


---

# 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/rop-return-oriented-programing/ret2lib/one-gadget.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.
