I found many methods on the internet to use Curl to forge the client source IP address, almost all of which use the curl function. later I verified that this function is powerful, not only can the client source IP address be forged, but also
I found many methods on the internet to use Curl to forge the client source IP address, almost all of which use the curl function. later I verified that this function is powerful, not only can the client source IP address be forged, but also the proxy IP address be forged. let's look at the code.
Generally, the server can obtain the client IP address in three cases.
1. if no proxy is used:
# Http://www.phpfensi.com
REMOTE_ADDR = customer IP
HTTP_VIA = null
HTTP_X_FORWARDED_FOR = null
2. when the proxy is used and the proxy server has the IP address of the forwarding client configured:
REMOTE_ADDR = proxy server IP address
HTTP_VIA = proxy server IP address
HTTP_X_FORWARDED_FOR = customer IP
The HTTP_VIA and HTTP_X_FORWARDED_FOR values can be customized by adding the Header to hide the client IP, provided that X_FORWARDED_FOR is enabled on the server.
Test results: Create a PHP program on the server.
Example code 1: The code is as follows:
-
- $ Ch = curl_init ();
- Curl_setopt ($ ch, CURLOPT_URL, "http: // localhost/index. 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://www.phpfensi.com/"); // Construct a path
- Curl_setopt ($ ch, CURLOPT_HEADER, 1 );
- $ Out = curl_exec ($ ch );
- Curl_close ($ ch );
Example code 2: php code:
-
- Function getClientIp (){
- If (! Emptyempty ($ _ SERVER ["HTTP_CLIENT_IP"])
- $ Ip = $ _ SERVER ["HTTP_CLIENT_IP"];
- Else if (! Emptyempty ($ _ SERVER ["HTTP_X_FORWARDED_FOR"])
- $ Ip = $ _ SERVER ["HTTP_X_FORWARDED_FOR"];
- Else if (! Emptyempty ($ _ SERVER ["REMOTE_ADDR"])
- $ Ip = $ _ SERVER ["REMOTE_ADDR"];
- Else
- $ Ip = "err ";
- Return $ ip;
- }
- Echo "IP:". getClientIp ()."";
- Echo "referer:". $ _ SERVER ["HTTP_REFERER"];
- Echo "IP:". getClientIp ()."";
- Echo "referer:". $ _ SERVER ["HTTP_REFERER"];
Forged successfully. does this provide a good IP address change solution for the "fake ticket" friends? haha.
Result:
- HTTP/1.1 200 OK Date: Wed, 03 Apr 2013 06:20:42 GMT Server: Apache/2.2.22 (Win32) PHP/5.3.13
- X-Powered-By: PHP/5.3.13 Content-Length: 44 Content-Type: text/html
- IP: 8.8.8.8
Referer: http://www.phpfensi.com/
The following describes the curl function.
List of curl-related functions:
Curl_init-initialize a CURL session
Curl_setopt-set an option for CURL calls
Curl_exec-execute a CURL session
Curl_close-close a CURL session
Curl_version-returns the current CURL version
1> curl_init-initialize a CURL session