백엔드 개발 PHP 튜토리얼 用PHP伪造referer突破网盘禁止外连的代码_PHP教程

用PHP伪造referer突破网盘禁止外连的代码_PHP教程

Jul 21, 2016 pm 03:51 PM
http php referer 암호 위조 문서 사용 ~의 금지하다 돌파구 나노미터 넷디스크

比如我放纳米盘里的文件http://img.namipan.com/downfile/da333ee178bdad6531d1ec1540cf86277c116b6300887600/02.Paid%20In%20Full.mp3

这个地址不能直接下载也不能在网页播放器里播放,点击下载转到了一个下载页面。要想能够直接下载这个文件或播放这个文件,那就要伪造referfer,欺骗服务器,referfer是来自纳米盘的链接。

最开始使用的方法是用PHP内置的函数stream_context_create。

代码如下:

function referfile($url, $refer=”) {
$opt=array('http'=>array('header'=>”Referer: $refer”));
$context=stream_context_create( $opt);
return file_get_contents($url,false, $context);
}

但这段代码有个缺点,file_get_contents实际上是把对方服务器的文件读取到了自己的服务器上然后再发送给浏览器,不但加大自己服务器的压力,而且下载反应速度还很慢,这个并不是很好的解决方法。

后来又看了遍手册,既要减轻自己服务器的压力,又能达到迷惑对方服务器。修改header里的Referfer信息就可以了。

改版后的代码如下:
$url=”img.namipan.com/downfile/da333ee178bdad6531d1ec1540cf86277c116b6300887600/02.Paid%20In%20Full.mp3″;//这里的url要过滤掉http://
$urlarr=explode(”/”,$url);
$domain=$urlarr[0];//分解出域名
$getfile=str_replace($urlarr[0],”,$url);
$content = @fsockopen(”$domain”, 80, $errno, $errstr, 12);//先连接上对方的服务器
if (!$content){//无法链接就提示错误信息
die(”对不起,无法连接上 $domain 。”);
}
fputs($content, “GET $getfile HTTP/1.0\r\n”);
fputs($content, “Host: $domain\r\n”);
fputs($content, “Referer: $domain\r\n”);//伪造referfer
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);将头部信息读取出来,里面将包含:Location:http://xxx/xxx.mp3,我们要的就是这个地址。
}
$arr=explode(”\n”,$tp);
$arr1=explode(”Location: “,$tp);
$arr2=explode(”\n”,$arr1[1]);//分解出Location:后面的地址
header('Content-Type:application/force-download');
header(”location:”.$arr2[0]);
fclose($content);

OK,目的达到了。

这个原来的地址:http://img.namipan.com/downfile/3a7c64518d46d986283eab73175a8b119305a76480b89200/Equilibrium-Turis_Fratyr-02-Wingthors_Hammer.mp3

转换后:

http://mms.music.krmcn.com/mms.music/namipan/img~~/3a7c64518d46d986283eab73175a8b119305a76480b89200/Equilibrium-Turis_Fratyr-02-Wingthors_Hammer.mp3

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/319077.htmlTechArticle比如我放纳米盘里的文件http://img.namipan.com/downfile/da333ee178bdad6531d1ec1540cf86277c116b6300887600/02.Paid%20In%20Full.mp3 这个地址不能直接下载也不能在网...
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

뜨거운 기사 태그

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

Ubuntu 및 Debian용 PHP 8.4 설치 및 업그레이드 가이드 Ubuntu 및 Debian용 PHP 8.4 설치 및 업그레이드 가이드 Dec 24, 2024 pm 04:42 PM

Ubuntu 및 Debian용 PHP 8.4 설치 및 업그레이드 가이드

CakePHP 날짜 및 시간 CakePHP 날짜 및 시간 Sep 10, 2024 pm 05:27 PM

CakePHP 날짜 및 시간

CakePHP 프로젝트 구성 CakePHP 프로젝트 구성 Sep 10, 2024 pm 05:25 PM

CakePHP 프로젝트 구성

CakePHP 파일 업로드 CakePHP 파일 업로드 Sep 10, 2024 pm 05:27 PM

CakePHP 파일 업로드

CakePHP 라우팅 CakePHP 라우팅 Sep 10, 2024 pm 05:25 PM

CakePHP 라우팅

CakePHP 토론 CakePHP 토론 Sep 10, 2024 pm 05:28 PM

CakePHP 토론

CakePHP 빠른 가이드 CakePHP 빠른 가이드 Sep 10, 2024 pm 05:27 PM

CakePHP 빠른 가이드

PHP 개발을 위해 Visual Studio Code(VS Code)를 설정하는 방법 PHP 개발을 위해 Visual Studio Code(VS Code)를 설정하는 방법 Dec 20, 2024 am 11:31 AM

PHP 개발을 위해 Visual Studio Code(VS Code)를 설정하는 방법

See all articles