Php uses curl to forge IP source code
- $ 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;
- ?>
Target file of the request --- target_ip.php:
- Echo getenv ('http _ CLIENT_IP ');
- Echo getenv ('http _ X_FORWARDED_FOR ');
- Echo getenv ('remote _ ADDR ');
- ?>
The IP address printing sequence in the target file target_ip is the IP address acquisition sequence of many open source systems to access fake_ip.php. The result is: 58.68.44.6158.68.44.61127.0.0.1.
Finally, we provide two small examples. Example 1:
- $ 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'); // Construct an IP address
- Curl_setopt ($ ch, CURLOPT_REFERER, "http://bbs.it-home.org/"); // Construct a path
- Curl_setopt ($ ch, CURLOPT_HEADER, 1 );
- $ Out = curl_exec ($ ch );
- Curl_close ($ ch );
- ?>
Example 2:
- 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"];
- ?>
|