search
Homephp教程php手册php伪造http头破解防盗链

防盗链

伪造referer实例代码,主要用于一些突破防盗链,比如图片,软件等。

这里就直接给出完整的程序吧,具体的应用可以自己修改。 
我这里给出的例子是很简单的,其实可以从这个例子中发展出很多的应用。比如隐藏真实的URL地址……嘿嘿,具体的就自己分析去吧 
这里新建一个文件file.php。后面的参数就是需要伪造referfer的目标地址吧。如:file.php/http://www.xxx.xxx/xxx.mp3 

代码: 
  1.    
  2. $url=str_replace('/file.php/','',$_SERVER["REQUEST_URI"]);//得出需要转换的网址。这里我就偷懒,不做安全检测了,需要的自己加上去   
  3. $downfile=str_replace(" ","%20",$url);//替换空格之类,可以根据实际情况进行替换   
  4. $downfile=str_replace("http://","",$downfile);//去掉http://   
  5. $urlarr=explode("/",$downfile);//以"/"分解出域名   
  6. $domain=$urlarr[0];//域名   
  7. $getfile=str_replace($urlarr[0],'',$downfile);//得出header中的GET部分   
  8. $content = @fsockopen("$domain", 80, $errno$errstr, 12);//连接目标主机   
  9. if (!$content){//链接不上就提示错误   
  10. die("对不起,无法连接上 $domain 。");   
  11. }   
  12. fputs($content"GET $getfile HTTP/1.0rn");   
  13. fputs($content"Host: $domainrn");   
  14. fputs($content"Referer: $domainrn");//伪造部分   
  15. fputs($content"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)rnrn");   
  16. while (!feof($content)) {   
  17. $tp.=fgets($content, 128);   
  18. if (strstr($tp,"200 OK")){ //这里要说明一下。header的第一行一般是请求文件的状态。具体请参照HTTP 1.1状态代码及其含义 hi.baidu.com/110911/blog/item/21f20d2475af812ed50742c5.html这里是正常的文件请求状态,只需直接转向就可以。其他状态的继续执行程序   
  19. header("Location:$url");   
  20. die();   
  21. }   
  22. }   
  23. //302 转向,大部分的防盗链系统都是先判断referfer,对了的话再转向真实的地址。下面就是获取真实的地址。   
  24. $arr=explode("n",$tp);   
  25. $arr1=explode("Location: ",$tp);//分解出Location后面的真时地址   
  26. $arr2=explode("n",$arr1[1]);   
  27. header('Content-Type:application/force-download');//强制下载   
  28. header("location:".$arr2[0]);//转向目标地址   
  29. die();   
  30. ?>   

以上代码只能针对使用referer来判断是否盗链的防盗链系统,使用其他特殊方法防盗链的,则不适用。

  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: Close\r\n\r\n";   
  24.   
  25.   
  26. fwrite($fp$out);   
  27. while(!feof($fp)){   
  28. echo fgets($fp, 1024);   
  29. }   
  30. fclose($fp);   
  31. }   
  32. ?>   
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.