I have a code that lead the code become remote code execution. How this exploit go and how to run it? Also how to fix the code. I've tried many times but it won't succeed. Thanks!
This is the code:
<?php
error_reporting(E_WARNING | E_DEPRECATED);
require_once 'inc.php';
function getip(){
if(getenv('HTTP_X_FORWARDED_FOR')){
$ip = $_SERVER['REMOTE_ADDR'];
if(preg_match("/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/", getenv('HTTP_X_FORWARDED_FOR'), $ip3)){
$ip2 = array('/^0\./', '/^127\.0\.0\.1/', '/^192\.168\..*/', '/^172\.16\..*/', '/^10..*/', '/^176..*/', '/^206..*/');
$ip = preg_replace($ip2, $ip, $ip3[1]);
}
}else{
$ip = $_SERVER['REMOTE_ADDR'];
}
if($ip == ""){ $ip = "x.x.x.x"; }
return $ip;
}
$ipnya = getip();
$arrip = array("192.168.10.10","192.168.11.11");
if(!in_array($ipnya,$arrip)) {
header( "HTTP/1.1 301 Moved Permanently" );
header( "Status: 301 Moved Permanently" );
header( "Location: https://www.google.com" );
exit(0);
}
if(class_exists(PHPIDS_SUSPECTIP)) {
$susp_ip = new PHPIDS_SUSPECTIP;
if($susp_ip->__add())
echo "<br>";
$susp_list = json_decode($susp_ip->__read())->ip;
if(in_array($ipnya,$susp_list)) {
header( "Status: 404 Page Not Found",true,404 );
} else {
}
}
?>