array( 'title' => __('PHP version is no longer fully supported', 'all-in-one-wp-content-security'), 'kind' => 'vulnerability', 'explanation' => __('Each PHP branch receives bug fixes for two years and security fixes for two more. After that, newly found vulnerabilities in PHP itself are no longer fixed by the PHP project.', 'all-in-one-wp-content-security'), 'impact' => __('An end-of-life PHP version accumulates unfixed security issues and increasingly misses compatibility with current plugins. (Some Linux distributions backport fixes; ask your host if that applies.)', 'all-in-one-wp-content-security'), 'remediation' => __('Switch the site to a supported PHP version in your hosting control panel after testing it on a staging copy.', 'all-in-one-wp-content-security'), 'steps' => array( __('Check that your plugins and theme support the target PHP version (most list "Requires PHP" / "Tested up to").', 'all-in-one-wp-content-security'), __('Test on a staging copy of the site if your host provides one.', 'all-in-one-wp-content-security'), __('Change the PHP version in the hosting control panel (or ask your host).', 'all-in-one-wp-content-security'), __('Open the site and the admin area, then re-run this check.', 'all-in-one-wp-content-security'), ), 'docs' => array( self::doc(__('PHP supported versions', 'all-in-one-wp-content-security'), 'https://www.php.net/supported-versions.php'), self::doc(__('WordPress requirements', 'all-in-one-wp-content-security'), 'https://wordpress.org/about/requirements/'), ), 'permission' => __('Hosting control panel or server administrator', 'all-in-one-wp-content-security'), ), ); } public function run($context) { $info = AOWPCS_EOL::php(PHP_VERSION); $recommended = AOWPCS_EOL::php_recommended(); $evidence = array( __('PHP version', 'all-in-one-wp-content-security') => PHP_VERSION, __('Active support until', 'all-in-one-wp-content-security') => $info['active_until'] ?: '—', __('Security support until', 'all-in-one-wp-content-security') => $info['security_until'] ?: '—', __('Support data as of', 'all-in-one-wp-content-security') => AOWPCS_EOL::DATA_DATE, ); if ($info['status'] === 'eol') { /* translators: 1: info branch, 2: value */ return array($this->issue('php.version_eol', 'high', 'php', sprintf(__('PHP %1$s reached end of life on %2$s and no longer receives security fixes.', 'all-in-one-wp-content-security'), $info['branch'], $info['security_until'] ?: __('an earlier date', 'all-in-one-wp-content-security')), array( 'detected' => PHP_VERSION, /* translators: %s: recommended */ 'expected' => sprintf(__('PHP %s or newer', 'all-in-one-wp-content-security'), $recommended), 'evidence' => $evidence, ))); } if ($info['status'] === 'security') { /* translators: 1: info branch, 2: info security until */ return array($this->issue('php.version_eol', 'low', 'php', sprintf(__('PHP %1$s only receives security fixes, until %2$s. Plan an upgrade.', 'all-in-one-wp-content-security'), $info['branch'], $info['security_until']), array( 'kind' => 'hardening', 'detected' => PHP_VERSION, /* translators: %s: recommended */ 'expected' => sprintf(__('PHP %s or newer', 'all-in-one-wp-content-security'), $recommended), 'evidence' => $evidence, ))); } $summary = !empty($info['newer_than_table']) /* translators: %s: PHP VERSION */ ? sprintf(__('PHP %s is newer than the bundled support table and is assumed to be supported.', 'all-in-one-wp-content-security'), PHP_VERSION) /* translators: 1: PHP VERSION, 2: info active until */ : sprintf(__('PHP %1$s is actively supported until %2$s.', 'all-in-one-wp-content-security'), PHP_VERSION, $info['active_until']); return array($this->pass('php.version_eol', $summary, $evidence)); } } /** * Security-relevant php.ini values. WP-CLI uses its own php.ini, so values captured during a * web request are used when the scan runs on the command line. */ class AOWPCS_Check_Php_Config extends AOWPCS_Check { public function id() { return 'php.config'; } public function category() { return 'php'; } public function rules() { $panel = __('Hosting control panel (PHP settings), php.ini / .user.ini, or the server administrator', 'all-in-one-wp-content-security'); $ini_doc = self::doc(__('PHP runtime configuration', 'all-in-one-wp-content-security'), 'https://www.php.net/manual/en/ini.list.php'); return array( 'php.display_errors' => array( 'title' => __('PHP displays errors to visitors', 'all-in-one-wp-content-security'), 'explanation' => __('display_errors is enabled for web requests, so any PHP warning or error is printed into the page.', 'all-in-one-wp-content-security'), 'impact' => __('Error messages reveal file system paths, code structure and sometimes database details, which help attackers plan further steps.', 'all-in-one-wp-content-security'), 'remediation' => __('Set display_errors = Off (and log_errors = On) for the production site.', 'all-in-one-wp-content-security'), 'steps' => array( __('In the hosting control panel (PHP settings) set display_errors to Off, or add "display_errors = Off" to php.ini / .user.ini.', 'all-in-one-wp-content-security'), __('Keep log_errors = On so errors are still written to the server log.', 'all-in-one-wp-content-security'), __('Optional immediate mitigation: "Apply fix" hides errors at runtime once WordPress has loaded.', 'all-in-one-wp-content-security'), ), 'docs' => array(self::doc('display_errors', 'https://www.php.net/manual/en/errorfunc.configuration.php#ini.display-errors')), 'permission' => $panel, 'fix' => 'hide_errors_runtime', ), 'php.expose_php' => array( 'title' => __('PHP announces its version in HTTP headers', 'all-in-one-wp-content-security'), 'kind' => 'hardening', 'explanation' => __('expose_php is on, so responses carry an "X-Powered-By: PHP/x.y.z" header.', 'all-in-one-wp-content-security'), 'impact' => __('Low: it tells automated scanners which PHP version to target. Keeping PHP updated matters more than hiding the version.', 'all-in-one-wp-content-security'), 'remediation' => __('Set expose_php = Off in php.ini (it cannot be changed at runtime).', 'all-in-one-wp-content-security'), 'steps' => array(__('Set expose_php = Off in the server\'s php.ini or ask your host to do so, then restart PHP.', 'all-in-one-wp-content-security')), 'docs' => array(self::doc('expose_php', 'https://www.php.net/manual/en/ini.core.php#ini.expose-php')), 'permission' => $panel, ), 'php.allow_url_include' => array( 'title' => __('PHP may include code from remote URLs', 'all-in-one-wp-content-security'), 'kind' => 'misconfiguration', 'explanation' => __('allow_url_include is enabled. It lets include/require load PHP code from http:// and other remote streams; WordPress never needs it.', 'all-in-one-wp-content-security'), 'impact' => __('Turns any file inclusion bug in a plugin into remote code execution.', 'all-in-one-wp-content-security'), 'remediation' => __('Set allow_url_include = Off.', 'all-in-one-wp-content-security'), 'steps' => array(__('Set allow_url_include = Off in php.ini / the hosting PHP settings and restart PHP.', 'all-in-one-wp-content-security')), 'docs' => array(self::doc('allow_url_include', 'https://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-include')), 'permission' => $panel, ), 'php.dangerous_functions' => array( 'title' => __('PHP functions that run system commands are available', 'all-in-one-wp-content-security'), 'kind' => 'informational', 'explanation' => __('Functions such as exec, shell_exec, system, passthru, proc_open and popen are not listed in disable_functions.', 'all-in-one-wp-content-security'), 'impact' => __('Informational. If an attacker can run PHP code, these functions let them run system commands too. Some legitimate plugins (backups, image optimisation) use them, so disabling them can break features.', 'all-in-one-wp-content-security'), 'remediation' => __('Only consider disabling them (disable_functions in php.ini) after confirming no plugin you use needs them. Never change this blindly.', 'all-in-one-wp-content-security'), 'steps' => array( __('Check whether your backup, image optimisation or deployment plugins require these functions.', 'all-in-one-wp-content-security'), __('If none do, ask your host to add them to disable_functions, then test the site.', 'all-in-one-wp-content-security'), ), 'docs' => array(self::doc('disable_functions', 'https://www.php.net/manual/en/ini.core.php#ini.disable-functions')), 'permission' => $panel, ), 'php.upload_limits' => array( 'title' => __('Upload size limits are inconsistent or very large', 'all-in-one-wp-content-security'), 'kind' => 'hardening', 'explanation' => __('upload_max_filesize and post_max_size control how much data a single request may send.', 'all-in-one-wp-content-security'), 'impact' => __('A post_max_size smaller than upload_max_filesize makes uploads fail without a clear error; very large limits let a single request consume a lot of disk space and memory.', 'all-in-one-wp-content-security'), 'remediation' => __('Set post_max_size slightly larger than upload_max_filesize, and keep both at what your site really needs.', 'all-in-one-wp-content-security'), 'steps' => array(__('Adjust upload_max_filesize and post_max_size in the hosting PHP settings (for example 64M and 72M).', 'all-in-one-wp-content-security')), 'docs' => array($ini_doc), 'permission' => $panel, ), ); } /** * ini values of web requests: live values, or the snapshot taken during the last web request */ public static function web_ini() { $keys = array('display_errors', 'expose_php', 'allow_url_include', 'disable_functions', 'upload_max_filesize', 'post_max_size', 'memory_limit', 'max_execution_time', 'open_basedir', 'log_errors'); if (PHP_SAPI !== 'cli') { $values = array(); foreach ($keys as $key) { $values[$key] = (string) ini_get($key); } $original = AOWPCS_Hardening::original_display_errors(); if ($original !== null) { $values['display_errors'] = $original; $values['display_errors_mitigated'] = AOWPCS_Hardening::is_enforced('hide_errors_runtime') ? '1' : ''; } return $values; } $snapshot = AOWPCS_Settings::state('php_ini_snapshot'); return is_array($snapshot) && !empty($snapshot['values']) ? $snapshot['values'] : null; } public static function ini_on($value) { $value = strtolower(trim((string) $value)); return in_array($value, array('1', 'on', 'yes', 'true', 'stdout', 'stderr'), true); } public static function bytes($value) { $value = trim((string) $value); if ($value === '') { return 0; } return function_exists('wp_convert_hr_to_bytes') ? wp_convert_hr_to_bytes($value) : (int) $value; } public function run($context) { $ini = self::web_ini(); if ($ini === null) { return $this->all_unknown(__('This scan runs on the command line, which uses a different php.ini. Open any admin page once so the plugin can record the web server\'s PHP settings, then scan again.', 'all-in-one-wp-content-security')); } $findings = array(); $production = AOWPCS_Plugin::is_production(); if (self::ini_on($ini['display_errors'])) { if (!$production) { /* translators: %s: type */ $findings[] = $this->pass('php.display_errors', sprintf(__('display_errors is on, which is acceptable for a "%s" environment.', 'all-in-one-wp-content-security'), wp_get_environment_type())); } elseif (!empty($ini['display_errors_mitigated'])) { $findings[] = $this->issue('php.display_errors', 'low', 'display_errors', __('display_errors is on in php.ini; this plugin hides errors at runtime, but errors raised before WordPress loads plugins are still shown.', 'all-in-one-wp-content-security'), array( 'detected' => 'display_errors = ' . $ini['display_errors'] . ' (' . __('mitigated at runtime', 'all-in-one-wp-content-security') . ')', 'expected' => 'display_errors = Off', )); } else { $findings[] = $this->issue('php.display_errors', 'high', 'display_errors', __('PHP errors are displayed in pages served to visitors.', 'all-in-one-wp-content-security'), array( 'detected' => 'display_errors = ' . $ini['display_errors'], 'expected' => 'display_errors = Off', 'evidence' => array('log_errors' => $ini['log_errors']), )); } } if (self::ini_on($ini['expose_php'])) { $findings[] = $this->issue('php.expose_php', 'low', 'expose_php', __('PHP sends its version in the X-Powered-By header.', 'all-in-one-wp-content-security'), array( 'detected' => 'expose_php = On', 'expected' => 'expose_php = Off', )); } if (self::ini_on($ini['allow_url_include'])) { $findings[] = $this->issue('php.allow_url_include', 'high', 'allow_url_include', __('allow_url_include is enabled.', 'all-in-one-wp-content-security'), array( 'detected' => 'allow_url_include = On', 'expected' => 'allow_url_include = Off', )); } $disabled = array_filter(array_map('trim', explode(',', strtolower($ini['disable_functions'])))); $risky = array('exec', 'shell_exec', 'system', 'passthru', 'proc_open', 'popen', 'pcntl_exec'); $available = array_values(array_diff($risky, $disabled)); if ($available) { /* translators: %d: available */ $findings[] = $this->issue('php.dangerous_functions', 'low', 'disable_functions', sprintf(__('%d functions that run system commands are available.', 'all-in-one-wp-content-security'), count($available)), array( 'kind' => 'informational', 'detected' => implode(', ', $available), 'expected' => __('Disabled where no plugin needs them (optional)', 'all-in-one-wp-content-security'), 'evidence' => array('disable_functions' => $ini['disable_functions'] !== '' ? $ini['disable_functions'] : __('(empty)', 'all-in-one-wp-content-security'), 'open_basedir' => $ini['open_basedir'] !== '' ? __('set', 'all-in-one-wp-content-security') : __('not set', 'all-in-one-wp-content-security')), )); } $upload = self::bytes($ini['upload_max_filesize']); $post = self::bytes($ini['post_max_size']); $limits = array('upload_max_filesize' => $ini['upload_max_filesize'], 'post_max_size' => $ini['post_max_size'], 'memory_limit' => $ini['memory_limit']); if ($post > 0 && $upload > $post) { $findings[] = $this->issue('php.upload_limits', 'low', 'upload_limits', __('post_max_size is smaller than upload_max_filesize, so large uploads fail.', 'all-in-one-wp-content-security'), array( 'kind' => 'misconfiguration', 'detected' => sprintf('upload_max_filesize = %s, post_max_size = %s', $ini['upload_max_filesize'], $ini['post_max_size']), 'expected' => __('post_max_size ≥ upload_max_filesize', 'all-in-one-wp-content-security'), 'evidence' => $limits, )); } elseif ($upload > 1073741824 || $post > 1073741824) { $findings[] = $this->issue('php.upload_limits', 'low', 'upload_limits', __('Requests may upload more than 1 GB.', 'all-in-one-wp-content-security'), array( 'detected' => sprintf('upload_max_filesize = %s, post_max_size = %s', $ini['upload_max_filesize'], $ini['post_max_size']), 'expected' => __('Limits that match what the site needs', 'all-in-one-wp-content-security'), 'evidence' => $limits, )); } else { $findings[] = $this->pass('php.upload_limits', sprintf('upload_max_filesize = %s, post_max_size = %s', $ini['upload_max_filesize'], $ini['post_max_size']), $limits); } return $findings; } } /** * Whether PHP files placed in the uploads directory could be executed */ class AOWPCS_Check_Php_Uploads_Execution extends AOWPCS_Check { public function id() { return 'php.uploads_execution'; } public function category() { return 'php'; } public function rules() { return array( 'php.uploads_execution' => array( 'title' => __('PHP execution may be possible in the uploads directory', 'all-in-one-wp-content-security'), 'explanation' => __('The uploads directory only needs to serve media files. If the web server executes .php files there, any upload vulnerability in a plugin becomes remote code execution.', 'all-in-one-wp-content-security'), 'impact' => __('A single file uploaded through a vulnerable form or plugin would give an attacker full control of the site.', 'all-in-one-wp-content-security'), 'remediation' => __('Deny execution of PHP files in wp-content/uploads.', 'all-in-one-wp-content-security'), 'steps' => array( __('Apache / LiteSpeed: use "Apply fix" to add a deny rule to wp-content/uploads/.htaccess. The change is verified with a harmless test file and can be rolled back.', 'all-in-one-wp-content-security'), __('Nginx: add a rule such as: location ~* ^/wp-content/uploads/.*\.(php[0-9]?|phtml|phar)$ { deny all; } to the server block and reload Nginx.', 'all-in-one-wp-content-security'), __('Run "Test now" to verify with a harmless test file.', 'all-in-one-wp-content-security'), ), 'docs' => array(self::doc(__('Hardening WordPress', 'all-in-one-wp-content-security'), 'https://developer.wordpress.org/advanced-administration/security/hardening/')), 'permission' => __('WordPress administrator (Apache/LiteSpeed fix) or web server configuration (Nginx)', 'all-in-one-wp-content-security'), 'fix' => 'uploads_php_deny', ), ); } /** * Whether a .htaccess body contains a rule that prevents PHP execution */ public static function htaccess_denies_php($content) { if (!is_string($content) || $content === '') { return false; } if (strpos($content, '# BEGIN ' . AOWPCS_Htaccess::UPLOADS) !== false) { return true; } if (preg_match('/php_flag\s+engine\s+off/i', $content) || preg_match('/RemoveHandler\s+[^\n]*\.php/i', $content) || preg_match('/SetHandler\s+none/i', $content)) { return true; } return (bool) preg_match('/]*php[^>]*>.*?(Require\s+all\s+denied|Deny\s+from\s+all)/is', $content); } public function run($context) { $probe = AOWPCS_Settings::state('uploads_probe'); if (is_array($probe) && !empty($probe['time']) && strtotime($probe['time'] . ' UTC') > time() - 30 * DAY_IN_SECONDS) { $evidence = array(__('Test performed', 'all-in-one-wp-content-security') => AOWPCS_Plugin::format_time($probe['time']), __('Result', 'all-in-one-wp-content-security') => $probe['detail']); if ($probe['result'] === 'executed') { return array($this->issue('php.uploads_execution', 'medium', 'uploads', __('A harmless test file placed in the uploads directory was executed by PHP.', 'all-in-one-wp-content-security'), array( 'confidence' => 'confirmed', 'detected' => __('PHP executes in uploads', 'all-in-one-wp-content-security'), 'expected' => __('PHP execution denied (HTTP 403)', 'all-in-one-wp-content-security'), 'evidence' => $evidence, ))); } if ($probe['result'] === 'blocked') { return array($this->pass('php.uploads_execution', __('A test file placed in the uploads directory was not executed.', 'all-in-one-wp-content-security'), $evidence)); } } $uploads = AOWPCS_Environment::uploads_dir(); $htaccess = $uploads['path'] . '/.htaccess'; $server = AOWPCS_Environment::server_software(); $evidence = array(__('Web server', 'all-in-one-wp-content-security') => AOWPCS_Environment::server_label()); if (in_array($server, array('apache', 'litespeed'), true)) { $content = is_readable($htaccess) ? file_get_contents($htaccess) : ''; if (self::htaccess_denies_php($content)) { $evidence[__('uploads/.htaccess', 'all-in-one-wp-content-security')] = __('contains a rule that denies PHP', 'all-in-one-wp-content-security'); return array($this->pass('php.uploads_execution', __('wp-content/uploads/.htaccess denies PHP execution. Use "Test now" to confirm with a test file.', 'all-in-one-wp-content-security'), $evidence)); } $evidence[__('uploads/.htaccess', 'all-in-one-wp-content-security')] = $content === '' ? __('missing or empty', 'all-in-one-wp-content-security') : __('no rule that denies PHP', 'all-in-one-wp-content-security'); return array($this->issue('php.uploads_execution', 'medium', 'uploads', __('Nothing in wp-content/uploads/.htaccess stops PHP files from being executed.', 'all-in-one-wp-content-security'), array( 'confidence' => 'unverified', 'detected' => __('No deny rule', 'all-in-one-wp-content-security'), 'expected' => __('PHP execution denied in uploads', 'all-in-one-wp-content-security'), 'evidence' => $evidence, ))); } if ($server === 'unknown') { return array($this->unknown('php.uploads_execution', __('The web server type is not known yet (it is recorded the first time an admin page is opened). Use "Test now" on this issue page to verify with a harmless test file.', 'all-in-one-wp-content-security'))); } /* translators: %s: label */ return array($this->unknown('php.uploads_execution', sprintf(__('The %s configuration cannot be read by WordPress. Use "Test now" on this issue page to verify with a harmless test file.', 'all-in-one-wp-content-security'), AOWPCS_Environment::server_label()))); } /** * Active verification (only on explicit request): write a harmless PHP file that prints a * random token, request it, delete it. Result is stored for 30 days. */ public static function probe() { $uploads = AOWPCS_Environment::uploads_dir(); if (!wp_is_writable($uploads['path'])) { return new WP_Error('aowpcs_probe', __('The uploads directory is not writable, so the test file could not be created.', 'all-in-one-wp-content-security')); } $token = AOWPCS_Plugin::token(12); $name = 'aowpcs-probe-' . AOWPCS_Plugin::token(8) . '.php'; $path = trailingslashit($uploads['path']) . $name; if (@file_put_contents($path, ' false)); @unlink($path); if ($response['error'] !== '') { /* translators: %s: response error */ $result = array('result' => 'unknown', 'detail' => sprintf(__('Request failed: %s', 'all-in-one-wp-content-security'), $response['error'])); } elseif ($response['status'] === 200 && trim($response['body']) === $token) { $result = array('result' => 'executed', 'detail' => __('HTTP 200 with the output of the PHP code', 'all-in-one-wp-content-security')); } elseif ($response['status'] === 200 && strpos($response['body'], $token) !== false) { $result = array('result' => 'blocked', 'detail' => __('The file was served as plain text (source visible) but not executed', 'all-in-one-wp-content-security')); } else { /* translators: %d: response status */ $result = array('result' => 'blocked', 'detail' => sprintf(__('HTTP %d', 'all-in-one-wp-content-security'), $response['status'])); } $result['time'] = AOWPCS_Plugin::now(); AOWPCS_Settings::set_state('uploads_probe', $result); /* translators: %s: result detail */ AOWPCS_Event_Log::log('uploads_probe', array('category' => 'scan', 'severity' => $result['result'] === 'executed' ? 'medium' : 'low', 'user_id' => get_current_user_id(), 'message' => sprintf(__('Uploads PHP execution test: %s', 'all-in-one-wp-content-security'), $result['detail']))); return $result; } }