php curl forges instance code from IP source

  • 2020-05-26 07:57:35
  • OfStack

curl requested file fake_ip.php:
code

 
<?php 
$ch = curl_init(); 
$url = "http://localhost/target_ip.php"; 
$header = array( 
'CLIENT-IP:58.68.44.61', 
'X-FORWARDED-FOR:58.68.44.61', 
); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); 
$page_content = curl_exec($ch); 
curl_close($ch); 
echo $page_content; 
?> 

Requested target file target_ip.php:
 
<?php 
echo getenv('HTTP_CLIENT_IP'); 
echo getenv('HTTP_X_FORWARDED_FOR'); 
echo getenv('REMOTE_ADDR'); 
?> 

The IP print order in target_ip is the IP fetch order in many open source systems today
Visit fake_ip.php and see the results:
58.68.44.61
58.68.44.61
127.0.0.1
The instance
CURL is really tough and can fake IP and its source.
1.php request 2.php.

1. php code:

 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "http://localhost/2.php"); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:8.8.8.8', 'CLIENT-IP:8.8.8.8')); // structure IP 
curl_setopt($ch, CURLOPT_REFERER, "https://www.ofstack.com/ "); // Tectonic background  
curl_setopt($ch, CURLOPT_HEADER, 1); 
$out = curl_exec($ch); 
curl_close($ch); 


2.php code is as follows:

 
function getClientIp() { 
if (!empty($_SERVER["HTTP_CLIENT_IP"])) 
$ip = $_SERVER["HTTP_CLIENT_IP"]; 
else if (!empty($_SERVER["HTTP_X_FORWARDED_FOR"])) 
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"]; 
else if (!empty($_SERVER["REMOTE_ADDR"])) 
$ip = $_SERVER["REMOTE_ADDR"]; 
else 
$ip = "err"; 
return $ip; 
} 
echo "IP: " . getClientIp() . ""; 
echo "referer: " . $_SERVER["HTTP_REFERER"]; 

Faked successfully, this is not for the "brush" friends to provide a good exchange IP scheme


Related articles: