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

/ 183,227评论 / 462168阅读 / 15点赞

有时我们想引用其他网站的资源(图片,视频等),明明在其网站上可用,而我们发送请求时却得到了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. Williamwhomb说道:

    indian pharmacy online indian pharmacies safe п»їlegitimate online pharmacies india

  2. Edwardintig说道:

    https://certifiedcanadapharm.store/# ed meds online canada

  3. iptv fiyatlar说道:

    I’m extremely impressed with your writing skills as neatly as with the structure in your weblog.

    Is that this a paid subject matter or did you customize it your self?

    Anyway keep up the nice quality writing, it is uncommon to see a nice blog like
    this one today..

  4. AlbertFlouh说道:

    reputable indian pharmacies: best india pharmacy – pharmacy website india

  5. It is appropriate time to make some plans
    for the future and it is time to be happy. I have read this post
    and if I could I desire to suggest you some interesting things or suggestions.
    Maybe you can write next articles referring to this article.
    I wish to read even more things about it!

  6. Freddypoope说道:

    mexican drugstore online: mexican mail order pharmacies – mexican online pharmacies prescription drugs

  7. Edwardintig说道:

    https://indiamedicine.world/# india online pharmacy

  8. bandarqq说道:

    selamat pagi unbtuk рara bapak ibu saaudara
    saudara kini mauu aku tampilkan web judi pkv terburuk
    yang pernah ada web judi poker qq dengan rating tak memuaskan hanya mengelabui orrang orang saja.
    situs yaang telah lama hadir menyediakan permainan qq online yang banyak peminat tetapi tertipu oleh situs pkv ini.
    situs judi pkv yang tiak pantas untik dibvuat tempat
    bermain ρara pejudi online, apabilaa anda berkeinginan bermain pikir pikikr dulu
    karena mereka cuma bisa mengcopy ⅽontent saja.

    salam sejahtera

    Μy web site: bandarqq

  9. Edwardintig说道:

    https://certifiedcanadapharm.store/# reputable canadian pharmacy

  10. Freddypoope说道:

    buy medicines online in india: reputable indian pharmacies – buy prescription drugs from india

  11. Edwardintig说道:

    https://certifiedcanadapharm.store/# best rated canadian pharmacy

  12. Freddypoope说道:

    mexican border pharmacies shipping to usa: mexican rx online – buying from online mexican pharmacy

  13. work from home说道:

    I always spent my half an hour to read this webpage’s articles or reviews daily along
    with a mug of coffee.

  14. M1124193说道:

    I’m truly enjoying the design and layout of your website.
    It’s a very easy on the eyes which makes it much
    more pleasant for me to come here and visit more often. Did you hire out a developer
    to create your theme? Great work!

  15. AlbertFlouh说道:

    canadian pharmacy reviews: global pharmacy canada – canada online pharmacy

  16. Edwardintig说道:

    https://mexpharmacy.sbs/# mexican online pharmacies prescription drugs

  17. Edwardintig说道:

    https://indiamedicine.world/# Online medicine order

  18. duenty说道:

    how i can write an essay la homework help write an essay on my school picnic

  19. Freddypoope说道:

    canadian pharmacy online ship to usa: canadianpharmacy com – onlinecanadianpharmacy

  20. AlbertFlouh说道:

    reputable canadian pharmacy: canadian pharmacies comparison – canadian pharmacy 24h com

  21. AlbertFlouh说道:

    medication from mexico pharmacy: medication from mexico pharmacy – best online pharmacies in mexico

  22. Williamwhomb说道:

    Online medicine home delivery indianpharmacy com top 10 pharmacies in india

  23. Williamwhomb说道:

    reputable mexican pharmacies online buying prescription drugs in mexico online reputable mexican pharmacies online

  24. Freddypoope说道:

    canadian pharmacy ratings: onlinepharmaciescanada com – canadian world pharmacy

  25. Freddypoope说道:

    п»їlegitimate online pharmacies india: online shopping pharmacy india – indian pharmacy

  26. AlbertFlouh说道:

    reputable indian pharmacies: indian pharmacy – best india pharmacy

  27. Williamwhomb说道:

    vipps canadian pharmacy my canadian pharmacy reviews best canadian online pharmacy

  28. AlbertFlouh说道:

    indian pharmacies safe: top online pharmacy india – online shopping pharmacy india

发表回复

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