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

/ 183,176评论 / 461945阅读 / 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. Davidfrify说道:

    cost generic propecia without dr prescription buy propecia prices cost of cheap propecia without a prescription

  2. Davidfrify说道:

    ciprofloxacin ciprofloxacin order online buy ciprofloxacin

  3. WilliamRen说道:

    https://nolvadex.life/# aromatase inhibitors tamoxifen

  4. Davidfrify说道:

    buy cytotec pills online cheap buy cytotec Cytotec 200mcg price

  5. Davidfrify说道:

    buy misoprostol over the counter buy cytotec pills buy cytotec online fast delivery

  6. RandallGuesE说道:

    lisinopril best price: lisinopril 20 mg price in india – discount zestril

  7. WilliamRen说道:

    https://lisinopril.network/# lisinopril brand

  8. RandallGuesE说道:

    lisinopril 2.5 mg tablet: lisinopril 20mg – cost of lisinopril 2.5 mg

  9. Davidfrify说道:

    tamoxifen postmenopausal tamoxifen and ovarian cancer tamoxifen buy

  10. WilliamRen说道:

    https://cytotec.club/# Abortion pills online

  11. RandallGuesE说道:

    buy cipro cheap: where can i buy cipro online – buy cipro online

  12. RandallGuesE说道:

    cipro online no prescription in the usa: buy cipro online without prescription – ciprofloxacin generic

  13. Davidfrify说道:

    nolvadex 10mg nolvadex half life tamoxifen citrate pct

  14. RandallGuesE说道:

    buying generic propecia no prescription: order generic propecia pill – get propecia online

  15. Davidfrify说道:

    how to get nolvadex tamoxifen postmenopausal benefits of tamoxifen

  16. Davidfrify说道:

    cost cheap propecia for sale cost generic propecia without rx cost propecia price

  17. Davidfrify说道:

    antibiotics cipro ciprofloxacin generic buy cipro online canada

  18. WilliamRen说道:

    https://ciprofloxacin.tech/# п»їcipro generic

  19. RonaldSwobe说道:

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

  20. WilliamRen说道:

    https://cytotec.club/# Misoprostol 200 mg buy online

  21. RonaldSwobe说道:

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

  22. Scottvaw说道:

    Understanding COSC Certification and Its Importance in Horology
    COSC Accreditation and its Strict Criteria
    COSC, or the Official Swiss Chronometer Testing Agency, is the official Switzerland testing agency that certifies the accuracy and accuracy of timepieces. COSC certification is a sign of excellent craftsmanship and dependability in chronometry. Not all watch brands seek COSC accreditation, such as Hublot, which instead adheres to its own strict criteria with movements like the UNICO calibre, attaining equivalent precision.

    The Art of Exact Chronometry
    The core mechanism of a mechanized timepiece involves the mainspring, which supplies power as it loosens. This mechanism, however, can be vulnerable to external elements that may influence its accuracy. COSC-validated mechanisms undergo rigorous testing—over 15 days in various conditions (five positions, 3 temperatures)—to ensure their resilience and dependability. The tests evaluate:

    Mean daily rate precision between -4 and +6 secs.
    Mean variation, peak variation levels, and effects of temperature variations.
    Why COSC Validation Is Important
    For timepiece aficionados and connoisseurs, a COSC-validated watch isn’t just a piece of tech but a proof to enduring excellence and accuracy. It signifies a timepiece that:

    Offers outstanding dependability and precision.
    Provides guarantee of superiority across the entire design of the watch.
    Is probable to hold its value more efficiently, making it a sound investment.
    Popular Timepiece Manufacturers
    Several famous brands prioritize COSC accreditation for their timepieces, including Rolex, Omega, Breitling, and Longines, among others. Longines, for instance, provides collections like the Record and Soul, which highlight COSC-validated movements equipped with innovative materials like silicon equilibrium suspensions to improve resilience and efficiency.

    Historic Context and the Evolution of Timepieces
    The notion of the timepiece originates back to the need for accurate timekeeping for navigation at sea, highlighted by John Harrison’s work in the eighteenth century. Since the official establishment of COSC in 1973, the accreditation has become a standard for evaluating the precision of high-end timepieces, continuing a tradition of superiority in watchmaking.

    Conclusion
    Owning a COSC-validated timepiece is more than an visual choice; it’s a dedication to excellence and accuracy. For those appreciating precision above all, the COSC certification offers peacefulness of thoughts, ensuring that each accredited timepiece will perform dependably under various circumstances. Whether for individual satisfaction or as an investment, COSC-accredited watches distinguish themselves in the world of horology, maintaining on a legacy of careful chronometry.

  23. Davidfrify说道:

    tamoxifen moa tamoxifen hormone therapy tamoxifen hair loss

  24. RonaldSwobe说道:

    http://nolvadex.life/# tamoxifen and depression

  25. RandallGuesE说道:

    ciprofloxacin mail online: ciprofloxacin generic price – ciprofloxacin 500mg buy online

发表回复

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