This commit is contained in:
Javier Casares 2026-07-09 06:20:06 +00:00
commit 31f7e97d39

View file

@ -1342,8 +1342,8 @@ function wpvulnerability_detect_php() {
// Second method: use system commands if the first fails and shell_exec is available.
if ( empty( $version ) && wpvulnerability_can_shell_exec() ) {
// Command to check PHP version.
$version_output = shell_exec( escapeshellcmd( 'php -v' ) ); // phpcs:ignore
// Command to check PHP version (routed through the safe wrapper for validation + audit logging).
$version_output = wpvulnerability_safe_shell_exec( 'php', 'php -v' );
if ( ! empty( $version_output ) && preg_match( '/PHP\s+(\d+\.\d+(?:\.\d+)?(?:-\d+)?)/i', $version_output, $matches ) ) {
$version = $matches[1];
@ -1377,8 +1377,8 @@ function wpvulnerability_detect_curl() {
// Second method: use system commands if the first fails and shell_exec is available.
if ( empty( $version ) && wpvulnerability_can_shell_exec() ) {
// Command to check cURL version.
$version_output = shell_exec( escapeshellcmd( 'curl --version' ) ); // phpcs:ignore
// Command to check cURL version (routed through the safe wrapper for validation + audit logging).
$version_output = wpvulnerability_safe_shell_exec( 'curl', 'curl --version' );
if ( ! empty( $version_output ) && preg_match( '/curl\s+(\d+\.\d+(?:\.\d+)?(?:-\d+)?)/i', $version_output, $matches ) ) {
$version = $matches[1];
@ -1642,10 +1642,10 @@ function wpvulnerability_detect_webserver() {
// If the version is not detected, try to get it from the OS.
if ( empty( $webserver['version'] ) && wpvulnerability_can_shell_exec() ) {
if ( 'apache' === $webserver['id'] ) {
$apache_version = shell_exec( escapeshellcmd( 'apache2 -v 2>&1' ) ); // phpcs:ignore
if ( 'apache' === $webserver['id'] && wpvulnerability_analyze_filter( 'apache' ) ) {
$apache_version = wpvulnerability_safe_shell_exec( 'apache', 'apache2 -v' );
if ( empty( $apache_version ) ) {
$apache_version = shell_exec( escapeshellcmd( 'httpd -v 2>&1' ) ); // phpcs:ignore
$apache_version = wpvulnerability_safe_shell_exec( 'apache', 'httpd -v' );
}
if ( ! empty( $apache_version ) && preg_match( '/Apache\/([\d.]+)/', $apache_version, $version_matches ) ) {
$webserver['version'] = $version_matches[1];
@ -1654,8 +1654,8 @@ function wpvulnerability_detect_webserver() {
$webserver['version'] = preg_replace( '/-(\d+)$/', '.' . $suffix_matches[1], $webserver['version'] );
}
}
} elseif ( 'nginx' === $webserver['id'] ) {
$nginx_version = shell_exec( escapeshellcmd( 'nginx -v 2>&1' ) ); // phpcs:ignore
} elseif ( 'nginx' === $webserver['id'] && wpvulnerability_analyze_filter( 'nginx' ) ) {
$nginx_version = wpvulnerability_safe_shell_exec( 'nginx', 'nginx -v' );
if ( ! empty( $nginx_version ) && preg_match( '/nginx\/([\d.]+)/', $nginx_version, $version_matches ) ) {
$webserver['version'] = $version_matches[1];
// Replace "-N" at the end with ".N" if present.
@ -1663,7 +1663,7 @@ function wpvulnerability_detect_webserver() {
$webserver['version'] = preg_replace( '/-(\d+)$/', '.' . $suffix_matches[1], $webserver['version'] );
}
} else {
$angie_version = shell_exec( escapeshellcmd( 'angie -v 2>&1' ) ); // phpcs:ignore
$angie_version = wpvulnerability_safe_shell_exec( 'nginx', 'angie -v' );
if ( ! empty( $angie_version ) && preg_match( '/angie\/([\d.]+)/', $angie_version, $version_matches ) ) {
$webserver['version'] = $version_matches[1];
// Replace "-N" at the end with ".N" if present.
@ -2613,6 +2613,7 @@ function wpvulnerability_validate_shell_command( $command ) {
'httpd',
'nginx',
'angie',
'caddy',
'php',
'curl',
);
@ -2621,14 +2622,8 @@ function wpvulnerability_validate_shell_command( $command ) {
$parts = explode( ' ', $command );
$base_command = $parts[0];
// Check if base command is in whitelist.
$command_allowed = false;
foreach ( $allowed_commands as $allowed ) {
if ( false !== stripos( $base_command, $allowed ) ) {
$command_allowed = true;
break;
}
}
// Check if the base command is in the allowlist (exact match, not substring).
$command_allowed = in_array( strtolower( $base_command ), $allowed_commands, true );
if ( ! $command_allowed ) {
wpvulnerability_maybe_log(