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

推荐订阅源

V
Vulnerabilities – Threatpost
F
Fortinet All Blogs
Vercel News
Vercel News
C
Check Point Blog
P
Privacy International News Feed
Know Your Adversary
Know Your Adversary
Google DeepMind News
Google DeepMind News
T
Troy Hunt's Blog
TaoSecurity Blog
TaoSecurity Blog
I
Intezer
T
The Exploit Database - CXSecurity.com
Security Archives - TechRepublic
Security Archives - TechRepublic
H
Hacker News: Front Page
P
Proofpoint News Feed
GbyAI
GbyAI
Engineering at Meta
Engineering at Meta
Attack and Defense Labs
Attack and Defense Labs
S
Security @ Cisco Blogs
IT之家
IT之家
D
DataBreaches.Net
Hacker News: Ask HN
Hacker News: Ask HN
SecWiki News
SecWiki News
Y
Y Combinator Blog
Project Zero
Project Zero
H
Hackread – Cybersecurity News, Data Breaches, AI and More
L
Lohrmann on Cybersecurity
T
Tenable Blog
大猫的无限游戏
大猫的无限游戏
L
LINUX DO - 最新话题
G
Google Developers Blog
The GitHub Blog
The GitHub Blog
Recorded Future
Recorded Future
有赞技术团队
有赞技术团队
Martin Fowler
Martin Fowler
K
Kaspersky official blog
PCI Perspectives
PCI Perspectives
A
Arctic Wolf
Latest news
Latest news
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
N
Netflix TechBlog - Medium
雷峰网
雷峰网
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Google Online Security Blog
Google Online Security Blog
P
Palo Alto Networks Blog
The Hacker News
The Hacker News
WordPress大学
WordPress大学
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
月光博客
月光博客
Schneier on Security
Schneier on Security
M
MIT News - Artificial intelligence

龙辉's Blog - 敲代码

对学某通的登录逆向分析 - 龙辉's Blog 蓝桥杯省赛Web题解及知识点复习 - 龙辉's Blog win10系统下可以上网但是提示没有网络的问题 - 龙辉's Blog Bilibili自动签到之使用教程 - 龙辉's Blog PHP采集工具之Querylist - 龙辉's Blog AirBook-自响应式引导页 - 龙辉's Blog qq内打开被拦截链接 - 龙辉's Blog 查询别人qq空间访客记录! - 龙辉'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

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

赞赏作者

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