search
Homephp教程php手册PHP伪造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);//得出header中的GET部分
$content = @fsockopen("$domain", 80, $errno, $errstr, 12);//连接目标主机
if (!$content){//链接不上就提示错误
die("对不起,无法连接上 $domain 。");
} www.jbxue.com
fputs($content, "GET $getfile HTTP/1.0\r\n");
fputs($content, "Host: $domain\r\n");
fputs($content, "Referer: $domain\r\n");//伪造部分
fputs($content, "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n\r\n");

while (!feof($content)) {
$tp.=fgets($content, 128);
if (strstr($tp,"200 OK")){ //这里要说明一下。header的第一行一般是请求文件的状态。具体请参照HTTP 1.1状态代码及其含义 hi.baidu.com/110911/blog/item/21f20d2475af812ed50742c5.html这里是正常的文件请求状态,只需直接转向就可以。其他状态的继续执行程序

header("Location:$url");
die();
}
}

//302 转向,大部分的防盗链系统都是先判断referfer,对了的话再转向真实的地址。下面就是获取真实的地址。
$arr=explode("\n",$tp);
$arr1=explode("Location: ",$tp);//分解出Location后面的真时地址
$arr2=explode("\n",$arr1[1]);
header('Content-Type:application/force-download');//强制下载
header("location:".$arr2[0]);//转向目标地址
die();
?>

此程序只能针对使用referer来判断是否盗链的防盗链系统,使用其他特殊方法防盗链的,这个估计就不适用了。

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

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

Atom editor mac version download

Atom editor mac version download

The most popular open source editor