惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Privacy & Cybersecurity Law Blog
V
V2EX
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Register - Security
The Register - Security
MongoDB | Blog
MongoDB | Blog
P
Privacy International News Feed
The Last Watchdog
The Last Watchdog
Security Archives - TechRepublic
Security Archives - TechRepublic
美团技术团队
Stack Overflow Blog
Stack Overflow Blog
博客园 - 司徒正美
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
K
Kaspersky official blog
S
Secure Thoughts
T
Tenable Blog
Security Latest
Security Latest
The Cloudflare Blog
S
Security @ Cisco Blogs
H
Heimdal Security Blog
aimingoo的专栏
aimingoo的专栏
TaoSecurity Blog
TaoSecurity Blog
Blog — PlanetScale
Blog — PlanetScale
Microsoft Security Blog
Microsoft Security Blog
Schneier on Security
Schneier on Security
Webroot Blog
Webroot Blog
G
Google Developers Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Scott Helme
Scott Helme
IT之家
IT之家
Latest news
Latest news
The Hacker News
The Hacker News
C
Check Point Blog
T
The Exploit Database - CXSecurity.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
腾讯CDC
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
N
News | PayPal Newsroom
Forbes - Security
Forbes - Security
P
Palo Alto Networks Blog
S
Security Affairs
S
Securelist
Google Online Security Blog
Google Online Security Blog
WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
C
Cybersecurity and Infrastructure Security Agency CISA
A
About on SuperTechFans

龙辉's Blog - 敲代码

暂无文章

怎么突破图片防盗链? - 龙辉's Blog
博主: Tinker-站长 · 2024-03-18 · via 龙辉's Blog - 敲代码

很多时候网站想引用别人网站里的图片但别人设置了防盗链,我们想引用但又用不了,那怎么办呢?
其实很简单,破解防盗链最好的办法就是直接读取。做为一个phper(哈哈当然不是),当然是用php来突破了
用到php中一个常用的函数file_get_contents(图片地址),意思是读取远程的一张图片,在输出就完事。非常简单~话不多说,直接上代码

<?php
header("Content-type: image/jpeg");//防止输出乱码
$img=$_GET['img'];//通过get方法获取图片地址
echo file_get_contents($img);//角色上场

?>

使用方法:新建一个img.php文件,把代码贴进去。你的链接/img.php?img=图片链接
下面是我搭建好的,搭建可以直接使用:http://blog.eirds.cn/img.php?img=

再说说更变态的方法,接一下我演示一个判断请求来源的防盗链!!
这里就要用到PHP 中强大的curl,他可以伪造头部来源IP,来源地址,甚至可以使用proxy,PHP爬虫必备。
我们来简单分析一下吧。

demo 这是一个连接,点击A标签可以看到一张图片, demo1 ,但是我们直接打开这张图片是不行的,因为他判断了请求的链接。如果不是在那个链接打开的,就会返回404, demo3 ,再继续分析,我们看一下请求refer,! 9{8F[ATCT@(EASG_HA@IY`8.png 可以看到必须是refer这个地址才行。那么我们就只有欺骗他的服务器了。废话不多说,直接贴代码,这是我封装好的CURL

<?php  
    function Crack_img($url,$refer){  
    $ch = curl_init($url);  //设置图片url
    curl_setopt ($ch, CURLOPT_REFERER, $refer);  //伪造请求来源
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);  
    $data = curl_exec($ch);  
    curl_close($ch);  
      
    //$ext = strtolower(substr(strrchr($img,'.'),1,10));  
    //输出图片格式
    /*$types = array(  
                'gif'=>'image/gif',  
                'jpeg'=>'image/jpeg',  
                'jpg'=>'image/jpeg',  
                'jpe'=>'image/jpeg',  
                'png'=>'image/png',  
    );*/  
    //$type = $types[$ext] ? $types[$ext] : 'image/jpeg';  
    header("Content-type:image/jpeg");  //输出二进制流图片
    return $data;}
        $url = $_GET["url"];  
        $refer = $_GET['refer'];
        echo Crack_img($url,$refer);

使用方法:新建PHP文件,粘贴进去,命名.php?url=图片地址&refer=来源地址
这是我搭建好的,大家可以直接使用:blog.eirds.cn/image.php?url=图片地址&refer=来源地址

转载请注明来源,此文章为本博原创


版权属于:龙辉博客

本文链接:https://blog.eirds.cn/91.html

如果没有特别声明则为本博原创。转载时须注明出处及本声明!

赞赏作者

如果觉得我的文章对你有用,请随意赞赏