File manager - Edit - /usr/local/cpanel/base/frontend/jupiter/cpguard/ajax.live.php
Back
<?php include_once __DIR__ . '/includes/init.php'; /** * Helper to validate that a requested path stays within the base directory. * * @param string $baseDir The allowed root directory. * @param string $requestedFile The user input (e.g., from $_GET). * @return string|false Returns the absolute path if safe, false otherwise. */ function get_safe_path($base_dir, $requested_file) { // 1. Construct the intended path $path = $base_dir . DIRECTORY_SEPARATOR . $requested_file; // 2. Resolve to absolute path (this removes ../ ./ and extra slashes) // realpath returns false if the file does not exist. $real_path = realpath($path); $real_base = realpath($base_dir); // 3. Security Check: // - Check if file exists ($real_path is not false) // - Check if the resolved path starts with the base directory // - Append DIRECTORY_SEPARATOR to base to prevent partial matches // (e.g., preventing /var/www/upload matching /var/www/uploads_secret) if ($real_path === false || strpos($real_path, $real_base . DIRECTORY_SEPARATOR) !== 0) { return false; } return $real_path; } if (isset($_GET['script']) || isset($_GET['ajax'])) { $safe_path = get_safe_path(__DIR__, $_GET['script'] ?? $_GET['ajax']); if ($safe_path === false) { // Handle error: file not found or outside allowed directory http_response_code(404); exit('File not found or access denied.'); } require_once $safe_path; } else if ($_GET['file']) { $file = get_safe_path($cpguard_user_dir, $_GET['file']); if ($file === false) { // Handle error: file not found or outside allowed directory http_response_code(404); exit('File not found or access denied.'); } header('Content-Type: ' . mime_content_type($file)); header('Content-Disposition: attachment;filename="' . basename($file) . '"'); header('Cache-Control: max-age=0'); echo file_get_contents($file); } exit;
| ver. 1.4 |
Github
|
.
| PHP 8.1.34 | Generation time: 0.04 |
proxy
|
phpinfo
|
Settings