Disable Functions Bypass - dl Function
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 सबमिट करें।
dl() PHP को runtime पर एक shared extension लोड करने देता है। अगर आप इसे attacker-controlled module लोड करवा सकते हैं, तो आप एक नया PHP function रजिस्टर कर सकते हैं जो आंतरिक रूप से execve, system, या किसी अन्य native primitive को कॉल करता है और इसलिए disable_functions को bypass कर देता है।
यह एक real primitive है, लेकिन आधुनिक targets पर यह पुराने writeups के सुझावों की तुलना में कहीं कम सामान्य है।
क्यों यह bypass आज कम आम है
मुख्य बाधाएँ हैं:
dl()मौजूद होना चाहिए और disabled नहीं होना चाहिएenable_dlको अभी भी डायनामिक लोडिंग की अनुमति देनी चाहिए- लक्षित SAPI को
dl()का समर्थन करना चाहिए - Payload एक मान्य PHP extension होना चाहिए जो same target ABI के लिए compiled हो
- Extension configured
extension_dirसे पहुंचने योग्य होना चाहिए
यहाँ सबसे महत्वपूर्ण वास्तविकता जांच official PHP manual है: dl() is only available for CLI and embed SAPIs, and for the CGI SAPI when run from the command line. इसका मतलब है कि technique usually not available in normal PHP-FPM/mod_php web requests, इसलिए payload बनाने में समय खर्च करने से पहले SAPI की जाँच करें।
ध्यान दें कि enable_dl एक INI_SYSTEM सेटिंग है और, PHP 8.3.0 के बाद से, PHP इसे deprecated के रूप में दस्तावेज करता है, इसलिए आप आम तौर पर attacker-controlled PHP code से runtime पर इसे बदल नहीं पाएँगे।
If dl() is not viable, go back to the broader list of module/version dependent bypasses.
Fast triage from a foothold
Before building anything, collect the exact parameters that the module must match:
<?php
phpinfo();
echo "PHP_VERSION=" . PHP_VERSION . PHP_EOL;
echo "PHP_SAPI=" . php_sapi_name() . PHP_EOL;
echo "ZTS=" . (PHP_ZTS ? "yes" : "no") . PHP_EOL;
echo "INT_BITS=" . (PHP_INT_SIZE * 8) . PHP_EOL;
echo "enable_dl=" . ini_get("enable_dl") . PHP_EOL;
echo "extension_dir=" . ini_get("extension_dir") . PHP_EOL;
echo "disabled=" . ini_get("disable_functions") . PHP_EOL;
?>
What you care about:
PHP_SAPI: अगर यहfpm-fcgiयाapache2handlerहै, तोdl()आम तौर पर web exploitation के लिए dead end होती हैextension_dir: payload को यहीं से लोड किया जाना चाहिएPHP Version, architecture, debug/non-debug, और ZTS/non-ZTS: आपका module इन्हें मैच करना चाहिएdisable_functions: यह पुष्टि करें किdlअनुपस्थित है क्योंकि यह disabled है या क्योंकि SAPI इसे support नहीं करता
Practical exploitation constraints
1. You normally need write access to extension_dir
यह सबसे बड़ा bottleneck है।
dl() extension filename लेता है, और PHP इसे extension_dir से लोड करता है। व्यवहार में, इसका मतलब है कि सामान्य arbitrary file upload /var/www/html/uploads में पर्याप्त नहीं है। आपको अभी भी ऐसा path चाहिए जहाँ आप .so/.dll रख सकें और PHP वास्तव में उसी path से extensions लोड करे।
वास्तविक परिस्थितियाँ जहाँ यह exploitable बन सकता है:
- CTFs या जानबूझकर कमजोर labs जहाँ
extension_dirwritable हो - Shared-hosting या container mistakes जो writable extension path को expose करते हों
- एक अलग arbitrary file write primitive जो पहले से ही
extension_dirतक पहुँचता हो - Post-exploitation scenarios जहाँ आप पहले से ही इतना escalate कर चुके हों कि वहाँ फाइलें drop कर सकें
2. The module must match the target build
सिर्फ PHP_VERSION मैच करना काफी नहीं है। extension को निम्नों से भी मैच करना होगा:
- OS और CPU architecture
- libc/toolchain expectations
ZEND_MODULE_API_NO- debug vs non-debug build
- ZTS vs NTS
यदि ये मैच नहीं करते हैं, तो dl() fail करेगा या process crash कर सकता है।
3. open_basedir is not the main defense here
एक बार जब आप module को extension_dir में रख सकते हैं और dl() कॉल कर सकते हैं, तो extension code PHP process के अंदर execute होता है। उस बिंदु पर संबंधित बाधा open_basedir नहीं थी, बल्कि valid shared object को extension loading path में land करने की क्षमता थी।
दुर्भावनापूर्ण extension बनाना
क्लासिक तरीका अब भी वैध है:
- पीड़ित के build को जितना संभव हो उतना करीब recreate करें
phpize,./configure, औरmakeका उपयोग करके एक shared extension बनाएं- एक PHP function export करें जैसे
bypass_exec($cmd)जो native command execution को wrap करे - compiled module को
extension_dirमें upload करें - इसे
dl()से load करें और exported function को कॉल करें
यह attack पुराना है, पर अभी भी relevant है क्योंकि PHP 8.x changelogs में लगातार dl()-specific crash fixes आते रहे हैं। यह primitive अभी भी मौजूद है; मुश्किल हिस्सा ऐसा deployment ढूँढना है जहाँ यह reachable हो और जहाँ आप एक matching module land कर सकें।
Minimal workflow
On the attacker box
mkdir bypass && cd bypass
phpize
./configure
make
परिणामी shared object सामान्यतः modules/ के तहत होगा।
यदि आप target से अलग environment पर build कर रहे हैं, तो produced file को draft के रूप में मानें जब तक आप यह सत्यापित न कर लें कि ABI victim से मेल खाता है।
Loading and using the extension
यदि target वास्तव में dl() को सपोर्ट करता है और module extension_dir के अंदर है, तो runtime पक्ष सरल है:
<?php
if (!extension_loaded('bypass')) {
dl('bypass.so'); // use the correct filename for the target platform
}
echo bypass_exec($_GET['cmd']);
?>
On Windows the filename will typically be a .dll, while on Unix-like targets it will usually be a .so.
हमलावर नोट्स
- यह मत मानिए कि यह रिमोटली काम करेगा सिर्फ इसलिए कि
function_exists("dl")कुछ दस्तावेज़ों या पुराने writeup में true लौटाता है; लाइव SAPI को सत्यापित करें - यदि मॉड्यूल असंगत है तो विफल
dl()प्रयास PHP worker को समाप्त कर सकता है - PHP 8 से, disabled functions को function table से हटा दिया गया है, इसलिए userland enumeration पुराने पोस्ट्स से भिन्न हो सकती है
- यदि आप
extension_dirमें लिख नहीं कर सकते हैं, तो यह तकनीक आम तौर पर FPM/FastCGI,LD_PRELOAD, या module-specific bypasses की तुलना में कम व्यावहारिक होती है, जैसा कि इस सेक्शन में पहले कवर किया जा चुका है
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 का समर्थन करें
- सदस्यता योजनाओं की जांच करें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमें Twitter 🐦 @hacktricks_live** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें और HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में PRs सबमिट करें।


