Home >Backend Development >PHP Tutorial >PHP uses curl to forge IP source code

PHP uses curl to forge IP source code

WBOY
WBOYOriginal
2016-07-25 09:03:31803browse
  1. $ch = curl_init();
  2. $url = "http://localhost/target_ip.php";
  3. $header = array(
  4. 'CLIENT-IP:58.68.44.61',
  5. ' ;
  6. $page_content = curl_exec($ch);
  7. curl_close($ch);
  8. echo $page_content;
  9. ?>
  10. Copy code
Requested target file ---target_ip.php:

echo getenv('HTTP_CLIENT_IP');
    echo getenv('HTTP_X_FORWARDED_FOR');
  1. echo getenv('REMOTE_ADDR');
  2. ?>
  3. Copy code
Goal The IP printing order in the file target_ip is the current IP acquisition order of many open source systems. Visit fake_ip.php and see the results: 58.68.44.61 58.68.44.61 127.0.0.1 Finally, I’ll provide you with two small examples. example 1:

$ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://localhost/2.php");
  1. curl_setopt($ch, CURLOPT_HTTPHEADER, array(' X-FORWARDED-FOR:8.8.8.8', 'CLIENT-IP:8.8.8.8')); //Construct IP
  2. curl_setopt($ch, CURLOPT_REFERER, "http://bbs.it-home.org/ ") ; //Construction source
  3. curl_setopt($ch, CURLOPT_HEADER, 1);
  4. $out = curl_exec($ch);
  5. curl_close($ch);
  6. ?>
  7. Copy code
Example 2:

function getClientIp() {
    if (!empty($_SERVER["HTTP_CLIENT_IP"]))
  1. $ip = $_SERVER["HTTP_CLIENT_IP"];
  2. else if (!empty( $_SERVER["HTTP_X_FORWARDED_FOR"]))
  3. $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
  4. else if (!empty($_SERVER["REMOTE_ADDR"]))
  5. $ip = $_SERVER["REMOTE_ADDR"];
  6. else
  7. $ip = "err";
  8. return $ip;
  9. }
  10. echo "IP: " . getClientIp() . "";
  11. echo "referer: " . $_SERVER["HTTP_REFERER"];
  12. ?>
  13. Copy code
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn