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

/ 191,933评论 / 537633阅读 / 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. NelsonSaIlk说道:

    best online pharmacies in mexico: mexico drug stores pharmacies – medicine in mexico pharmacies

  2. Arnoldscava说道:

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

  3. RichardMonge说道:

    https://mexicandeliverypharma.com/# purple pharmacy mexico price list

  4. RichardMonge说道:

    http://mexicandeliverypharma.com/# best online pharmacies in mexico

  5. Arnoldscava说道:

    mexican mail order pharmacies mexico drug stores pharmacies mexican pharmacy

  6. Waynetar说道:

    mexico pharmacies prescription drugs: purple pharmacy mexico price list – reputable mexican pharmacies online

  7. Arnoldscava说道:

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

  8. RichardMonge说道:

    https://mexicandeliverypharma.com/# mexico drug stores pharmacies

  9. DominicHOr说道:

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

  10. RichardMonge说道:

    https://mexicandeliverypharma.com/# medicine in mexico pharmacies

  11. Waynetar说道:

    medicine in mexico pharmacies: pharmacies in mexico that ship to usa – purple pharmacy mexico price list

  12. DominicHOr说道:

    mexican mail order pharmacies: purple pharmacy mexico price list – mexican rx online

  13. Arnoldscava说道:

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

  14. Waynetar说道:

    mexican rx online: mexican rx online – mexican drugstore online

  15. Arnoldscava说道:

    buying prescription drugs in mexico mexican pharmaceuticals online buying from online mexican pharmacy

  16. DominicHOr说道:

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

  17. DominicHOr说道:

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

  18. Arnoldscava说道:

    mexican pharmacy mexico pharmacies prescription drugs medication from mexico pharmacy

  19. RichardMonge说道:

    http://mexicandeliverypharma.com/# buying from online mexican pharmacy

  20. Waynetar说道:

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

  21. DominicHOr说道:

    purple pharmacy mexico price list: mexican online pharmacies prescription drugs – mexican pharmaceuticals online

  22. RichardMonge说道:

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

  23. веб студия разработка сайтов biztest.ru .

  24. Waynetar说道:

    mexico drug stores pharmacies: medication from mexico pharmacy – mexican pharmaceuticals online

  25. DominicHOr说道:

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

  26. Waynetar说道:

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

  27. DominicHOr说道:

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

  28. Arnoldscava说道:

    mexican pharmaceuticals online mexico drug stores pharmacies buying from online mexican pharmacy

  29. JamesLer说道:

    Discover Kyrie Irving’s https://mavericks-de-dallas.kyrie-irving-fr.com journey with the Dallas Mavericks, from his early days to forming a power duo with Luka Doncic and competing for a championship.

  30. Waynetar说道:

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

  31. DominicHOr说道:

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

  32. KevinFug说道:

    Mavericks rising superstar Luka Doncic https://mavericks-de-dallas.lukadoncic-fr.com continues to amaze the basketball world with his game.

  33. Waynetar说道:

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

  34. DominicHOr说道:

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

  35. ThomasHem说道:

    The story of Michael Phelps https://amerique.michael-phelps.com how he became the greatest swimmer of all time, overcoming adversity, setting records and inspiring the world.

  36. RonaldCoova说道:

    Learn about Jayson Tatum’s https://celtics-de-boston.jayson-tatum.com rise from young rookie to key leader of the Boston Celtics in the NBA, his impact on the team and his success on the court.

  37. Charlesfrott说道:

    The Boston Celtics https://celtics-de-boston.bill-russel.com are one of the most successful teams in the history of the National Basketball Association (NBA).

  38. RichardMonge说道:

    https://mexicandeliverypharma.com/# medicine in mexico pharmacies

  39. RichardMonge说道:

    https://mexicandeliverypharma.com/# buying from online mexican pharmacy

  40. Arnoldscava说道:

    medication from mexico pharmacy mexican rx online mexican online pharmacies prescription drugs

  41. Arnoldscava说道:

    mexican border pharmacies shipping to usa mexican mail order pharmacies medicine in mexico pharmacies

  42. DominicHOr说道:

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

  43. Arnoldscava说道:

    mexican drugstore online best online pharmacies in mexico medication from mexico pharmacy

  44. Arnoldscava说道:

    reputable mexican pharmacies online mexican rx online п»їbest mexican online pharmacies

  45. Waynetar说道:

    purple pharmacy mexico price list: mexican online pharmacies prescription drugs – mexican mail order pharmacies

  46. DominicHOr说道:

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

发表回复

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