Home > Backend Development > PHP Tutorial > PHP forges http header to crack anti-hotlink_PHP tutorial

PHP forges http header to crack anti-hotlink_PHP tutorial

WBOY
Release: 2016-07-13 10:35:35
Original
937 people have browsed it

Anti-hotlinking

Forged referer instance code is mainly used to break through anti-leeching, such as pictures, software, etc.

The complete program will be given directly here. You can modify it yourself for specific applications.
The example I give here is very simple. In fact, many applications can be developed from this example. For example, hiding the real URL address... Hehe, just analyze it yourself
Create a new file file.php here. The following parameter is the target address of the referfer that needs to be forged. Such as: file.php/http://www.xxx.xxx/xxx.mp3

Code:
  1. $url=str_replace('/file.php/','',$_SERVER["REQUEST_URI"]); //Get the URL that needs to be converted. I'm being lazy here and don't do security checks. I'll add what I need if necessary
  2. $downfile=str_replace(" ", "%20",$url);//Replace spaces and the like, you can replace them according to the actual situation
  3. $downfile=str_replace("http://" ,"",$downfile);//Remove http:// 
  4. $urlarr=explode("/",$downfile);//Use "/" to decompose the domain name
  5. $domain=$urlarr[0];//Domain name
  6. $getfile=str_replace($urlarr[0], '',$downfile);//Get the GET part in the header
  7. $content = @fsockopen("$domain", 80, $errno, $errstr, 12);//Connect to the target host
  8. if (!$content){//If the link cannot be reached, an error will be prompted
  9. die("Sorry, unable to connect to $domain ."); 
  10. fputs($content, "GET $getfile HTTP/1.0rn" );
  11. fputs($content, "Host: $domainrn" );
  12. fputs($content, "Referer: $domainrn" );//Forged part
  13. fputs($content, "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)rnrn");
  14. while (!feof($content)) { 
  15. $tp.=fgets($content, 128) ; 
  16. if (strstr($tp,"200 OK")){ //Some explanation here. The first line of the header is generally the status of the requested file. For details, please refer to HTTP 1.1 status codes and their meanings hi.baidu.com/110911/blog/item/21f20d2475af812ed50742c5.html This is the normal file request status, just redirect it directly.Continue executing the program in other states
  17. header("Location:$url");
  18. die();
  19. //302 redirection, most anti-hotlink systems first determine the referfer, and then redirect to the real address if it is correct. The following is to obtain the real address.
  20. $arr=explode("n",$tp);
  21. $arr1=explode("Location: ",$tp);//Decompose the real-time address behind Location
  22. $arr2=explode("n",$arr1[1]);
  23. header('Content-Type:application/force-download');//Force download
  24. header("location:".$arr2[0]);//Direction Destination address
  25. die();
  26. ?>

The above code can only be used for the anti-hotlinking system that uses referer to determine whether it is hotlinked. It is not applicable to the anti-hotlinking system that uses other special methods to prevent hotlinking.

  1. $txt=$_GET['url'];   
  2. echo referfile($txt,'http://www.jbxue.com/');   
  3.   
  4.   
  5. function referfile($url,$refer='') {   
  6. $opt=array('http'=>array('header'=>"Referer:$refer"));   
  7. $context=stream_context_create($opt);   
  8. Header("Location:".$url);   
  9. return file_get_contents($url,false,$context);   
  10. }   
  11.    
  12. $host = "pakey.net"//你要访问的域名   
  13. $target = "/test.asp"//你要访问的页面地址   
  14. $referer = "http//uuwar.com/"; //伪造来路页面   
  15. $fp = fsockopen($host, 80, $errno$errstr, 30);   
  16. if(!$fp){   
  17. echo "$errstr($errno)n";   
  18. }else{   
  19. $out = "   
  20. GET $target HTTP/1.1   
  21. Host: $host   
  22. Referer: $referer   
  23. Connection: Closernrn";   
  24.   
  25.   
  26. fwrite($fp$out);   
  27. while(!feof($fp)){   
  28. echo fgets($fp, 1024);   
  29. }   
  30. fclose($fp);   
  31. }   
  32. ?>   

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/743818.htmlTechArticleAnti-hotlink forgery referer example code, mainly used for some breakthroughs in anti-hotlinking, such as pictures, software, etc. The complete program will be given directly here. You can modify it yourself for specific applications. ...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template