防盗链
伪造referer实例代码,主要用于一些突破防盗链,比如图片,软件等。
这里就直接给出完整的程序吧,具体的应用可以自己修改。
我这里给出的例子是很简单的,其实可以从这个例子中发展出很多的应用。比如隐藏真实的URL地址……嘿嘿,具体的就自己分析去吧
这里新建一个文件file.php。后面的参数就是需要伪造referfer的目标地址吧。如:file.php/http://www.xxx.xxx/xxx.mp3
代码:
-
- $url=str_replace('/file.php/','',$_SERVER["REQUEST_URI"]);
- $downfile=str_replace(" ","%20",$url);
- $downfile=str_replace("http://","",$downfile);//去掉http://
- $urlarr=explode("/",$downfile);
- $domain=$urlarr[0];
- $getfile=str_replace($urlarr[0],'',$downfile);
- $content = @fsockopen("$domain", 80, $errno, $errstr, 12);
- if (!$content){
- die("对不起,无法连接上 $domain 。");
- }
- fputs($content, "GET $getfile HTTP/1.0rn");
- fputs($content, "Host: $domainrn");
- fputs($content, "Referer: $domainrn");
- fputs($content, "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)rnrn");
- while (!feof($content)) {
- $tp.=fgets($content, 128);
- if (strstr($tp,"200 OK")){
- header("Location:$url");
- die();
- }
- }
-
- $arr=explode("n",$tp);
- $arr1=explode("Location: ",$tp);
- $arr2=explode("n",$arr1[1]);
- header('Content-Type:application/force-download');
- header("location:".$arr2[0]);
- die();
- ?>
以上代码只能针对使用referer来判断是否盗链的防盗链系统,使用其他特殊方法防盗链的,则不适用。
- $txt=$_GET['url'];
- echo referfile($txt,'http://www.jbxue.com/');
-
-
- function referfile($url,$refer='') {
- $opt=array('http'=>array('header'=>"Referer:$refer"));
- $context=stream_context_create($opt);
- Header("Location:".$url);
- return file_get_contents($url,false,$context);
- }
-
- $host = "pakey.net";
- $target = "/test.asp";
- $referer = "http//uuwar.com/"; //伪造来路页面
- $fp = fsockopen($host, 80, $errno, $errstr, 30);
- if(!$fp){
- echo "$errstr($errno)
\n";
- }else{
- $out = "
- GET $target HTTP/1.1
- Host: $host
- Referer: $referer
- Connection: Close\r\n\r\n";
-
-
- fwrite($fp, $out);
- while(!feof($fp)){
- echo fgets($fp, 1024);
- }
- fclose($fp);
- }
- ?>
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