'/\bbase64_decode\s*\(/i', 'eval' => '/\beval\s*\(/i', 'assert' => '/\bassert\s*\(/i', 'gzinflate' => '/\bgzinflate\s*\(/i', 'gzuncompress' => '/\bgzuncompress\s*\(/i', 'str_rot13' => '/\bstr_rot13\s*\(/i', 'file_put_contents'=> '/\bfile_put_contents\s*\(/i', 'fopen' => '/\bfopen\s*\(/i', 'unlink' => '/\bunlink\s*\(/i', 'rename' => '/\brename\s*\(/i', 'copy' => '/\bcopy\s*\(/i', 'db_read' => '/\b(?:get_option|get_site_option|\$wpdb\s*->\s*(?:get_var|get_row|get_results|get_col))\b/i', 'direct_sql' => '/\$wpdb\s*->\s*(?:query|get_results|get_row|get_var)\s*\(/i', ); public function run() { $findings = array(); $content_dir = ACHWPA_Paths::content_dir(); $paths = ACHWPA_Paths::wp_config_candidates(); if ( '' !== $content_dir ) { $paths[] = $content_dir . '/object-cache.php'; $paths[] = $content_dir . '/advanced-cache.php'; $paths[] = $content_dir . '/db.php'; } foreach ( array_unique( $paths ) as $path ) { if ( ! is_file( $path ) || ! is_readable( $path ) ) { continue; } $content = ACHWPA_Preview::read_limited_file( $path ); if ( '' === $content ) { continue; } $hits = $this->collect_hits( $content ); $ioc_hits = ACHWPA_IOC::matches( $content . ' ' . basename( $path ) ); $identifiers = $this->extract_identifiers( $content ); $artifacts = $this->extract_artifacts( $content ); $write_hits = array_intersect( $hits, array( 'file_put_contents', 'fopen', 'unlink', 'rename', 'copy' ) ); $decode_hits = array_intersect( $hits, array( 'base64_decode', 'eval', 'assert', 'gzinflate', 'gzuncompress', 'str_rot13' ) ); $db_hits = array_intersect( $hits, array( 'db_read', 'direct_sql' ) ); if ( empty( $hits ) && empty( $ioc_hits ) ) { continue; } $level = 'Info'; $reason = __( 'Potentially sensitive functions or persistence-related indicators were observed. Their presence alone does not establish malicious behavior.', 'aiutocomputerhelp-persistence-audit' ); if ( ! empty( $write_hits ) && ! empty( $decode_hits ) ) { $level = 'Review'; $reason = __( 'The file combines code transformation or execution primitives with filesystem write operations. This combination deserves manual review.', 'aiutocomputerhelp-persistence-audit' ); } if ( ! empty( $write_hits ) && ! empty( $decode_hits ) && ! empty( $db_hits ) ) { $level = 'Warning'; $reason = __( 'The file combines database access, code transformation or execution primitives, and filesystem write operations. This pattern can be consistent with restore or reinfection logic and should be reviewed manually.', 'aiutocomputerhelp-persistence-audit' ); } if ( ! empty( $ioc_hits ) && 'Info' === $level ) { $level = 'Review'; $reason = __( 'A known persistence indicator was observed. It is treated as supporting evidence only and requires manual verification.', 'aiutocomputerhelp-persistence-audit' ); } $relative = $this->relative_path( $path ); $preview_needles = array_merge( $hits, $ioc_hits, $identifiers ); foreach ( $artifacts as $artifact ) { $artifact_value = preg_replace( '/^[A-Z]+:/', '', (string) $artifact ); if ( ! is_string( $artifact_value ) || '' === $artifact_value ) { continue; } if ( 0 === strcasecmp( $artifact_value, basename( $path ) ) || 0 === strcasecmp( $artifact_value, $relative ) ) { continue; } $preview_needles[] = $artifact_value; } $preview_needles = array_values( array_unique( array_filter( $preview_needles ) ) ); $preview = basename( $path ) === 'wp-config.php' ? ACHWPA_Preview::contextual( $content, $preview_needles, 1800, true ) : ACHWPA_Preview::sanitize( $content, 1800, false ); $findings[] = new ACHWPA_Finding( array( 'category' => 'Bootstrap', 'level' => $level, 'location' => $relative, 'indicator' => implode( ', ', array_merge( $hits, $ioc_hits ) ), 'explanation' => $reason, 'preview' => $preview, 'artifacts' => array_merge( array( 'FILE:' . basename( $path ), 'PATH:' . $relative ), $artifacts ), 'identifiers' => $identifiers, ) ); } return $findings; } private function collect_hits( $content ) { $hits = array(); foreach ( $this->patterns as $name => $pattern ) { if ( preg_match( $pattern, $content ) ) { $hits[] = $name; } } return $hits; } private function extract_identifiers( $content ) { $ids = array(); if ( preg_match_all( '/\b[a-f0-9]{6,32}\b/i', $content, $matches ) ) { foreach ( $matches[0] as $candidate ) { if ( ! ctype_digit( $candidate ) ) { $ids[] = strtolower( $candidate ); } } } return array_slice( array_values( array_unique( $ids ) ), 0, 40 ); } private function extract_artifacts( $content ) { $artifacts = array(); if ( preg_match_all( '/[A-Za-z0-9_.-]{3,}\.php\b/', $content, $matches ) ) { foreach ( $matches[0] as $file ) { $artifacts[] = 'FILE:' . basename( $file ); } } if ( preg_match_all( '/(?:_site_transient_|_transient_|wp_cache_|wp_compat_|_wp_)[A-Za-z0-9_.-]{3,}/i', $content, $matches ) ) { foreach ( $matches[0] as $option ) { $artifacts[] = 'OPTION:' . $option; } } return array_slice( array_values( array_unique( $artifacts ) ), 0, 60 ); } private function relative_path( $path ) { $normalized = wp_normalize_path( $path ); $root = trailingslashit( ACHWPA_Paths::wordpress_root() ); if ( 0 === strpos( $normalized, $root ) ) { return substr( $normalized, strlen( $root ) ); } return basename( $path ); } }