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

推荐订阅源

S
Secure Thoughts
罗磊的独立博客
T
The Blog of Author Tim Ferriss
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
Last Week in AI
Last Week in AI
美团技术团队
Google Online Security Blog
Google Online Security Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
D
Docker
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
月光博客
月光博客
L
LINUX DO - 最新话题
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
W
WeLiveSecurity
H
Heimdal Security Blog
Vercel News
Vercel News
SecWiki News
SecWiki News
Forbes - Security
Forbes - Security
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
TaoSecurity Blog
TaoSecurity Blog
T
Troy Hunt's Blog
A
About on SuperTechFans
C
Check Point Blog
S
Security Affairs
Hacker News - Newest:
Hacker News - Newest: "LLM"
AI
AI
WordPress大学
WordPress大学
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Help Net Security
Help Net Security
博客园_首页
The Last Watchdog
The Last Watchdog
S
SegmentFault 最新的问题
Hugging Face - Blog
Hugging Face - Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Engineering at Meta
Engineering at Meta
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
I
Intezer
K
Kaspersky official blog
M
MIT News - Artificial intelligence
J
Java Code Geeks
G
GRAHAM CLULEY
P
Palo Alto Networks Blog

龙辉'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

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

赞赏作者

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