Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kharissulistiyo/fa49dfde0e207aba9a3d133721df5999 to your computer and use it in GitHub Desktop.
Save kharissulistiyo/fa49dfde0e207aba9a3d133721df5999 to your computer and use it in GitHub Desktop.
Bad PHP code sample: Remote Code Execution (RCE) vulnerability
<?php
if( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'scupdates' ) {
if( isset( $_POST[ 'wp_cache_location' ] ) && $_POST[ 'wp_cache_location' ] != '' ) {
$dir = realpath( trailingslashit( dirname( $_POST[ 'wp_cache_location' ] ) ) );
if ( $dir == false ) {
$dir = WP_CONTENT_DIR . '/cache/';
} else {
$dir = trailingslashit( $dir ) . trailingslashit(wpsc_deep_replace( array( '..', '\\' ), basename( $_POST[ 'wp_cache_location' ] ) ) );
}
$new_cache_path = $dir;
} else {
$new_cache_path = WP_CONTENT_DIR . '/cache/';
}
if ( $new_cache_path != $cache_path ) {
if ( file_exists( $new_cache_path ) == false )
rename( $cache_path, $new_cache_path );
$cache_path = $new_cache_path;
wp_cache_replace_line('^ *\$cache_path', "\$cache_path = '" . $cache_path . "';", $wp_cache_config_file);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment