(int) $state['scan_id'], 'fingerprint' => md5( 'config|' . $key ), 'category' => 'config', 'location' => '' !== $location ? $location : $key, 'line' => 0, 'severity' => $severity, 'confidence' => (int) $confidence, 'signature' => substr( 'cfg_' . preg_replace( '/[^a-z0-9_]/', '_', strtolower( $key ) ), 0, 64 ), 'title' => $title, 'description' => $description, 'snippet' => '', 'verdict' => 'suspicious', 'remediation' => $remediation, 'file_hash' => md5( $description ), 'meta' => $meta, ) ); $state['findings']++; if ( 'critical' === $severity ) { $state['critical']++; } } private static function check_versions( array &$state ) { if ( ! function_exists( 'get_core_updates' ) ) { require_once ABSPATH . 'wp-admin/includes/update.php'; } $updates = get_site_transient( 'update_core' ); if ( ! is_object( $updates ) || empty( $updates->updates ) || ( isset( $updates->last_checked ) && time() - (int) $updates->last_checked > DAY_IN_SECONDS ) ) { wp_version_check( array(), true ); } $core = get_core_updates(); if ( is_array( $core ) && ! empty( $core[0] ) && isset( $core[0]->response ) && 'upgrade' === $core[0]->response ) { self::add( $state, 'WordPress core', __( 'WordPress is not up to date', 'ai-guardwall' ), 'medium', 75, sprintf( /* translators: 1: WordPress version, 2: current */ __( 'Version %1$s is installed; %2$s is available. Updates close publicly known holes; this is the single most effective protection.', 'ai-guardwall' ), Softvolt_Ai_Bodyguard_Helpers::wp_version(), $core[0]->current ), 'update', array( 'details' => $core[0]->current ) ); } wp_update_plugins(); $plugins = get_site_transient( 'update_plugins' ); if ( is_object( $plugins ) && ! empty( $plugins->response ) ) { $installed = Softvolt_Ai_Bodyguard_Integrity::installed_plugins(); foreach ( $plugins->response as $file => $data ) { $name = isset( $installed[ $file ]['Name'] ) ? $installed[ $file ]['Name'] : $file; $from = isset( $installed[ $file ]['Version'] ) ? $installed[ $file ]['Version'] : '?'; $to = isset( $data->new_version ) ? $data->new_version : '?'; self::add( $state, 'plugin|' . $file, sprintf( /* translators: %s: name */ __( 'Plugin update available: %s', 'ai-guardwall' ), $name ), 'medium', 55, sprintf( /* translators: 1: name, 2: from, 3: to */ __( '%1$s %2$s is installed; %3$s is available. Most WordPress hacks come through outdated plugins with published vulnerabilities.', 'ai-guardwall' ), $name, $from, $to ), 'update', array( 'details' => $file ), 'wp-content/plugins/' . $file ); } } wp_update_themes(); $themes = get_site_transient( 'update_themes' ); if ( is_object( $themes ) && ! empty( $themes->response ) ) { foreach ( $themes->response as $slug => $data ) { $to = isset( $data['new_version'] ) ? $data['new_version'] : '?'; self::add( $state, 'theme|' . $slug, sprintf( /* translators: %s: slug */ __( 'Theme update available: %s', 'ai-guardwall' ), $slug ), 'low', 45, sprintf( /* translators: 1: slug, 2: to */ __( 'Theme "%1$s" can be updated to %2$s.', 'ai-guardwall' ), $slug, $to ), 'update', array( 'details' => $slug ), 'wp-content/themes/' . $slug ); } } $inactive = array(); $active = (array) get_option( 'active_plugins', array() ); foreach ( Softvolt_Ai_Bodyguard_Integrity::installed_plugins() as $file => $data ) { if ( ! in_array( $file, $active, true ) && ! is_plugin_active_for_network( $file ) ) { $inactive[] = $data['Name']; } } if ( $inactive ) { self::add( $state, 'inactive plugins', sprintf( /* translators: %d: number of inactive */ _n( '%d inactive plugin installed', '%d inactive plugins installed', count( $inactive ), 'ai-guardwall' ), count( $inactive ) ), 'info', 20, sprintf( /* translators: %s: list of inactive */ __( 'Inactive plugins still contain code attackers can reach. Delete the ones you do not use: %s', 'ai-guardwall' ), implode( ', ', array_slice( $inactive, 0, 25 ) ) ), 'manual_review' ); } $all_themes = wp_get_themes(); $extra = array(); foreach ( $all_themes as $slug => $theme ) { if ( $slug !== get_stylesheet() && $slug !== get_template() ) { $extra[] = $slug; } } if ( count( $extra ) > 1 ) { self::add( $state, 'inactive themes', sprintf( /* translators: %d: number of extra */ __( '%d inactive themes installed', 'ai-guardwall' ), count( $extra ) ), 'info', 20, sprintf( /* translators: %s: list of extra */ __( 'Keep the active theme (and its parent) plus one default theme; delete the rest: %s', 'ai-guardwall' ), implode( ', ', $extra ) ), 'manual_review' ); } $php = Softvolt_Ai_Bodyguard_Helpers::php_status(); if ( 'unsupported' === $php ) { self::add( $state, 'PHP version', __( 'PHP version is no longer supported', 'ai-guardwall' ), 'high', 80, sprintf( /* translators: %s: value */ __( 'PHP %s receives no security fixes. Switch to PHP 8.3 or newer in your hosting panel.', 'ai-guardwall' ), PHP_VERSION ), 'fix_config' ); } elseif ( 'outdated' === $php ) { self::add( $state, 'PHP version', __( 'PHP is missing security fixes', 'ai-guardwall' ), 'medium', 80, sprintf( /* translators: %s: value */ __( 'PHP %s is older than 8.2.35, the release with the latest PHP 8.2 security fixes. Ask your host for 8.2.35 or newer, or better switch to PHP 8.3 or newer in your hosting panel.', 'ai-guardwall' ), PHP_VERSION ), 'fix_config' ); } } private static function check_wp_config( array &$state ) { $path = Softvolt_Ai_Bodyguard_Wpconfig::path(); if ( defined( 'WP_DEBUG' ) && WP_DEBUG && ( ! defined( 'WP_DEBUG_DISPLAY' ) || WP_DEBUG_DISPLAY ) ) { self::add( $state, 'WP_DEBUG', __( 'Debug output is shown to visitors', 'ai-guardwall' ), 'medium', 70, __( 'WP_DEBUG is on and WP_DEBUG_DISPLAY is not off, so error messages with file paths and database details can appear on the site. Set WP_DEBUG_DISPLAY to false (and WP_DEBUG off in production).', 'ai-guardwall' ), 'fix_config', array(), 'wp-config.php' ); } if ( ( ! defined( 'DISALLOW_FILE_EDIT' ) || ! DISALLOW_FILE_EDIT ) && ! Softvolt_Ai_Bodyguard_Settings::hardening_enabled( 'disable_file_edit' ) ) { self::add( $state, 'DISALLOW_FILE_EDIT', __( 'The theme/plugin file editor is enabled', 'ai-guardwall' ), 'low', 40, __( 'Anyone who gets an administrator login can write PHP through Appearance > Theme File Editor. Switch on "Disable the file editor" on the Hardening tab.', 'ai-guardwall' ), 'fix_config', array( 'rule' => 'disable_file_edit' ), 'wp-config.php' ); } $salts = Softvolt_Ai_Bodyguard_Wpconfig::weak_salts(); if ( $salts ) { self::add( $state, 'salts', __( 'Security keys and salts are weak or placeholders', 'ai-guardwall' ), 'high', 80, sprintf( /* translators: %s: list of salts */ __( 'These keys are missing or still the sample text: %s. Weak salts let attackers forge login cookies. Rotate them on the Tools tab.', 'ai-guardwall' ), implode( ', ', $salts ) ), 'fix_config', array( 'details' => implode( ', ', $salts ) ), 'wp-config.php' ); } global $wpdb; if ( 'wp_' === $wpdb->prefix ) { self::add( $state, 'table prefix', __( 'Database tables use the default "wp_" prefix', 'ai-guardwall' ), 'low', 20, __( 'Automated SQL-injection payloads assume wp_. A custom prefix is a small extra hurdle; change it only with a backup and a plugin made for it.', 'ai-guardwall' ), 'manual_review', array(), 'wp-config.php' ); } if ( $path && is_readable( $path ) ) { $content = (string) file_get_contents( $path ); if ( preg_match( '/\b(?:include|require)(?:_once)?\b\s*\(?\s*(?![\'"]?\s*ABSPATH\s*\.\s*[\'"]wp-settings\.php)/i', preg_replace( '~/\*.*?\*/|//[^\n]*|#[^\n]*~s', '', $content ) ) ) { self::add( $state, 'wp-config include', __( 'wp-config.php includes an extra file', 'ai-guardwall' ), 'high', 70, __( 'Besides wp-settings.php, wp-config.php loads another file. Hosts sometimes add environment files; malware hides loaders here. Open the file and check what is included.', 'ai-guardwall' ), 'manual_review', array( 'rel' => Softvolt_Ai_Bodyguard_Helpers::rel_path( $path ) ), 'wp-config.php' ); } } } private static function check_permissions( array &$state ) { if ( '\\' === DIRECTORY_SEPARATOR ) { return; // Windows reports 0777/0666 for everything; Unix permissions mean nothing here. } $items = array( 'wp-config.php' => array( Softvolt_Ai_Bodyguard_Wpconfig::path(), 'file' ), '.htaccess' => array( Softvolt_Ai_Bodyguard_Htaccess::root_file(), 'file' ), '/' => array( Softvolt_Ai_Bodyguard_Helpers::site_dir( '' ), 'dir' ), 'wp-admin/' => array( Softvolt_Ai_Bodyguard_Helpers::site_dir( '' ) . '/wp-admin', 'dir' ), 'wp-includes/' => array( Softvolt_Ai_Bodyguard_Helpers::site_dir( '' ) . '/' . WPINC, 'dir' ), 'wp-content/' => array( Softvolt_Ai_Bodyguard_Helpers::site_dir( 'wp-content' ), 'dir' ), 'wp-content/plugins/' => array( Softvolt_Ai_Bodyguard_Helpers::site_dir( 'wp-content/plugins' ), 'dir' ), 'wp-content/themes/' => array( Softvolt_Ai_Bodyguard_Helpers::site_dir( 'wp-content/themes' ), 'dir' ), 'wp-content/uploads/' => array( Softvolt_Ai_Bodyguard_Helpers::site_dir( 'wp-content/uploads' ), 'dir' ), ); foreach ( $items as $label => $info ) { list( $path, $kind ) = $info; if ( ! $path || ! file_exists( $path ) ) { continue; } $perms = @fileperms( $path ); if ( false === $perms ) { continue; } $mode = $perms & 0777; if ( $mode & 0002 ) { self::add( $state, 'perm|' . $label, sprintf( /* translators: %s: label */ __( '%s is writable by everyone', 'ai-guardwall' ), $label ), 'high', 85, sprintf( /* translators: 1: text, 2: value */ __( 'Permissions are %1$s. Any process on the server (another customer\'s site on shared hosting) can change it. Set %2$s.', 'ai-guardwall' ), sprintf( '%04o', $mode ), 'dir' === $kind ? '755' : ( 'wp-config.php' === $label ? '600' : '644' ) ), 'fix_config', array( 'details' => sprintf( '%04o', $mode ) ), $label ); } elseif ( 'wp-config.php' === $label && ( $mode & 0004 ) ) { self::add( $state, 'perm|' . $label, __( 'wp-config.php is readable by other users on the server', 'ai-guardwall' ), 'low', 35, sprintf( /* translators: %s: text */ __( 'Permissions are %s. On shared hosting, 600 or 640 keeps your database password private from other accounts (some hosts require 644; check with yours).', 'ai-guardwall' ), sprintf( '%04o', $mode ) ), 'fix_config', array( 'details' => sprintf( '%04o', $mode ) ), $label ); } } } private static function check_exposure( array &$state ) { if ( 'https' !== wp_parse_url( home_url(), PHP_URL_SCHEME ) ) { self::add( $state, 'https', __( 'The site does not use HTTPS', 'ai-guardwall' ), 'medium', 75, __( 'Logins and cookies travel in clear text. Install a free Let\'s Encrypt certificate at your host, enforce HTTPS and change both URLs under Settings > General to https://.', 'ai-guardwall' ), 'fix_config' ); } if ( ! Softvolt_Ai_Bodyguard_Settings::hardening_enabled( 'disable_xmlrpc' ) ) { self::add( $state, 'xmlrpc', __( 'XML-RPC is enabled', 'ai-guardwall' ), 'low', 30, __( 'xmlrpc.php is used for brute-force amplification (system.multicall) and pingback floods. Unless you use the WordPress mobile app or Jetpack, switch "Disable XML-RPC" on under Hardening.', 'ai-guardwall' ), 'fix_config', array( 'rule' => 'disable_xmlrpc' ), 'xmlrpc.php' ); } $probes = array( 'dir_listing' => array( includes_url(), 'GET', '/Index of|Parent Directory/i', __( 'Directory listing is enabled', 'ai-guardwall' ), 'medium', 60, __( 'Visitors can browse folder contents (for example /wp-includes/), which reveals versions and file names. Switch "Disable directory browsing" on under Hardening.', 'ai-guardwall' ), 'disable_directory_indexes' ), 'readme' => array( home_url( '/readme.html' ), 'GET', '/<title>WordPress/i', __( 'readme.html is publicly readable', 'ai-guardwall' ), 'low', 25, __( 'The readme reveals the WordPress version. Switch "Protect sensitive files" on under Hardening.', 'ai-guardwall' ), 'protect_sensitive_files' ), 'rest_users' => array( add_query_arg( 'rest_route', '/wp/v2/users', home_url( '/' ) ), 'GET', '/"slug"\s*:\s*"/', __( 'User names are exposed through the REST API', 'ai-guardwall' ), 'medium', 60, __( 'Anyone can list your user accounts (login names) at /wp-json/wp/v2/users, which feeds brute-force attacks. Switch "Stop user enumeration" on under Hardening.', 'ai-guardwall' ), 'disable_user_enumeration' ), 'debug_log' => array( content_url( '/debug.log' ), 'GET', '/PHP (?:Notice|Warning|Fatal|Deprecated)|Stack trace/i', __( 'The debug log is publicly readable', 'ai-guardwall' ), 'medium', 70, __( 'wp-content/debug.log is downloadable by anyone and contains file paths and sometimes credentials. Switch "Protect sensitive files" on, or delete the file and turn WP_DEBUG_LOG off.', 'ai-guardwall' ), 'protect_sensitive_files' ), ); foreach ( $probes as $key => $p ) { if ( 'debug_log' === $key && ! file_exists( Softvolt_Ai_Bodyguard_Helpers::site_dir( 'wp-content' ) . '/debug.log' ) ) { continue; } $res = wp_remote_request( $p[0], array( 'method' => $p[1], 'timeout' => 6, 'redirection' => 0, 'sslverify' => apply_filters( 'https_local_ssl_verify', false ), 'user-agent' => Softvolt_Ai_Bodyguard_Providers::user_agent() . ' (self-check)', 'cookies' => array(), ) ); if ( is_wp_error( $res ) || 200 !== (int) wp_remote_retrieve_response_code( $res ) ) { continue; } $body = (string) wp_remote_retrieve_body( $res ); if ( preg_match( $p[2], $body ) ) { self::add( $state, 'exposure|' . $key, $p[3], $p[4], $p[5], $p[6], 'fix_config', array( 'rule' => $p[7] ), $p[0] ); } } } private static function check_misc( array &$state ) { $missing = Softvolt_Ai_Bodyguard_Integrity::missing_core_files(); if ( $missing ) { self::add( $state, 'missing core files', sprintf( /* translators: %d: number of missing */ _n( '%d WordPress core file is missing', '%d WordPress core files are missing', count( $missing ), 'ai-guardwall' ), count( $missing ) ), 'high', 70, sprintf( /* translators: %s: list of missing */ __( 'Files that ship with this WordPress version are absent: %s. Malware sometimes deletes core files (for example to stop updates); re-install WordPress from Dashboard > Updates.', 'ai-guardwall' ), implode( ', ', array_slice( $missing, 0, 20 ) ) . ( count( $missing ) > 20 ? '…' : '' ) ), 'replace_official_file', array( 'details' => implode( "\n", $missing ) ), 'wp-admin/, wp-includes/' ); } $others = array(); foreach ( array( 'wordfence/wordfence.php' => 'Wordfence', 'sucuri-scanner/sucuri.php' => 'Sucuri', 'better-wp-security/better-wp-security.php' => 'Solid Security', 'all-in-one-wp-security-and-firewall/wp-security.php' => 'All-In-One Security', 'wp-cerber/wp-cerber.php' => 'WP Cerber', 'malcare-security/malcare.php' => 'MalCare' ) as $file => $name ) { if ( is_plugin_active( $file ) ) { $others[] = $name; } } if ( $others ) { self::add( $state, 'other security plugins', __( 'Another security plugin is active', 'ai-guardwall' ), 'info', 20, sprintf( /* translators: %s: list of others */ __( 'Running two firewalls (%s and AI GuardWall) doubles the load and can block each other. Keep one firewall on; AI GuardWall\'s scanner can still run alongside.', 'ai-guardwall' ), implode( ', ', $others ) ), 'manual_review' ); } if ( 'block' !== Softvolt_Ai_Bodyguard_Settings::get( 'firewall_mode' ) ) { self::add( $state, 'firewall off', __( 'The AI GuardWall firewall is not blocking', 'ai-guardwall' ), 'low', 40, __( 'The firewall is off or in log-only mode, so attacks are recorded but not stopped. Set it to Block on the Firewall tab.', 'ai-guardwall' ), 'fix_config', array( 'rule' => 'firewall' ) ); } if ( ! Softvolt_Ai_Bodyguard_Settings::hardening_enabled( 'two_factor' ) ) { self::add( $state, '2fa off', __( 'Two-factor authentication is off', 'ai-guardwall' ), 'low', 40, __( 'A stolen or guessed password is enough to take over the site. Switch on two-factor authentication for administrators under Login security.', 'ai-guardwall' ), 'fix_config', array( 'rule' => 'two_factor' ) ); } } }