Define false user browser information HTTP_USER_AGENT
The code is as follows: |
Copy code |
$ Binfo = array ('mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0 ;. net clr 2.0.50727; InfoPath.2; AskTbPTV/5.17.0.25589; Alexa Toolbar) ', 'mozilla/5.0 (Windows NT 5.1; rv: 22.0) Gecko/20100101 Firefox/123456 ', 'mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0 ;. NET4.0C; Alexa Toolbar) ', 'mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)', $ _ SERVER ['http _ USER_AGENT ']); // 123.125.68 .* // 125.90.88 .* |
Define the source segment of the forged IP address. Here I am looking for the IP address of Baidu
The code is as follows: |
Copy code |
$ Cip = '1970. 123. 68. '. mt_rand (125 ); $ Xip = '1970. 90. 88. '. mt_rand (125 ); $ Header = array ( 'Client-IP: '. $ cip, 'X-FORWARDED-FOR: '. $ xip, ); |
Use curl to start sending forged information to the server
The code is as follows: |
Copy code |
Function getimgs ($ url, $ userinfo, $ header) { $ Ch = curl_init (); $ Timeout = 5; Curl_setopt ($ ch, CURLOPT_URL, "$ url "); Curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ header ); Curl_setopt ($ ch, CURLOPT_REFERER, "http://www.baidu.com /"); Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 ); Curl_setopt ($ ch, CURLOPT_USERAGENT, "$ userinfo "); Curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, $ timeout ); $ Contents = curl_exec ($ ch ); Curl_close ($ ch ); Return $ contents; } |
We can save the obtained data.
The code is as follows: |
Copy code |
Function saveimgs ($ handle) { $ Fp = fopen('a.jpg ', "w "); Fwrite ($ fp, $ handle ); Unset ($ fp ); Unset ($ handle ); } |
Test counterfeit IP Instances
The code is as follows: |
Copy code |
$ Url = 'yun _ qi_img/logo.jpg '; $ U = $ binfo [mt_rand (0, 3)]; Saveimgs (getimgs ($ url, $ u, $ header )); |
In this case, you have saved a.jpg file in your current directory. Can I check whether the server log is our custom user information?
192.168.1.108--[22/Jul/2013: 10: 29: 37 + 0800] "GET/test. php HTTP/1.1 "200 1244"-"" Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0 ;. net clr 2.0.50727; InfoPath.2; AskTbPTV/5.17.0.25589; Alexa Toolbar )"
192.168.1.108--[22/Jul/2013: 10: 29: 37 + 0800] "GET/HTTP/1.1" 200 40538 "http://www.baidu.com/" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0 ;. NET4.0C; Alexa Toolbar )"
192.168.1.108--[22/Jul/2013: 10: 29: 37 + 0800] "GET/test. php HTTP/1.1 "200 1244"-"" Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0 ;. net clr 2.0.50727; InfoPath.2; AskTbPTV/5.17.0.25589; Alexa Toolbar )"
192.168.1.108--[22/Jul/2013: 10: 29: 37 + 0800] "GET/HTTP/1.1" 200 40538 "http://www.baidu.com/" "Mozilla/5.0 (Windows NT 5.1; rv: 22.0) Gecko/20100101 Firefox/22.0"
I can see it. It's completely correct, but I didn't test the IP address. When I use php to obtain the IP address, it will show that I forged the IP address.