Search K
Appearance
Appearance
Other ways to support HackTricks:
Important note:

dl is a PHP function that can be used to load PHP extensions. It the function isn't disabled it could be abused to bypass disable_functions and execute arbitrary commands.
However, it has some strict limitations:
dl function must be present in the environment and not disabledextension_dir directive (you can see it in the output of phpinfo). It's very unprobeable that an attacker trying to abuse the server will have write access over this directory, so this requirement probably will prevent you to abuse this technique).If you meet these requirements, continue reading the post https://antichat.com/threads/70763/ to learn how to bypass disable_functions. Here is a summary:
The dl function is used to load PHP extensions dynamically during script execution. PHP extensions, typically written in C/C++, enhance PHP's functionality. The attacker, upon noticing the dl function is not disabled, decides to create a custom PHP extension to execute system commands.
PHP Version Identification:
<?php echo 'PHP Version is '.PHP_VERSION; ?>).PHP Source Acquisition:
Local PHP Setup:
Extension Creation:
ext/standard/exec.c.ZEND_MODULE_API_NO:
ZEND_MODULE_API_NO in bypass.c must match the current Zend Extension Build, retrievable with:php -i | grep "Zend Extension Build" |awk -F"API4" '{print $2}' | awk -F"," '{print $1}'PHP_FUNCTION Modification:
PHP_FUNCTION(bypass_exec) may need adjustment. The provided code snippet details this modification.phpize to configure the build environment for the custom extension.Compilation Commands:
phpize, ./configure, and make to compile the extension.bypass.so is then located in the modules subdirectory.Cleanup:
make clean and phpize --clean after compilation.Version Compatibility:
Extension Loading:
dl function, circumventing restrictions by using relative paths or a script to automate the process.Script Execution:
bypass.so and a PHP script to the victim's server.dl_local function to dynamically load bypass.so and then calls bypass_exec with a command passed via the cmd query parameter.http://www.example.com/script.php?cmd=<command>This detailed walkthrough outlines the process of creating and deploying a PHP extension to execute system commands, exploiting the dl function, which should ideally be disabled to prevent such security breaches.
Other ways to support HackTricks: