PHP SSRF
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์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.
SSRF PHP ํจ์
**file_get_contents(), fopen(), file(), md5_file()**์ ๊ฐ์ ์ผ๋ถ ํจ์๋ ์ฌ์ฉ์๊ฐ ๋ฐ์ดํฐ๋ฅผ ์ ์ดํ ์ ์๋ ๊ฒฝ์ฐ SSRF ์ทจ์ฝ์ ์ ๋ฐ์์ํฌ ์ ์๋ URL์ ์ ๋ ฅ์ผ๋ก ๋ฐ์๋ค์ ๋๋ค:
file_get_contents("http://127.0.0.1:8081");
fopen("http://127.0.0.1:8081", "r");
file("http://127.0.0.1:8081");
md5_file("http://127.0.0.1:8081");
Wordpress SSRF via DNS Rebinding
As explained in this blog post, even the Wordpress function **wp_safe_remote_get**๋ DNS ๋ฆฌ๋ฐ์ธ๋ฉ์ ์ทจ์ฝํ์ฌ SSRF ๊ณต๊ฒฉ์ ์ทจ์ฝํ ์ ์์ต๋๋ค. ํธ์ถํ๋ ์ฃผ์ ๊ฒ์ฆ์ wp_http_validate_url๋ก, ํ๋กํ ์ฝ์ด http:// ๋๋ https://์ธ์ง, ํฌํธ๊ฐ 80, 443, 8080 ์ค ํ๋์ธ์ง ํ์ธํ์ง๋ง, DNS ๋ฆฌ๋ฐ์ธ๋ฉ์ ์ทจ์ฝํฉ๋๋ค.
๊ฒ์๋ฌผ์ ๋ฐ๋ฅด๋ฉด ๋ค๋ฅธ ์ทจ์ฝํ ํจ์๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค:
wp_safe_remote_request()wp_safe_remote_post()wp_safe_remote_head()WP_REST_URL_Details_Controller::get_remote_url()download_url()wp_remote_fopen()WP_oEmbed::discover()
CRLF
๊ฒ๋ค๊ฐ, ๊ฒฝ์ฐ์ ๋ฐ๋ผ ์ด์ ํจ์์ CRLF โ์ทจ์ฝ์ โ์ ํตํด ์์์ ํค๋๋ฅผ ์ ์กํ ์๋ ์์ต๋๋ค:
# The following will create a header called from with value Hi and
# an extra header "Injected: I HAVE IT"
ini_set("from", "Hi\r\nInjected: I HAVE IT");
file_get_contents("http://127.0.0.1:8081");
GET / HTTP/1.1
From: Hi
Injected: I HAVE IT
Host: 127.0.0.1:8081
Connection: close
# Any of the previously mentioned functions will send those headers
Warning
CRLF ์ทจ์ฝ์ ์ ๋ํ ์์ธํ ์ ๋ณด๋ ์ด ๋ฒ๊ทธ๋ฅผ ํ์ธํ์ธ์ https://bugs.php.net/bug.php?id=81680&edit=1
์ด ํจ์๋ ์์ฒญ์์ ์์์ ํค๋๋ฅผ ์ค์ ํ๋ ๋ค๋ฅธ ๋ฐฉ๋ฒ์ด ์์ ์ ์์ต๋๋ค, ์๋ฅผ ๋ค์ด:
$url = "";
$options = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"Cookie: foo=bar\r\n" . // check function.stream-context-create on php.net
"User-Agent: Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10\r\n" // i.e. An iPad
)
);
$context = stream_context_create($options);
$file = file_get_contents($url, false, $context);
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์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.


