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

/ 183,214评论 / 462119阅读 / 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. Freddypoope说道:

    buying prescription drugs in mexico: п»їbest mexican online pharmacies – mexican pharmaceuticals online

  2. Freddypoope说道:

    is canadian pharmacy legit: canadian pharmacy store – canadian mail order pharmacy

  3. Edwardintig说道:

    http://mexpharmacy.sbs/# buying prescription drugs in mexico

  4. Robertorind说道:

    https://certifiedcanadapharm.store/# certified canadian international pharmacy

  5. Freddypoope说道:

    canadian pharmacy world: online canadian pharmacy – pharmacy in canada

  6. Edwardintig说道:

    https://mexpharmacy.sbs/# buying prescription drugs in mexico online

  7. Williamwhomb说道:

    online canadian pharmacy canadian pharmacy 365 trustworthy canadian pharmacy

  8. Inague说道:

    how to write a strong essay for college homework help discord how to write a claim statement for an essay

  9. AlbertFlouh说道:

    medicine in mexico pharmacies: mexican rx online – mexican border pharmacies shipping to usa

  10. It’s nearly impossible to find experienced people in this particular subject,
    but you seem like you know what you’re talking about! Thanks

  11. Freddypoope说道:

    pharmacies in canada that ship to the us: canadian medications – legitimate canadian pharmacy

  12. Edwardintig说道:

    https://certifiedcanadapharm.store/# maple leaf pharmacy in canada

  13. Edwardintig说道:

    https://mexpharmacy.sbs/# п»їbest mexican online pharmacies

  14. Phillipcak说道:

    Hi! treatments for ed beneficial web page.

  15. AlbertFlouh说道:

    canada drugs: canadian pharmacy prices – canadian pharmacy online

  16. Freddypoope说道:

    mexico drug stores pharmacies: mexican border pharmacies shipping to usa – medication from mexico pharmacy

  17. AlbertFlouh说道:

    mexico drug stores pharmacies: mexican drugstore online – mexican border pharmacies shipping to usa

  18. AlbertFlouh说道:

    canada drugs: online canadian pharmacy – canadian pharmacy service

  19. website说道:

    Hello there, just became alert to your blog through Google, and found that it is really informative.
    I’m going to watch out for brussels. I will be grateful if you
    continue this in future. Numerous people will be benefited from your writing.
    Cheers!

  20. Edwardintig说道:

    http://certifiedcanadapharm.store/# canadian pharmacy near me

  21. Freddypoope说道:

    medication from mexico pharmacy: best online pharmacies in mexico – buying prescription drugs in mexico online

  22. AlbertFlouh说道:

    canadian king pharmacy: global pharmacy canada – canada rx pharmacy world

  23. Phillipcak说道:

    Hi! natural ed medications very good web page.

  24. iptv fiyatlar说道:

    Link exchange is nothing else but it is just placing the other
    person’s website link on your page at suitable place and other person will also do
    similar in support of you.

  25. Freddypoope说道:

    mexico pharmacies prescription drugs: п»їbest mexican online pharmacies – reputable mexican pharmacies online

  26. Depo 25 bonus 25说道:

    Hi, Neat post. There is a problem with your website in web explorer, could
    test this? IE nonetheless is the market leader and a big element of other folks will miss your wonderful writing because of
    this problem.

  27. Robertorind说道:

    https://mexpharmacy.sbs/# п»їbest mexican online pharmacies

发表回复

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