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

/ 191,960评论 / 538004阅读 / 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. Arnoldscava说道:

    purple pharmacy mexico price list mexico pharmacies prescription drugs mexican drugstore online

  2. Waynetar说道:

    buying prescription drugs in mexico online: mexican rx online – mexican pharmaceuticals online

  3. DominicHOr说道:

    mexico drug stores pharmacies: mexican pharmaceuticals online – mexico pharmacies prescription drugs

  4. DominicHOr说道:

    purple pharmacy mexico price list: mexican pharmaceuticals online – mexico drug stores pharmacies

  5. Arnoldscava说道:

    mexico drug stores pharmacies mexican pharmacy reputable mexican pharmacies online

  6. My relatives every time say that I am wasting my time here
    at net, however I know I am getting familiarity everyday by reading
    thes nice content.

  7. NelsonSaIlk说道:

    medicine in mexico pharmacies: mexican pharmaceuticals online – mexico drug stores pharmacies

  8. Waynetar说道:

    mexican drugstore online: mexican rx online – medication from mexico pharmacy

  9. DominicHOr说道:

    mexican mail order pharmacies: п»їbest mexican online pharmacies – mexican pharmaceuticals online

  10. NelsonSaIlk说道:

    best online pharmacies in mexico: mexico drug stores pharmacies – purple pharmacy mexico price list

  11. Waynetar说道:

    medicine in mexico pharmacies: mexican rx online – mexican rx online

  12. DominicHOr说道:

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

  13. Waynetar说道:

    buying from online mexican pharmacy: medication from mexico pharmacy – buying prescription drugs in mexico

  14. Arnoldscava说道:

    pharmacies in mexico that ship to usa mexican online pharmacies prescription drugs reputable mexican pharmacies online

  15. NelsonSaIlk说道:

    best online pharmacies in mexico: reputable mexican pharmacies online – buying prescription drugs in mexico

  16. DominicHOr说道:

    buying prescription drugs in mexico: п»їbest mexican online pharmacies – mexican border pharmacies shipping to usa

  17. NelsonSaIlk说道:

    pharmacies in mexico that ship to usa: mexico pharmacies prescription drugs – medicine in mexico pharmacies

  18. Waynetar说道:

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

  19. NelsonSaIlk说道:

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

  20. Waynetar说道:

    medication from mexico pharmacy: reputable mexican pharmacies online – purple pharmacy mexico price list

  21. NelsonSaIlk说道:

    mexican pharmaceuticals online: mexican rx online – п»їbest mexican online pharmacies

  22. Waynetar说道:

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

  23. DominicHOr说道:

    buying prescription drugs in mexico online: mexican border pharmacies shipping to usa – mexico drug stores pharmacies

  24. DominicHOr说道:

    п»їbest mexican online pharmacies: mexican rx online – buying from online mexican pharmacy

  25. NelsonSaIlk说道:

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

  26. NelsonSaIlk说道:

    pharmacies in mexico that ship to usa: mexican mail order pharmacies – purple pharmacy mexico price list

  27. Arnoldscava说道:

    purple pharmacy mexico price list mexican rx online pharmacies in mexico that ship to usa

  28. NelsonSaIlk说道:

    mexican border pharmacies shipping to usa: purple pharmacy mexico price list – buying prescription drugs in mexico online

  29. NelsonSaIlk说道:

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

  30. NelsonSaIlk说道:

    mexico drug stores pharmacies: mexico pharmacies prescription drugs – mexican mail order pharmacies

  31. Arnoldscava说道:

    purple pharmacy mexico price list mexican pharmaceuticals online medication from mexico pharmacy

  32. Arnoldscava说道:

    reputable mexican pharmacies online mexico drug stores pharmacies mexican border pharmacies shipping to usa

  33. Waynetar说道:

    purple pharmacy mexico price list: mexico pharmacies prescription drugs – buying prescription drugs in mexico

  34. DominicHOr说道:

    п»їbest mexican online pharmacies: п»їbest mexican online pharmacies – mexican border pharmacies shipping to usa

  35. idviking说道:

    Greetings from Carolina! I’m bored to tears at work so I decided to check out your blog on my
    iphone during lunch break. I love the knowledge you present here and
    can’t wait to take a look when I get home. I’m shocked at
    how quick your blog loaded on my cell phone .. I’m not even using WIFI,
    just 3G .. Anyhow, wonderful site!

  36. Waynetar说道:

    buying prescription drugs in mexico online: mexican rx online – best online pharmacies in mexico

  37. Arnoldscava说道:

    reputable mexican pharmacies online medicine in mexico pharmacies mexico drug stores pharmacies

  38. DominicHOr说道:

    buying prescription drugs in mexico online: mexican pharmaceuticals online – pharmacies in mexico that ship to usa

  39. Arnoldscava说道:

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

  40. DominicHOr说道:

    mexican drugstore online: reputable mexican pharmacies online – buying from online mexican pharmacy

  41. Arnoldscava说道:

    purple pharmacy mexico price list buying prescription drugs in mexico online mexico pharmacies prescription drugs

  42. Waynetar说道:

    buying from online mexican pharmacy: mexican online pharmacies prescription drugs – mexican mail order pharmacies

  43. NelsonSaIlk说道:

    buying from online mexican pharmacy: mexican rx online – mexico drug stores pharmacies

  44. Waynetar说道:

    mexico pharmacies prescription drugs: buying from online mexican pharmacy – reputable mexican pharmacies online

  45. DominicHOr说道:

    buying from online mexican pharmacy: purple pharmacy mexico price list – mexican pharmaceuticals online

  46. Waynetar说道:

    medicine in mexico pharmacies: medication from mexico pharmacy – purple pharmacy mexico price list

  47. NelsonSaIlk说道:

    п»їbest mexican online pharmacies: best online pharmacies in mexico – mexico drug stores pharmacies

  48. DominicHOr说道:

    medicine in mexico pharmacies: buying prescription drugs in mexico – pharmacies in mexico that ship to usa

  49. Waynetar说道:

    mexican online pharmacies prescription drugs: reputable mexican pharmacies online – mexican border pharmacies shipping to usa

发表回复

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