---
title: "PHP 5.x Shellshock Command Execution"
section: "Network Services"
sectionSlug: "network-services-pentesting"
sourcePath: "src/network-services-pentesting/pentesting-web/php-tricks-esp/php-useful-functions-disable_functions-open_basedir-bypass/disable_functions-php-5.x-shellshock-exploit.md"
sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/network-services-pentesting/pentesting-web/php-tricks-esp/php-useful-functions-disable_functions-open_basedir-bypass/disable_functions-php-5.x-shellshock-exploit.md"
sha: "188de82beb54e70956b2952367a0af91d26758b8"
isIndex: false
modified: true
license: "CC-BY-NC-4.0"
---
# PHP 5.x Shellshock Command Execution
This historical technique relies on CVE-2014-6271 (Shellshock): vulnerable Bash versions execute commands appended to an exported function definition. The PHP proof of concept sets such an environment variable and invokes `mail()`, which may cause the local mail transport to start a vulnerable Bash process.[[1]](#references)[[2]](#references)
It works only when all of the required conditions are present, including a vulnerable Bash, `/bin/sh` resolving to Bash, a usable `mail()` path, and the relevant PHP functions not being disabled. It should therefore be treated as a legacy, environment-specific check.[[1]](#references)[[2]](#references)
On historical `safe_mode` configurations, PHP commonly allowed users to change only environment variables whose names began with the configured `safe_mode_allowed_env_vars` prefixes; the default prefix was `PHP_`. The proof of concept therefore uses the name `PHP_LOL` for the exported function payload.[[2]](#references)
```php
$tmp 2>&1");
mail('a@127.0.0.1', '', '', '', '-bv');
$output = @file_get_contents($tmp);
@unlink($tmp);
return $output !== '' ? $output : 'No output, or the target is not vulnerable.';
}
echo shellshock($_REQUEST['cmd']);
?>
```
## References
- [1] [NIST NVD - CVE-2014-6271](https://nvd.nist.gov/vuln/detail/CVE-2014-6271)
- [2] [SafeBuff - `disable_functions` bypass examples (archived)](https://web.archive.org/web/20170801153107/http://blog.safebuff.com:80/2016/05/06/disable-functions-bypass/)