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

/ 184,378评论 / 468947阅读 / 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. RandallGuesE说道:

    buying propecia without prescription: buy generic propecia no prescription – buy cheap propecia without insurance

  2. RandallGuesE说道:

    buy cytotec pills: cytotec buy online usa – order cytotec online

  3. RandallGuesE说道:

    tamoxifen mechanism of action: tamoxifen and grapefruit – how does tamoxifen work

  4. RonaldSwobe说道:

    http://ciprofloxacin.tech/# cipro 500mg best prices

  5. Davidfrify说道:

    cytotec pills buy online buy cytotec online buy cytotec online fast delivery

  6. RandallGuesE说道:

    nolvadex online: tamoxifen breast cancer – tamoxifen chemo

  7. Free sex说道:

    He is good at eating pickles and telling women about his emotional problems.

  8. WilliamRen说道:

    http://ciprofloxacin.tech/# buy cipro online without prescription

  9. RandallGuesE说道:

    Misoprostol 200 mg buy online: buy cytotec online – cytotec abortion pill

  10. Davidfrify说道:

    ciprofloxacin 500 mg tablet price buy cipro online ciprofloxacin over the counter

  11. WilliamRen说道:

    http://nolvadex.life/# tamoxifen medication

  12. WilliamRen说道:

    https://finasteride.store/# how cЙ‘n i get cheap propecia pills

  13. Davidfrify说道:

    buy ciprofloxacin ciprofloxacin 500 mg tablet price ciprofloxacin

  14. RandallGuesE说道:

    ciprofloxacin order online: ciprofloxacin generic – cipro

  15. It’s going to be finish of mine day, but before finish I am reading this fantastic post
    to increase my know-how.

  16. Davidfrify说道:

    lisinopril 10 mg tabs zestoretic coupon ordering lisinopril without a prescription uk

  17. WilliamRen说道:

    http://lisinopril.network/# lisinopril 50 mg

  18. Davidfrify说道:

    propecia sale cost generic propecia price order propecia

  19. WilliamRen说道:

    http://nolvadex.life/# does tamoxifen make you tired

  20. Davidfrify说道:

    lisinopril 102 discount zestril prinivil lisinopril

  21. RandallGuesE说道:

    buy generic ciprofloxacin: cipro pharmacy – buy cipro online without prescription

  22. RandallGuesE说道:

    lisinopril pill 40 mg: lisinopril tabs 20mg – lisinopril 1.25

  23. RandallGuesE说道:

    benefits of tamoxifen: tamoxifen rash pictures – nolvadex generic

  24. Davidfrify说道:

    buy cytotec buy misoprostol over the counter buy cytotec pills

  25. It’s going to be end of mine day, but before
    finish I am reading this great article to increase
    my experience.

  26. RandallGuesE说道:

    ciprofloxacin generic: ciprofloxacin generic – purchase cipro

  27. Davidfrify说道:

    cipro ciprofloxacin ciprofloxacin 500mg buy online buy cipro online without prescription

  28. WilliamRen说道:

    http://ciprofloxacin.tech/# ciprofloxacin generic price

  29. Davidfrify说道:

    zestril no prescription buy cheap lisinopril 40 mg no prescription lisinopril 40 mg for sale

  30. RandallGuesE说道:

    buy cytotec: buy cytotec online fast delivery – order cytotec online

  31. WilliamRen说道:

    https://nolvadex.life/# nolvadex for sale

  32. WilliamRen说道:

    https://ciprofloxacin.tech/# ciprofloxacin order online

  33. RonaldSwobe说道:

    http://nolvadex.life/# tamoxifen premenopausal

  34. RandallGuesE说道:

    tamoxifen hot flashes: how to prevent hair loss while on tamoxifen – how does tamoxifen work

发表回复

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