Goal Reached Thanks to every supporter — we hit 100%!

Goal: 1000 CNY · Raised: 1310 CNY

100%

CVE-2025-47917 PoC — Mbed TLS 资源管理错误漏洞

Source
Associated Vulnerability
Title:Mbed TLS 资源管理错误漏洞 (CVE-2025-47917)
Description:Mbed TLS before 3.6.4 allows a use-after-free in certain situations of applications that are developed in accordance with the documentation. The function mbedtls_x509_string_to_names() takes a head argument that is documented as an output argument. The documentation does not suggest that the function will free that pointer; however, the function does call mbedtls_asn1_free_named_data_list() on that argument, which performs a deep free(). As a result, application code that uses this function (relying only on documented behavior) is likely to still hold pointers to the memory blocks that were freed, resulting in a high risk of use-after-free or double-free. In particular, the two sample programs x509/cert_write and x509/cert_req are affected (use-after-free if the san string contains more than one DN).
Description
PoC exploit for CVE-2025-47917: Use-After-Free in mbedTLS leading to remote code execution.
Readme
## CVE-2025-47917 Exploit (Use-After-Free in mbedTLS)
# Author       : Byte Reaper
# Telegram     : [@ByteReaper0](https://t.me/ByteReaper0)
# CVE          : CVE-2025-47917
# Vulnerability :  Use-After-Free (UAF) in mbedTLS 3.6.4 name parsing

---

## Description

This repository contains an exploit targeting a Use-After-Free vulnerability in the mbedtls_x509_string_to_names() name parsing function of the mbedTLS library. A successful exploit grants arbitrary code execution with root privileges by hijacking freed heap metadata and redirecting control flow to injected shellcode.

---

## Prerequisites

1. **Operating System**: Linux (tested on Kali Linux)
2. **Root privileges**: Required for disabling ASLR and executing injected shellcode
3. **mbedTLS development libraries (mbedTLS < 3.6.4)**:

   ```
   sudo apt update
   sudo apt install -y libmbedtls-dev
   ```
4. **Build tools**: `gcc`, `make` (optional)

---

## Compilation

Adjust include/library paths according to your installation:

```
gcc /path/to/exploit.c \
    -I/usr/local/include \
    -L/usr/local/lib \
    -lmbedtls -lmbedx509 -lmbedcrypto \
    -Wl,-rpath,/usr/local/lib \
    -o exploit_UAF
```

---

## Usage

1. **Disable ASLR** (Address Space Layout Randomization):

   ```
   echo 0 | sudo tee /proc/sys/kernel/randomize_va_space
   ```
2. **Prepare a listener** for the reverse shell on attacker machine (port 4454):

   ```
   nc -lvnp 4454
   ```
3. **Run the exploit** with root privileges:

   ```
   sudo ./exploit_UAF
   ```

---

## Exploitation Workflow

1. **ASLR Check**: `checkAslr()` reads `/proc/sys/kernel/randomize_va_space` to ensure ASLR is disabled. Exits if enabled.
2. **First `mbedtls_x509_string_to_names()` call**: Initializes an empty named-data list.
3. **Heap Spray**: `paddingChunk()` allocates many fake named-data structs to fill free list entries with controlled content pointing to shellcode.
4. **Second `mbedtls_x509_string_to_names()` call**: Triggers the Use-After-Free condition, reuses freed chunk containing fake metadata.
5. **Shellcode Injection**: Shellcode is mapped RWX via `mmap()`, copied, and executed through corrupted `named_data->val.p` pointer.

---

## Reverse Shell Shellcode

* **Target IP**: `192.168.92.187`
* **Target Port**: `4454`

The shellcode performs a `socket` + `connect` + `dup2` sequence, then `execve("/bin/sh")`.

---

## Ethical and Legal Disclaimer

* This code is provided **for authorized security research and educational purposes only**.
* Unauthorized use against systems for which you do not have explicit permission is illegal and unethical.
* Always obtain written permission before testing on any network or host.

---

## License

MIT
File Snapshot

Log in to view the POC file snapshot cached by Shenlong Bot

Log in to view
Remarks
    1. It is advised to access via the original source first.
    2. Local POC snapshots are reserved for subscribers — if the original source is unavailable, the local mirror is part of the paid plan.
    3. Mirroring, verifying, and maintaining this POC archive takes ongoing effort, so local snapshots are a paid feature. Your subscription keeps the archive online — thank you for the support. View subscription plans →