'config', 'wp-config.php~' => 'config', 'wp-config.bak' => 'config', 'wp-config.old' => 'config', 'wp-config.php.old' => 'config', 'wp-config.php.save' => 'config', 'wp-config.php.orig' => 'config', 'wp-config.txt' => 'config', '.wp-config.php.swp' => 'config', '.env' => 'env', '.git/config' => 'git', '.htpasswd' => 'htpasswd', 'backup.sql' => 'sql', 'database.sql' => 'sql', 'dump.sql' => 'sql', 'db.sql' => 'sql', 'wordpress.sql' => 'sql', 'backup.zip' => 'zip', 'site.zip' => 'zip', 'wordpress.zip' => 'zip', 'public_html.zip' => 'zip', 'error_log' => 'log', 'php_errorlog' => 'log', 'phpinfo.php' => 'info', 'info.php' => 'info', ); /** The passwords tried against administrator accounts (plus the user name and site name). */ const COMMON = array( '123456', '123456789', '12345678', 'password', 'qwerty', '12345', '1234567', '111111', '123123', 'abc123', 'password1', 'admin', 'admin123', 'admin@123', 'administrator', 'letmein', 'welcome', 'welcome1', 'qwerty123', '1q2w3e4r', 'iloveyou', 'monkey', 'dragon', 'sunshine', 'master', 'football', 'pass123', 'wordpress', 'wp-admin', 'changeme', 'test', 'test123', '000000', 'P@ssw0rd', 'Passw0rd', 'secret' ); /** * One step of the audit. * * @param array $state Scan state (by reference). * @param float $deadline microtime() to stop at. * @return bool True when every task is done. */ public static function step( array &$state, $deadline ) { if ( empty( $state['audit'] ) ) { $state['audit'] = array( 'tasks' => self::tasks(), 'i' => 0, 'vuln' => array(), ); } $a = &$state['audit']; while ( $a['i'] < count( $a['tasks'] ) ) { $task = $a['tasks'][ $a['i'] ]; $a['i']++; $state['current'] = 'audit: ' . $task; try { self::run_task( $task, $state ); } catch ( Throwable $e ) { $state['errors'][] = Softvolt_Ai_Bodyguard_Helpers::trim_text( 'audit ' . $task . ': ' . $e->getMessage(), 300 ); } if ( microtime( true ) >= $deadline ) { return false; } } $state['current'] = ''; if ( ! empty( $a['vuln'] ) && 'scheduled' === ( $state['type'] ?? '' ) ) { do_action( 'svabg_vulnerable_software', $a['vuln'] ); } return true; } /** * The share of tasks done (0..1). */ public static function progress( $state ) { if ( empty( $state['audit']['tasks'] ) ) { return 0; } return min( 1, $state['audit']['i'] / max( 1, count( $state['audit']['tasks'] ) ) ); } private static function on( $key ) { return (bool) Softvolt_Ai_Bodyguard_Settings::get( $key, 1 ); } /** * The task list for this site. */ public static function tasks() { $t = array(); if ( self::on( 'scan_vulnerabilities' ) ) { $t[] = 'vuln_core'; foreach ( array_keys( Softvolt_Ai_Bodyguard_Integrity::installed_plugins() ) as $file ) { $t[] = 'vuln_plugin:' . $file; } foreach ( array_keys( wp_get_themes() ) as $slug ) { $t[] = 'vuln_theme:' . $slug; } } if ( self::on( 'scan_abandoned' ) ) { foreach ( self::repo_plugins() as $file => $slug ) { $t[] = 'abandoned:' . $file; } } if ( self::on( 'scan_exposed_files' ) ) { foreach ( array_keys( self::PROBES ) as $path ) { $t[] = 'probe:' . $path; } $t[] = 'fpd'; $t[] = 'uploads_listing'; } if ( self::on( 'scan_weak_passwords' ) ) { foreach ( get_users( array( 'role' => 'administrator', 'fields' => 'ID', 'number' => 50 ) ) as $id ) { $t[] = 'password:' . (int) $id; } } if ( self::on( 'scan_reputation' ) ) { $t[] = 'dnsbl'; $t[] = 'safe_browsing'; } $t[] = 'ssl'; $t[] = 'disk'; $t[] = 'display_names'; /** * The audit tasks of a scan. * * @since 1.4.0 * @param string[] $t Task ids. */ return (array) apply_filters( 'svabg_audit_tasks', $t ); } private static function run_task( $task, array &$state ) { list( $kind, $arg ) = array_pad( explode( ':', $task, 2 ), 2, '' ); switch ( $kind ) { case 'vuln_core': self::vuln_core( $state ); break; case 'vuln_plugin': self::vuln_plugin( $state, $arg ); break; case 'vuln_theme': self::vuln_theme( $state, $arg ); break; case 'abandoned': self::abandoned( $state, $arg ); break; case 'probe': self::probe( $state, $arg ); break; case 'fpd': self::fpd( $state ); break; case 'uploads_listing': self::uploads_listing( $state ); break; case 'password': self::weak_password( $state, (int) $arg ); break; case 'dnsbl': self::dnsbl( $state ); break; case 'safe_browsing': self::safe_browsing( $state ); break; case 'ssl': self::ssl( $state ); break; case 'disk': self::disk( $state ); break; case 'display_names': self::display_names( $state ); break; default: do_action( 'svabg_audit_task', $task, $state ); } } private static function add( array &$state, $key, $category, $location, $title, $severity, $confidence, $description, $remediation = 'manual_review', $meta = array() ) { Softvolt_Ai_Bodyguard_Findings::upsert( array( 'scan_id' => (int) $state['scan_id'], 'fingerprint' => md5( 'audit|' . $key ), 'category' => $category, 'location' => $location, 'line' => 0, 'severity' => $severity, 'confidence' => (int) $confidence, 'signature' => substr( 'audit_' . preg_replace( '/[^a-z0-9_]/', '_', strtolower( strtok( $key, '|' ) ) ), 0, 64 ), 'title' => $title, 'description' => $description, 'snippet' => '', 'verdict' => 'suspicious', 'remediation' => $remediation, 'file_hash' => md5( $title . $description ), 'meta' => $meta, ) ); $state['findings']++; if ( 'critical' === $severity ) { $state['critical']++; } } /* -------------------------------- vulnerabilities -------------------------------- */ /** * A WPVulnerability answer, cached for 12 hours. */ private static function api( $path ) { $key = 'svabg_vuln_' . md5( $path ); $cached = get_transient( $key ); if ( is_array( $cached ) ) { return $cached; } $res = wp_remote_get( self::API . $path, array( 'timeout' => 10, 'user-agent' => 'AI-GuardWall/' . SOFTVOLT_AI_BODYGUARD_VERSION, ) ); if ( is_wp_error( $res ) || 200 !== (int) wp_remote_retrieve_response_code( $res ) ) { return null; } $body = json_decode( (string) wp_remote_retrieve_body( $res ), true ); $data = is_array( $body ) && empty( $body['error'] ) && isset( $body['data'] ) && is_array( $body['data'] ) ? $body['data'] : array(); set_transient( $key, $data, 12 * HOUR_IN_SECONDS ); return $data; } /** * Whether a version falls inside a vulnerability's range. */ public static function affected( $version, $op ) { $map = array( 'lt' => '<', 'le' => '<=', 'gt' => '>', 'ge' => '>=', 'eq' => '==' ); if ( ! is_array( $op ) ) { return true; } if ( ! empty( $op['min_version'] ) && isset( $map[ $op['min_operator'] ?? '' ] ) && ! version_compare( $version, (string) $op['min_version'], $map[ $op['min_operator'] ] ) ) { return false; } if ( ! empty( $op['max_version'] ) && isset( $map[ $op['max_operator'] ?? '' ] ) && ! version_compare( $version, (string) $op['max_version'], $map[ $op['max_operator'] ] ) ) { return false; } return ! empty( $op['max_version'] ) || ! empty( $op['min_version'] ) || ! empty( $op['unfixed'] ); } /** * Severity from the CVSS score (unknown scores count as high). */ private static function severity( $v ) { $score = isset( $v['impact']['cvss']['score'] ) ? (float) $v['impact']['cvss']['score'] : ( isset( $v['impact']['cvss3']['score'] ) ? (float) $v['impact']['cvss3']['score'] : -1 ); if ( $score < 0 ) { return 'high'; } if ( $score >= 9 ) { return 'critical'; } if ( $score >= 7 ) { return 'high'; } return $score >= 4 ? 'medium' : 'low'; } /** * Turn a list of vulnerabilities into one finding for the component. */ private static function report( array &$state, $type, $id, $name, $version, $location, array $list ) { if ( ! $list ) { return; } $rank = 0; $sev = 'low'; $lines = array(); $links = array(); $fixed = ''; $open = false; foreach ( $list as $v ) { $s = self::severity( $v ); if ( Softvolt_Ai_Bodyguard_Helpers::severity_rank( $s ) > $rank ) { $rank = Softvolt_Ai_Bodyguard_Helpers::severity_rank( $s ); $sev = $s; } $title = ''; foreach ( (array) ( $v['source'] ?? array() ) as $src ) { if ( '' === $title && ! empty( $src['name'] ) && 0 !== strpos( (string) $src['name'], 'CVE-' ) ) { // Names such as "Plugin <= 1.2 - XSS": only real tags are removed, a lone "<" stays. $title = trim( preg_replace( '/<\/?[a-z][^>]*>/i', '', html_entity_decode( (string) $src['name'], ENT_QUOTES ) ) ); } if ( ! empty( $src['link'] ) && count( $links ) < 6 ) { $links[] = esc_url_raw( (string) $src['link'] ); } } $title = '' !== $title ? $title : (string) ( $v['name'] ?? '' ); $max = isset( $v['operator']['max_version'] ) ? (string) $v['operator']['max_version'] : ''; $fix = '' !== $max && 'lt' === ( $v['operator']['max_operator'] ?? '' ) ? $max : ''; if ( ! empty( $v['operator']['unfixed'] ) && '0' !== (string) $v['operator']['unfixed'] ) { $open = true; } if ( '' !== $fix && ( '' === $fixed || version_compare( $fix, $fixed, '>' ) ) ) { $fixed = $fix; } $lines[] = '• ' . $title . ( '' !== $fix ? ' ' . sprintf( /* translators: %s: fix */ __( '(fixed in %s)', 'ai-guardwall' ), $fix ) : '' ); } $desc = sprintf( /* translators: 1: name, 2: version, 3: count. */ _n( '%1$s %2$s has %3$d publicly known security hole:', '%1$s %2$s has %3$d publicly known security holes:', count( $list ), 'ai-guardwall' ), $name, $version, count( $list ) ) . "\n" . implode( "\n", array_slice( $lines, 0, 12 ) ) . "\n\n" . ( $open && '' === $fixed ? __( 'No fixed version exists yet. Deactivate it and look for an alternative until a fix is released.', 'ai-guardwall' ) : sprintf( /* translators: %s: value */ __( 'Update to %s or later now (Dashboard › Updates). Attackers scan for these holes within days of them being published.', 'ai-guardwall' ), '' !== $fixed ? $fixed : __( 'the latest version', 'ai-guardwall' ) ) ); self::add( $state, 'vuln|' . $type . '|' . $id, $type, $location, sprintf( /* translators: 1: name, 2: version */ __( 'Known vulnerability: %1$s %2$s', 'ai-guardwall' ), $name, $version ), $sev, 90, $desc, $open && '' === $fixed ? 'manual_review' : 'update', array( 'details' => $id, 'links' => $links, 'fixed_in' => $fixed, 'count' => count( $list ) ) ); $state['audit']['vuln'][] = array( 'name' => $name, 'version' => $version, 'title' => count( $list ) > 1 ? sprintf( /* translators: %d: number of list */ __( '%d known security holes', 'ai-guardwall' ), count( $list ) ) : trim( ltrim( $lines[0], '• ' ) ), 'fixed_in' => $fixed ); } private static function vuln_core( array &$state ) { $version = Softvolt_Ai_Bodyguard_Helpers::wp_version(); $data = self::api( 'core/' . rawurlencode( $version ) . '/' ); if ( ! $data ) { return; } // The core endpoint is per version: every entry applies. self::report( $state, 'core', 'wordpress', 'WordPress', $version, 'wp-includes/version.php', (array) ( $data['vulnerability'] ?? array() ) ); } private static function vuln_plugin( array &$state, $file ) { $plugins = Softvolt_Ai_Bodyguard_Integrity::installed_plugins(); if ( ! isset( $plugins[ $file ] ) ) { return; } $slug = false !== strpos( $file, '/' ) ? dirname( $file ) : basename( $file, '.php' ); $version = (string) $plugins[ $file ]['Version']; $data = self::api( 'plugin/' . rawurlencode( $slug ) . '/' ); if ( ! $data || '' === $version ) { return; } $hit = array(); foreach ( (array) ( $data['vulnerability'] ?? array() ) as $v ) { if ( self::affected( $version, $v['operator'] ?? null ) ) { $hit[] = $v; } } self::report( $state, 'plugin', $file, (string) $plugins[ $file ]['Name'], $version, 'wp-content/plugins/' . $file, $hit ); } private static function vuln_theme( array &$state, $slug ) { $theme = wp_get_theme( $slug ); if ( ! $theme->exists() ) { return; } $version = (string) $theme->get( 'Version' ); $data = self::api( 'theme/' . rawurlencode( $slug ) . '/' ); if ( ! $data || '' === $version ) { return; } $hit = array(); foreach ( (array) ( $data['vulnerability'] ?? array() ) as $v ) { if ( self::affected( $version, $v['operator'] ?? null ) ) { $hit[] = $v; } } self::report( $state, 'theme', $slug, (string) $theme->get( 'Name' ), $version, 'wp-content/themes/' . $slug, $hit ); } /* --------------------------------- abandoned --------------------------------- */ /** * Plugins WordPress.org knows (from the update check): file => slug. */ public static function repo_plugins() { $out = array(); $t = get_site_transient( 'update_plugins' ); foreach ( array( 'response', 'no_update' ) as $k ) { if ( is_object( $t ) && ! empty( $t->$k ) ) { foreach ( (array) $t->$k as $file => $item ) { $item = (object) $item; if ( ! empty( $item->slug ) && ( empty( $item->url ) || false !== strpos( (string) $item->url, 'wordpress.org' ) ) ) { $out[ $file ] = (string) $item->slug; } } } } return $out; } private static function abandoned( array &$state, $file ) { $repo = self::repo_plugins(); $all = Softvolt_Ai_Bodyguard_Integrity::installed_plugins(); if ( ! isset( $repo[ $file ], $all[ $file ] ) ) { return; } $slug = $repo[ $file ]; $key = 'svabg_wporg_' . md5( $slug ); $info = get_transient( $key ); if ( ! is_array( $info ) ) { $res = wp_remote_get( 'https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&request[slug]=' . rawurlencode( $slug ) . '&request[fields][sections]=0&request[fields][versions]=0&request[fields][screenshots]=0&request[fields][contributors]=0', array( 'timeout' => 10 ) ); if ( is_wp_error( $res ) ) { return; } $info = json_decode( (string) wp_remote_retrieve_body( $res ), true ); $info = is_array( $info ) ? array_intersect_key( $info, array_flip( array( 'error', 'closed', 'closed_date', 'reason', 'reason_text', 'last_updated', 'name' ) ) ) : array(); set_transient( $key, $info, 3 * DAY_IN_SECONDS ); } $name = (string) $all[ $file ]['Name']; if ( ( isset( $info['error'] ) && 'closed' === $info['error'] ) || ! empty( $info['closed'] ) ) { $why = ! empty( $info['reason_text'] ) ? (string) $info['reason_text'] : ( ! empty( $info['reason'] ) ? (string) $info['reason'] : '' ); self::add( $state, 'closed|' . $slug, 'plugin', 'wp-content/plugins/' . $file, sprintf( /* translators: %s: name */ __( 'Plugin removed from WordPress.org: %s', 'ai-guardwall' ), $name ), 'high', 80, sprintf( /* translators: 1: name, 2: value */ __( '%1$s was closed on WordPress.org%2$s. Closed plugins get no more updates, and they are often closed because of an unfixed security issue. Replace it with a maintained alternative.', 'ai-guardwall' ), $name, '' !== $why ? ' (' . $why . ( ! empty( $info['closed_date'] ) ? ', ' . substr( (string) $info['closed_date'], 0, 10 ) : '' ) . ')' : '' ), 'manual_review', array( 'details' => $file ) ); return; } if ( ! empty( $info['last_updated'] ) ) { $when = strtotime( (string) $info['last_updated'] ); if ( $when && $when < time() - 2 * YEAR_IN_SECONDS ) { self::add( $state, 'abandoned|' . $slug, 'plugin', 'wp-content/plugins/' . $file, sprintf( /* translators: %s: name */ __( 'Plugin not updated for over two years: %s', 'ai-guardwall' ), $name ), 'medium', 60, sprintf( /* translators: 1: name, 2: date */ __( '%1$s was last updated on %2$s. It may be abandoned: security problems found now would not be fixed. Look for a maintained alternative.', 'ai-guardwall' ), $name, wp_date( get_option( 'date_format' ), $when ) ), 'manual_review', array( 'details' => $file ) ); } } } /* ---------------------------------- exposure ---------------------------------- */ private static function fetch( $url, $bytes = 4096 ) { $res = wp_remote_get( $url, array( 'timeout' => 6, 'redirection' => 0, 'sslverify' => apply_filters( 'https_local_ssl_verify', false ), 'limit_response_size' => $bytes, 'user-agent' => 'AI-GuardWall/' . SOFTVOLT_AI_BODYGUARD_VERSION . ' (self-check)', 'cookies' => array(), ) ); if ( is_wp_error( $res ) ) { return null; } return array( 'code' => (int) wp_remote_retrieve_response_code( $res ), 'body' => (string) wp_remote_retrieve_body( $res ) ); } /** * Whether the answer really is the file (not a soft "not found" page). */ public static function looks_like( $kind, $body ) { switch ( $kind ) { case 'config': return (bool) preg_match( '/DB_(?:NAME|PASSWORD|USER)|table_prefix/', $body ); case 'env': return (bool) preg_match( '/^\s*[A-Z][A-Z0-9_]{2,}\s*=/m', $body ) && false === stripos( $body, 'PHP \d/i', $body ); } return false; } private static function probe( array &$state, $path ) { if ( ! isset( self::PROBES[ $path ] ) ) { return; } $url = home_url( '/' . $path ); $r = self::fetch( $url ); if ( ! $r || 200 !== $r['code'] || ! self::looks_like( self::PROBES[ $path ], $r['body'] ) ) { return; } $kind = self::PROBES[ $path ]; $crit = in_array( $kind, array( 'config', 'env', 'sql', 'htpasswd' ), true ); $texts = array( 'config' => __( 'A copy of wp-config.php with your database password can be downloaded by anyone.', 'ai-guardwall' ), 'env' => __( 'An environment file with passwords or keys can be downloaded by anyone.', 'ai-guardwall' ), 'git' => __( 'The site\'s Git folder is public: the full source code and its history can be downloaded.', 'ai-guardwall' ), 'htpasswd' => __( 'A password file can be downloaded and cracked offline.', 'ai-guardwall' ), 'sql' => __( 'A database dump with every user and password hash can be downloaded by anyone.', 'ai-guardwall' ), 'zip' => __( 'A site backup archive can be downloaded by anyone.', 'ai-guardwall' ), 'log' => __( 'An error log with file paths and sometimes data from forms is public.', 'ai-guardwall' ), 'info' => __( 'A phpinfo() page shows the server\'s full configuration to anyone.', 'ai-guardwall' ), ); self::add( $state, 'exposed|' . $path, 'root', $path, sprintf( /* translators: %s: path */ __( 'Publicly downloadable: /%s', 'ai-guardwall' ), $path ), $crit ? 'critical' : 'high', 95, $texts[ $kind ] . ' ' . __( 'Delete it or move it out of the web root (by FTP or with the file manager in your hosting panel), then change any password it contained.', 'ai-guardwall' ), 'delete', array( 'url' => $url ) ); } private static function fpd( array &$state ) { $r = self::fetch( includes_url( 'rss-functions.php' ), 8192 ); if ( $r && preg_match( '/(?:Fatal error|Warning|Uncaught)[^<]{0,200}? in ?([A-Za-z]:[\\\\\/]|\/)[^<]{3,}\.php<\/b>? on line/i', $r['body'] ) ) { self::add( $state, 'fpd', 'config', 'wp-includes/rss-functions.php', __( 'PHP errors reveal the server path', 'ai-guardwall' ), 'medium', 80, __( 'Opening a WordPress file directly shows a PHP error with the full folder path of the site. Set display_errors = Off in your hosting panel\'s PHP settings, and WP_DEBUG_DISPLAY to false in wp-config.php.', 'ai-guardwall' ), 'manual_review', array() ); } } private static function uploads_listing( array &$state ) { $up = wp_upload_dir( null, false ); $r = self::fetch( trailingslashit( $up['baseurl'] ), 8192 ); if ( $r && 200 === $r['code'] && preg_match( '/Index of|Parent Directory/i', $r['body'] ) ) { self::add( $state, 'uploads_listing', 'upload', 'wp-content/uploads/', __( 'The uploads folder can be browsed', 'ai-guardwall' ), 'medium', 85, __( 'Anyone can list every file in the uploads folder, including private documents and backups that plugins put there. Switch "Disable directory browsing" on under Hardening.', 'ai-guardwall' ), 'fix_config', array( 'rule' => 'disable_directory_indexes' ) ); } } /* ---------------------------------- accounts ---------------------------------- */ private static function weak_password( array &$state, $user_id ) { $user = get_userdata( $user_id ); if ( ! $user || '' === (string) $user->user_pass ) { return; } $host = strtolower( (string) preg_replace( '/^www\./', '', (string) wp_parse_url( home_url(), PHP_URL_HOST ) ) ); $tries = array_merge( self::COMMON, array( $user->user_login, $user->user_login . '123', $user->user_login . '1', ucfirst( $user->user_login ) . '123', strtok( $host, '.' ), strtok( $host, '.' ) . '123', (string) get_option( 'blogname' ) ) ); foreach ( array_unique( array_filter( $tries, 'strlen' ) ) as $guess ) { if ( wp_check_password( $guess, $user->user_pass, $user->ID ) ) { self::add( $state, 'weak_password|' . $user->ID, 'user', 'user:' . $user->user_login, sprintf( /* translators: %s: user login */ __( 'Administrator "%s" uses a very common password', 'ai-guardwall' ), $user->user_login ), 'critical', 99, __( 'This password is on every attacker\'s first list; brute-force tools guess it within seconds. Change it now to a long, unique one (a password manager helps) and switch two-factor authentication on.', 'ai-guardwall' ), 'manual_review', array( 'user_id' => (int) $user->ID ) ); return; } } } private static function display_names( array &$state ) { $list = Softvolt_Ai_Bodyguard_Access::exposed_logins(); if ( ! $list ) { return; } self::add( $state, 'display_names', 'user', 'users', sprintf( /* translators: %d: number of list */ _n( '%d account shows its login name publicly', '%d accounts show their login names publicly', count( $list ), 'ai-guardwall' ), count( $list ) ), 'low', 70, sprintf( /* translators: %s: list of list */ __( 'The display name equals the login name for: %s. It appears on posts and in feeds, handing attackers half of the login. Fix it on Security Wall › Users & sessions.', 'ai-guardwall' ), implode( ', ', wp_list_pluck( $list, 'login' ) ) ), 'fix_config' ); } /* --------------------------------- reputation --------------------------------- */ private static function dnsbl( array &$state ) { $host = (string) wp_parse_url( home_url(), PHP_URL_HOST ); $ip = gethostbyname( $host ); if ( ! filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) ) { return; // Local or private address: block lists do not apply. } $rev = implode( '.', array_reverse( explode( '.', $ip ) ) ); $listed = array(); foreach ( array( 'zen.spamhaus.org', 'bl.spamcop.net', 'b.barracudacentral.org' ) as $zone ) { $a = gethostbyname( $rev . '.' . $zone ); // 127.0.0.x is a listing; 127.255.255.x means the list refused the query (public resolver). if ( 0 === strpos( $a, '127.0.0.' ) ) { $listed[] = $zone; } } if ( $listed ) { self::add( $state, 'dnsbl', 'config', $ip, __( 'The server\'s address is on a spam block list', 'ai-guardwall' ), 'high', 75, sprintf( /* translators: 1: IP address, 2: list of listed */ __( '%1$s is listed by %2$s. Mail from the site may be rejected, and listings often follow a hacked site sending spam. Clean the site, then ask for removal on the list\'s website (or ask your host if the address is shared).', 'ai-guardwall' ), $ip, implode( ', ', $listed ) ), 'manual_review' ); } } private static function safe_browsing( array &$state ) { $key = (string) Softvolt_Ai_Bodyguard_Settings::secret( 'gsb_key' ); if ( '' === $key ) { return; } $res = wp_remote_post( 'https://safebrowsing.googleapis.com/v4/threatMatches:find?key=' . rawurlencode( $key ), array( 'timeout' => 10, 'headers' => array( 'Content-Type' => 'application/json' ), 'body' => wp_json_encode( array( 'client' => array( 'clientId' => 'softvoltai-ai-bodyguard', 'clientVersion' => SOFTVOLT_AI_BODYGUARD_VERSION ), 'threatInfo' => array( 'threatTypes' => array( 'MALWARE', 'SOCIAL_ENGINEERING', 'UNWANTED_SOFTWARE', 'POTENTIALLY_HARMFUL_APPLICATION' ), 'platformTypes' => array( 'ANY_PLATFORM' ), 'threatEntryTypes' => array( 'URL' ), 'threatEntries' => array( array( 'url' => home_url( '/' ) ) ), ), ) ), ) ); if ( is_wp_error( $res ) || 200 !== (int) wp_remote_retrieve_response_code( $res ) ) { return; } $body = json_decode( (string) wp_remote_retrieve_body( $res ), true ); if ( ! empty( $body['matches'] ) ) { $types = array_unique( wp_list_pluck( (array) $body['matches'], 'threatType' ) ); self::add( $state, 'safe_browsing', 'config', home_url( '/' ), __( 'Google Safe Browsing flags this site', 'ai-guardwall' ), 'critical', 95, sprintf( /* translators: %s: list of types */ __( 'Google lists the site as %s: browsers show visitors a red warning page. Clean every finding, then request a review in Google Search Console › Security issues.', 'ai-guardwall' ), implode( ', ', $types ) ), 'manual_review' ); } } /* ---------------------------------- server ---------------------------------- */ private static function ssl( array &$state ) { if ( 'https' !== wp_parse_url( home_url(), PHP_URL_SCHEME ) ) { return; // The config scanner reports a site without HTTPS. } $s = Softvolt_Ai_Bodyguard_Monitor::ssl_check( false ); if ( empty( $s['expires'] ) ) { return; } $days = (int) floor( ( (int) $s['expires'] - time() ) / DAY_IN_SECONDS ); if ( $days < 0 ) { self::add( $state, 'ssl', 'config', (string) $s['host'], __( 'The SSL certificate has expired', 'ai-guardwall' ), 'critical', 95, sprintf( /* translators: %s: date */ __( 'The certificate expired on %s. Browsers block the site with a security warning. Renew it at your host now.', 'ai-guardwall' ), wp_date( 'Y-m-d', (int) $s['expires'] ) ), 'fix_config' ); } elseif ( $days < 14 ) { self::add( $state, 'ssl', 'config', (string) $s['host'], __( 'The SSL certificate expires soon', 'ai-guardwall' ), 'medium', 90, sprintf( /* translators: 1: days, 2: date */ _n( 'The certificate expires in %1$d day (%2$s). Check that automatic renewal works at your host.', 'The certificate expires in %1$d days (%2$s). Check that automatic renewal works at your host.', $days, 'ai-guardwall' ), $days, wp_date( 'Y-m-d', (int) $s['expires'] ) ), 'fix_config' ); } } private static function disk( array &$state ) { if ( ! function_exists( 'disk_free_space' ) ) { return; } $free = @disk_free_space( Softvolt_Ai_Bodyguard_Helpers::site_dir( '' ) ); $total = @disk_total_space( Softvolt_Ai_Bodyguard_Helpers::site_dir( '' ) ); if ( false === $free || ! $total ) { return; } if ( $free < 300 * MB_IN_BYTES || $free / $total < 0.03 ) { self::add( $state, 'disk', 'config', 'disk', __( 'The server is almost out of disk space', 'ai-guardwall' ), 'medium', 90, sprintf( /* translators: 1: size, 2: size */ __( 'Only %1$s of %2$s is free. A full disk stops updates, backups, uploads and logins (sessions cannot be written). Delete old backups or ask your host for more space.', 'ai-guardwall' ), size_format( $free, 1 ), size_format( $total, 1 ) ), 'manual_review' ); } } }