--- title: "PHP 5.2 fopen safemode Bypass" 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-bypass-php-5.2-fopen-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-bypass-php-5.2-fopen-exploit.md" sha: "188de82beb54e70956b2952367a0af91d26758b8" isIndex: false modified: true license: "CC-BY-NC-4.0" --- # PHP 5.2 `fopen` `safe_mode` Bypass This historical local exploit targets a `safe_mode` restriction-bypass issue reported in PHP 5.2.0. In a shared-hosting scenario where an attacker could already execute PHP code, a crafted `srpath://` URI passed to `fopen` could write a file outside the intended location.[[1]](#references) This is not a general bypass for modern PHP because `safe_mode` and its related configuration options were removed in PHP 5.4.[[2]](#references) ```bash php -r 'fopen("srpath://../../../../../../../dir/pliczek", "a");' ``` ## References - [1] [Exploit Database - PHP 5.2 `fopen` `safe_mode` Restriction Bypass](https://gitlab.com/exploit-database/exploitdb/-/blob/main/exploits/php/local/29528.txt) - [2] [PHP 5.4.0 Release Announcement](https://www.php.net/releases/5_4_0.php)