Sploitus

Exploit for Off-by-one Error in Sudo Project Sudo

gitee Β· 2021-12-11

Exploit Code

MARKDOWN12 lines
## https://sploitus.com/exploit?id=52B02390-8B6F-5DCF-84A0-F650C8FC1561
This is a PoC (Proof of Concept) exploit for the CVE-2021-3156 vulnerability in the sudo package. The vulnerability is a heap-based buffer overflow that can be exploited to gain elevated privileges.

The exploit is written in C and uses a brute-force approach to identify the correct offset and position of the `hooks->u.getenv_fn()` function, which is used to perform the partial overwrite to redirect control flow to an `execv()` located at `sudoers.so`. The exploit crafts a payload with a bruteforce for the partial overwrite (2 bytes) to reach code execution.

The exploit has three main components:

1. `callback.c`: This is the callback code that is executed when the exploit is successful. It checks if the current user is root and if so, it executes the `/bin/sh` shell.
2. `exploit.c`: This is the main exploit code that performs the brute-force search for the correct offset and position of the `hooks->u.getenv_fn()` function.
3. `fuzz.py`: This is a Python script that performs the brute-force search for the correct offset and position of the `hooks->u.getenv_fn()` function.

The exploit is designed to work on specific versions of Ubuntu and sudo, and it requires a brutef