[nginx/openresty]代理请求修改referer,破解防盗链

/ 191,944评论 / 537821阅读 / 17点赞

有时我们想引用其他网站的资源(图片,视频等),明明在其网站上可用,而我们发送请求时却得到了403错误,访问被拒绝,很可能就是该网站对这些资源文件设置了防盗链,下面我们聊聊其防盗的原理以及破解方法。

名词

防盗链

Referer

Origin

破解防盗链

直接伪造请求

这个方法适用于客户端,而不适用于浏览器中的网页。

const axios = require(`axios`);
const getServer = (in_url, in_data, successFun, errFun) => {
    axios({
        method: "get",
        url:    in_url,
        params: in_data,
        headers: {
            "referer":"https://www.bilibili.com/"

            //"referer":"https://127.0.0.1/"  //你可以尝试使用这一句替换上面那句,请求将被拒绝
        }
    }).then(function (res) {
        console.log(res.data);
        if (typeof (successFun) != 'undefined') {
            successFun(res);
        }
        console.log("--- 请求成功 ---");
    }).catch(function (err) {
        console.log(err);
        if (typeof (errFun) != 'undefined') {
            errFun(err);
        }
        console.log("--- 请求失败 ---");
    })
}

//获取对应id的视频的下载链接
getServer(
    "https://api.bilibili.com/x/player/playurl",
    {
        "fnval": 80,
        "bvid":"BV1pT41157it",
        "cid":"746904707"
    });

代理转发

客户端,网页都适用,但一般客户端不需要由服务器代理,客户端自己可以搞定,就不需要占用服务器的带宽性能

server {
        listen       80;
        server_name  localhost, 127.0.0.1;
	resolver 8.8.8.8;
        location / {
		header_filter_by_lua_file /usr/local/openresty/lua/toBili.lua;
                proxy_set_header referer 'https://www.bilibili.com/';
		proxy_set_header Host $proxy_host;
		proxy_set_header Origin 'https://www.bilibili.com';
		if ($query_string ~* ^(.*)url=(.*)$) {
			proxy_pass $2;
		}
	}
}
ngx.header['Access-Control-Allow-Origin']  =  '*';
ngx.header['Access-Control-Allow-Methods'] = 'get, post, options';
ngx.header['Access-Control-Allow-Headers'] = 'dnt,x-mx-reqtoken,keep-alive,user-agent,x-requested-with,if-modified-since,cache-control,content-type,authorization';

关于空referer

<!DOCTYPE html>
<html lang="zh">
<head>

    <meta name="referrer" content="never">
</head>
<body>
</body>

摸索过程记录

add_header Access-Control-Allow-Origin '*';
add_header Access-Control-Allow-Methods 'POST,OPTIONS,GET';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';

思考

上面的示例中,我们在使用时,只能也必须传入一个参数 url,那有没有办法传递更多参数呢?

  1. ThomasInace说道:

    https://doxycyclinedelivery.pro/# rx doxycycline 100mg

  2. ThomasInace说道:

    https://amoxildelivery.pro/# amoxicillin generic

  3. ThomasInace说道:

    https://doxycyclinedelivery.pro/# buy doxycycline hyclate 100mg without a rx

  4. Jamesjer说道:

    doxycycline 100mg for sale: doxycycline 75 mg – best price for doxycycline

  5. ThomasInace说道:

    https://paxloviddelivery.pro/# Paxlovid over the counter

  6. Jamesjer说道:

    buy amoxicillin 500mg: where can i buy amoxicillin without prec – where can i buy amoxicillin without prec

  7. Jamesjer说道:

    cipro online no prescription in the usa: ciprofloxacin – buy cipro

  8. Jeffreyquime说道:

    Manny Pacquiao https://filipino-boxer.manny-pacquiao-ar.com is one of the most prominent boxers in the history of the sport.

  9. HerbertSed说道:

    Muhammad Ali https://american-boxer.muhammad-ali-ar.com is perhaps one of the most famous and greatest athletes in the history of boxing.

  10. Keithdoure说道:

    Mike Tyson https://american-boxer.mike-tyson-ar.com one of the most famous and influential boxers in history, was born on June 30, 1966 in Brooklyn, New York.

  11. Jamesjer说道:

    buy doxycycline tablets 100mg: doxycycline brand name in india – doxycycline cap tab 100mg

  12. Jamesjer说道:

    paxlovid buy: paxlovid buy – Paxlovid over the counter

  13. ThomasInace说道:

    http://doxycyclinedelivery.pro/# doxycycline 1000 mg best buy

  14. Jamesjer说道:

    ciprofloxacin order online: cipro online no prescription in the usa – ciprofloxacin 500 mg tablet price

  15. ThomasInace说道:

    http://clomiddelivery.pro/# where can i buy clomid without insurance

  16. Jamesjer说道:

    paxlovid generic: paxlovid pill – Paxlovid over the counter

  17. Jamesjer说道:

    buy cipro without rx: buy ciprofloxacin over the counter – buy cipro online

  18. ThomasInace说道:

    https://ciprodelivery.pro/# buy ciprofloxacin over the counter

  19. Jamesjer说道:

    where can i buy amoxicillin over the counter uk: amoxicillin 500mg price canada – amoxicillin 500 capsule

  20. BryanScath说道:

    Michael Jordan https://chicago-bulls.michael-jordan-ar.com is one of the greatest basketball players of all time, whose career with the Chicago Bulls is legendary.

  21. Jamesjer说道:

    cipro ciprofloxacin: cipro for sale – buy cipro online usa

  22. Stevennup说道:

    стили дизайнов интерьера фото дизайн интерьера сайт

  23. Edwinimale说道:

    The Formula One World Championship https://world-circuit-racing-championship.formula-1-ar.com, known as the Formula Championship in motor racing, is the highest tier of professional motor racing.

  24. ChrisWap说道:

    After some difficult years in the late 2010s, Manchester United https://england.manchester-united-ar.com returned to greatness in English football by 2024.

  25. ThomasInace说道:

    https://amoxildelivery.pro/# buy amoxicillin over the counter uk

  26. ThomasInace说道:

    http://clomiddelivery.pro/# can i order generic clomid now

  27. ThomasInace说道:

    https://amoxildelivery.pro/# buy cheap amoxicillin

  28. ThomasInace说道:

    https://ciprodelivery.pro/# buy generic ciprofloxacin

  29. Robertphits说道:

    Jennifer Lopez https://lets-get-loud.jenniferlopez-ar.com was born in 1969 in the Bronx, New York, to parents who were Puerto Rican immigrants.

  30. ThomasInace说道:

    https://amoxildelivery.pro/# amoxicillin 500 tablet

  31. ThomasInace说道:

    https://clomiddelivery.pro/# order cheap clomid without a prescription

  32. ThomasInace说道:

    https://ciprodelivery.pro/# ciprofloxacin mail online

  33. бесплатное лучшее порно без рекламы http://best-free-porno.ru .

  34. Jamesjer说道:

    ciprofloxacin over the counter: buy ciprofloxacin over the counter – purchase cipro

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注