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

/ 191,955评论 / 537940阅读 / 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说道:

    mexican pharmaceuticals online mexican mail order pharmacies mexico pharmacies prescription drugs

  2. DominicHOr说道:

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

  3. NelsonSaIlk说道:

    buying from online mexican pharmacy: mexican rx online – mexican drugstore online

  4. NelsonSaIlk说道:

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

  5. Waynetar说道:

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

  6. NelsonSaIlk说道:

    purple pharmacy mexico price list: best online pharmacies in mexico – mexican border pharmacies shipping to usa

  7. Waynetar说道:

    pharmacies in mexico that ship to usa: reputable mexican pharmacies online – medication from mexico pharmacy

  8. DominicHOr说道:

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

  9. NelsonSaIlk说道:

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

  10. DominicHOr说道:

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

  11. NelsonSaIlk说道:

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

  12. NelsonSaIlk说道:

    mexican rx online: reputable mexican pharmacies online – mexican pharmaceuticals online

  13. Arnoldscava说道:

    mexican online pharmacies prescription drugs mexican pharmacy medication from mexico pharmacy

  14. prodvizhen_uapl说道:

    сколько стоит аудит сайта http://www.prodvizhenie-sajtov15.ru .

  15. prodvizhen_ozpl说道:

    продвижение сайта в поисковых системах https://www.prodvizhenie-sajtov15.ru/ .

  16. I got this site from my buddy who told me regarding this website and now this time I am
    visiting this site and reading very informative content at this time.

  17. NelsonSaIlk说道:

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

  18. NelsonSaIlk说道:

    mexico pharmacies prescription drugs: medicine in mexico pharmacies – mexico pharmacies prescription drugs

  19. えろ 人形and emotional toxicity that can gradually erode the individuals’ sense of self, self-esteem,

  20. Baratz goes on to tell me about one of his clients, a woman currently going through a divorce and having a sexual awakening. ‘女性 用 ラブドールEach time she meets someone new, she punishes herself,’ he says.

  21. Arnoldscava说道:

    mexico drug stores pharmacies mexican mail order pharmacies purple pharmacy mexico price list

  22. Arnoldscava说道:

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

  23. えろ 人形说道:

    going on to become advocates for people of color and champions against racism.About half the men reported that they had felt objectified,ドール アダルト

  24. Arnoldscava说道:

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

  25. Waynetar说道:

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

  26. Arnoldscava说道:

    mexico pharmacies prescription drugs mexico pharmacies prescription drugs mexican online pharmacies prescription drugs

  27. Waynetar说道:

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

  28. Arnoldscava说道:

    mexico pharmacies prescription drugs reputable mexican pharmacies online mexican pharmaceuticals online

  29. Arnoldscava说道:

    buying from online mexican pharmacy mexican pharmaceuticals online reputable mexican pharmacies online

  30. Waynetar说道:

    best online pharmacies in mexico: medication from mexico pharmacy – mexican mail order pharmacies

  31. DominicHOr说道:

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

  32. Waynetar说道:

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

  33. DominicHOr说道:

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

  34. скачать популярные игры на телефон бесплатно https://android-games-download.ru .

  35. Arnoldscava说道:

    mexican border pharmacies shipping to usa mexico pharmacy mexican online pharmacies prescription drugs

  36. Waynetar说道:

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

  37. DominicHOr说道:

    reputable mexican pharmacies online: mexican rx online – medication from mexico pharmacy

  38. Waynetar说道:

    pharmacies in mexico that ship to usa: mexican rx online – mexico drug stores pharmacies

  39. NelsonSaIlk说道:

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

  40. Waynetar说道:

    п»їbest mexican online pharmacies: mexico drug stores pharmacies – pharmacies in mexico that ship to usa

  41. NelsonSaIlk说道:

    best online pharmacies in mexico: best online pharmacies in mexico – reputable mexican pharmacies online

  42. DominicHOr说道:

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

  43. Waynetar说道:

    reputable mexican pharmacies online: п»їbest mexican online pharmacies – purple pharmacy mexico price list

  44. Arnoldscava说道:

    mexico pharmacies prescription drugs mexico pharmacy п»їbest mexican online pharmacies

  45. DominicHOr说道:

    mexican border pharmacies shipping to usa: pharmacies in mexico that ship to usa – reputable mexican pharmacies online

  46. NelsonSaIlk说道:

    pharmacies in mexico that ship to usa: mexican mail order pharmacies – mexican drugstore online

  47. Tooft说道:

    Cookie Preferences First State Update Ezell and Elizabeth Chase, a doctoral student at the University of Michigan School of Public Health, are co-authors of “A Population-Based Assessment of Physical Symptoms and Mental Health Outcomes Among Adults Following the Flint Water Crisis,” published March 31 in the Journal of Urban Health. Stay connected with the latest legal news, court opinions and commentary. Sign up here! The Michigan Department of Health and Human Services has confirmed a case of measles in Washtenaw… Registration on or use of this site constitutes acceptance of our User Agreement and Privacy Policy If you are 16-19 years old and a Flint resident Flint & Genesee Education & Talent could have… In 2014, Flint managers appointed by Snyder took the city out of a regional water system and began using the Flint River to save money while a new pipeline to Lake Huron was being built. But the river water wasn’t treated to reduce its corrosive qualities. Lead broke off from old pipes and contaminated the system for more than a year.
    https://hotel-wiki.win/index.php?title=10_different_kinds_of_media
    Citizens of Sudan’s capital, Khartoum, woke up to what many considered inevitable. Sudan’s army and a paramilitary force known as the Rapid Support Force (RSF) have declared war against each other bringing the country to its knees, with little regard to Sudanese people caught in the middle.” Stay informed. Sign up for a FREE NewsNow account and get our email alert of the day’s top stories from the UK and around the world. I go blank when someone asks me about South Sudan. This is because I am often confused with where or how to categorise this blessed nation state. South Sudan is a land of abundance. That to many may seem unrealistic but it is real. It is a land of many diverse economies, cultures and environments. The site is secure. A lock () or ensures that you are connecting to the official website and that any information you provide is encrypted and transmitted securely.

发表回复

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