Home  >  Article  >  Backend Development  >  Crack anti-hotlink code by forging http headers under PHP_PHP Tutorial

Crack anti-hotlink code by forging http headers under PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:36:351187browse

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

The complete program will be given directly here. The specific application can be modified by yourself.
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. For example: file.php/http://www.xxx.xxx/xxx.mp3

Copy code The code is as follows:

$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 whatever I need
$downfile=str_replace(" ","%20",$url);//Replace spaces and the like, you can replace them according to the actual situation
$downfile=str_replace("http://","",$downfile);//Remove http://
$urlarr=explode("/",$downfile);//Replace with "/" Decompose the domain name
$domain=$urlarr[0];//Domain name
$getfile=str_replace($urlarr[0],'',$downfile);//Get the GET part in the header
$content = @fsockopen("$domain", 80, $errno, $errstr, 12);//Connect to the target host
if (!$content){//If the link cannot be connected, an error will be prompted
die ("Sorry, unable to connect to $domain.");
}
fputs($content, "GET $getfile HTTP/1.0rn");
fputs($content, "Host: $domainrn" );
fputs($content, "Referer: $domainrn");//Fake part
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")){ //here To explain. 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
header("Location:$url");
die();
}
}
//302 redirection, most anti-hotlink systems are Determine the referrer first, and then switch to the real address if it is correct. The following is to obtain the real address.
$arr=explode("n",$tp);
$arr1=explode("Location: ",$tp);//Decompose the real-time address after Location
$arr2=explode ("n",$arr1[1]);
header('Content-Type:application/force-download');//Force download
header("location:".$arr2[0]) ;//Redirect to the target address
die();
?>



This program can only be used to prevent hotlinking by using referer to determine whether it is a hotlink. For systems that use other special methods to prevent hotlinking, this estimate is not applicable
Copy code The code is as follows:

$txt =$_GET['url'];
echo referfile($txt,'http://www.jb51.net/');

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);
}

Copy code The code is as follows:

$host = "pakey.net"; //The domain name you want to visit
$target = "/test.asp" ; //The address of the page you want to visit
$referer = "http//uuwar.com/"; //Fake source page
$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: Closernrn";

fwrite($fp, $out);
while(!feof( $fp)){
echo fgets($fp, 1024);
}
fclose($fp);
}
?>

It’s the code I used in my novel The Thief to crack Yunxuange’s txt e-book anti-theft link.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/322103.htmlTechArticleFake referer example code, mainly used for some breakthroughs in anti-leeching, such as pictures, software, etc., are given directly here It’s a complete program, you can modify it yourself for specific applications. Here I give...
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