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 ์ง€์›ํ•˜๊ธฐ

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 ์ง€์›ํ•˜๊ธฐ