吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3985|回复: 7
收起左侧

[其他转载] 图片防盗链破解 解决图片防盗链问题 反向代{过}{滤}理

  [复制链接]
yuupuu 发表于 2020-1-15 11:26
本帖最后由 yuupuu 于 2020-1-15 11:30 编辑

很多小伙伴的博客,网站都是用图床来实现的,那么现在很多稳定的图床接口都被做了防盗链处理,例如百度、阿里、京东、小米、搜狗等。所以我们应该怎么避开防盗链直接使用图片呢?

1 防盗的原理是什么?
当客户端(浏览器)向服务器请求内容的时候,会提交一个header,这个header中包含了如:浏览器信息、cookie等内容,那么有一个叫referer的东东,也包含在这里面。referer是干啥用的呢?它就是告诉服务器,这个请求的来源是谁,比如:从页面A跳转到页面B,那么页面B收到的referer就是页面A。但是在图片身上和这个有点不同,图片是在html页面加载完毕后才加载的,所以图片收到的referer不是网页的上一个页面,而是当前页面。说这么多,不要被说绕了,简单点就是:对于图片而言,收到的referer就是引用图片的这个网页的网址。那么现在的很多网站是如何利用referer来进行防图片盗链的呢?三种情况下允许引用图片:

1、本网站。
2、无referer信息的情况。(服务器认为是从浏览器直接访问的图片URL,所以这种情况下能正常访问)
3、白名单网址

开始做防盗链处理


[PHP] 纯文本查看 复制代码
<?php
 class ImgBridge{
    private $water='';
    private $imgUrl=''; 
    private $referer='';
    private $ua='MQQBrowser/26 Mozilla/5.0 (Linux; U; Android 2.3.7; zh-cn; MB200 Build/GRJ22; CyanogenMod-7) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1';
    private $imgCode='';
    private $imgHeader='';
    private $imgBody='';
    private $imgType='';

    public function \_\_construct($config=array()){
        foreach($config as $key=>$value){
            $this->$key=$value;
        }
    }
    
    public function getImg($imgUrl){
        $this->imgUrl=$imgUrl;
        /\*\* 处理url \*/
        if(substr($this->imgUrl,0,7)!=='http://' && substr($this->imgUrl,0,8)!=='https://'){
            $this->imgUrl='http://'.$this->imgUrl;
        }
        /\*\* 解析url中的host \*/
        $url\_array=parse\_url($this->imgUrl);
        /\*\* 设置referer \*/
        $this->referer=$this->referer==""?'http://'.$url\_array\['host'\]:$this->referer;
        /\*\*开始获取 \*/
        $this->urlOpen();
        $this->imgBody;
        /\*\*处理错误 \*/
        if($this->imgCode!=200){
            $this->error(1);
            exit();
        }
        
        /\*\*获取图片格式 \*/
        preg\_match("/Content-Type: image\\/(.+?)\\n/sim",$this->imgHeader,$result);
        /\*\*看看是不是图片 \*/
        if(!isset($result\[1\])){
            $this->error(2);
            exit();
        }else{
            $this->imgType=$result\[1\];
        }
        /\*\* 输出内容 \*/
        $this->out();        
    }
    private function out(){
        /\*\* gif 不处理,直接出图 \*/
        if($this->imgType=='gif'){
            header("Content-Type: image/gif");
            echo $this->imgBody;
            exit();
        }
        header("Content-Type: image/png");
        /\*\* 其他类型的,加水印 \*/
        $im=imagecreatefromstring($this->imgBody);
        $white = imagecolorallocate($im, 255, 255, 255);
        /\*加上水印\*/
        if($this->water){
            imagettftext($im, 12, 0, 20, 20, $white, "/fonts/hwxh.ttf", $this->water);            
        }
        imagepng($im);
        
    }
    private function error($err){
        header("Content-Type: image/jpeg");
        $im=imagecreatefromstring(file\_get\_contents('./default.jpg'));
        imagejpeg($im);
    }

    private function urlOpen()
    {
        $ch = curl\_init();
        curl\_setopt($ch, CURLOPT\_URL, $this->imgUrl);
        curl\_setopt($ch, CURLOPT\_USERAGENT, $this->ua);
        curl\_setopt ($ch,CURLOPT\_REFERER,$this->referer);
        curl\_setopt($ch, CURLOPT\_RETURNTRANSFER, 1);
        curl\_setopt($ch, CURLOPT\_HEADER, 1);
        /\*\*跳转也要 \*/
        curl\_setopt($ch, CURLOPT\_FOLLOWLOCATION, true);
        /\*\*  支持https \*/
        $opt\[CURLOPT\_SSL\_VERIFYHOST\] = 2;
        $opt\[CURLOPT\_SSL\_VERIFYPEER\] = FALSE;
        curl\_setopt\_array($ch, $opt);
        $response = curl\_exec($ch);
        $this->imgCode=curl\_getinfo($ch, CURLINFO\_HTTP\_CODE) ;
        if ($this->imgCode == '200') {
            $headerSize = curl\_getinfo($ch, CURLINFO\_HEADER\_SIZE);
            $this->imgHeader = substr($response, 0, $headerSize);
            $this->imgBody = substr($response, $headerSize);
            return ;
        }
        curl\_close($ch);
    }

 }

 $img=new ImgBridge(array('water'=>''));
 $img->getImg(strstr($\_SERVER\["QUERY\_STRING"\], "http"));



代码命名为dl.php
那么直接可以访问
http://域名/dl.php?url=


案例


我用135编辑器上传一张图片,获得图片地址


https://image.135editor.com/files/users/740/7407329/201912/zTeFAx8R_Cmea.jpg


加上反向代{过}{滤}理,破解防盗链处理


http://域名/dl.php?url=https://image.135editor.com/files/users/740/7407329/201912/zTeFAx8R_Cmea.jpg


HTML格式

[HTML] 纯文本查看 复制代码
<img src="http://域名/dl.php?url=https://image.135editor.com/files/users/740/7407329/201912/zTeFAx8R_Cmea.jpg"/>


然后就可以正常使用了!

免费评分

参与人数 1吾爱币 +3 热心值 +1 收起 理由
苏紫方璇 + 3 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

indian806 发表于 2020-1-15 13:33
找不到,请指教下
http://699pic.com/dl.php?url=http://seopic.699pic.com/photo/50024/9588.jpg_wh1200.jpg
头像被屏蔽
袁煜914 发表于 2020-1-15 11:37
xxjj999 发表于 2020-1-15 11:42
天空の幻像 发表于 2020-1-15 12:05
牛逼。。。这也可以破解啊
wangyujie96 发表于 2020-1-15 12:32
curl?服务器转发?服务器流量不要钱吗?这样还不如就用服务器搭图床,省一半流量
213141 发表于 2020-3-26 15:19
貌似不行,貌似,可能是我这边技术问题
smallhaoao 发表于 2021-3-1 20:48
本帖最后由 smallhaoao 于 2021-3-3 12:56 编辑

楼主,这种带token的怎么破解?


  https://某域名.某域名.com/177e96db2172aee13fd2f31a.png?e=1614529079&token=GKsToXq5swcvg2UEuDxm8woANva0kMxY1WQ3e9Y8:u9ocv1_eX5I6w88cg8eqONggxvc=   


如上
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-8 00:05

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表