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

/ 181,924评论 / 453487阅读 / 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. RickyAlage说道:

    best online pharmacy india india pharmacy india online pharmacy

  2. StevenSen说道:

    indianpharmacy com: best india pharmacy – best online pharmacy india

  3. Marcelcrolf说道:

    https://indiaph24.store/# reputable indian pharmacies

  4. Michaelsew说道:

    http://canadaph24.pro/# canadian pharmacy

  5. Marcelcrolf说道:

    https://canadaph24.pro/# canadian pharmacy oxycodone

  6. Marcelcrolf说道:

    http://canadaph24.pro/# canadian pharmacies compare

  7. JustinTut说道:

    online shopping pharmacy india https://indiaph24.store/# buy medicines online in india
    online pharmacy india

  8. JustinTut说道:

    india pharmacy https://indiaph24.store/# indian pharmacy online
    Online medicine home delivery

  9. RickyAlage说道:

    best canadian pharmacy online Large Selection of Medications from Canada pharmacy com canada

  10. Marcelcrolf说道:

    https://indiaph24.store/# india online pharmacy

  11. Marcelcrolf说道:

    http://mexicoph24.life/# pharmacies in mexico that ship to usa

  12. Scottvaw说道:

    Rolex watches
    Understanding COSC Accreditation and Its Importance in Horology
    COSC Validation and its Strict Criteria
    Controle Officiel Suisse des Chronometres, or the Official Swiss Chronometer Testing Agency, is the official Switzerland testing agency that verifies the precision and precision of timepieces. COSC certification is a mark of superior craftsmanship and trustworthiness in chronometry. Not all timepiece brands seek COSC accreditation, such as Hublot, which instead adheres to its own demanding criteria with movements like the UNICO, achieving similar precision.

    The Science of Exact Chronometry
    The core mechanism of a mechanical watch involves the mainspring, which provides energy as it unwinds. This system, however, can be susceptible to environmental factors that may impact its precision. COSC-certified movements undergo demanding testing—over fifteen days in various circumstances (5 positions, 3 temperatures)—to ensure their resilience and dependability. The tests assess:

    Average daily rate precision between -4 and +6 seconds.
    Mean variation, peak variation rates, and effects of thermal variations.
    Why COSC Validation Is Important
    For watch enthusiasts and collectors, a COSC-certified watch isn’t just a piece of technology but a demonstration to lasting quality and precision. It symbolizes a timepiece that:

    Provides outstanding dependability and precision.
    Provides assurance of quality across the complete design of the watch.
    Is likely to maintain its worth more efficiently, making it a wise choice.
    Well-known Chronometer Brands
    Several renowned manufacturers 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 feature COSC-validated movements equipped with advanced materials like silicon equilibrium springs to improve durability and performance.

    Historical Background and the Evolution of Timepieces
    The idea of the chronometer originates back to the requirement for precise chronometry for navigational at sea, emphasized by John Harrison’s work in the eighteenth cent. Since the official foundation of COSC in 1973, the accreditation has become a yardstick for evaluating the precision of high-end timepieces, continuing a tradition of superiority in horology.

    Conclusion
    Owning a COSC-validated timepiece is more than an aesthetic choice; it’s a dedication to excellence and precision. For those appreciating accuracy above all, the COSC certification provides tranquility of mind, ensuring that each accredited timepiece will perform dependably under various circumstances. Whether for personal contentment or as an investment, COSC-certified watches stand out in the world of horology, carrying on a legacy of meticulous chronometry.

  13. RickyAlage说道:

    online pharmacy india Cheapest online pharmacy indian pharmacy paypal

  14. I do trust all of the ideas you’ve offered for your post.
    They are really convincing and will certainly work. Nonetheless, the posts are very short for beginners.
    Could you please lengthen them a bit from next time? Thank you for the post.

  15. Pedropaite说道:

    mexican rx online: Online Pharmacies in Mexico – buying from online mexican pharmacy

  16. Marcelcrolf说道:

    http://mexicoph24.life/# mexican border pharmacies shipping to usa

  17. RickyAlage说道:

    canada drugs online Prescription Drugs from Canada my canadian pharmacy

  18. RickyAlage说道:

    online shopping pharmacy india indian pharmacy top online pharmacy india

  19. Pedropaite说道:

    buying from online mexican pharmacy: Mexican Pharmacy Online – mexican border pharmacies shipping to usa

  20. StevenSen说道:

    mexico drug stores pharmacies: Online Pharmacies in Mexico – reputable mexican pharmacies online

  21. JustinTut说道:

    indian pharmacy paypal https://indiaph24.store/# Online medicine home delivery
    india pharmacy

  22. Pedropaite说道:

    purple pharmacy mexico price list: mexico pharmacy – mexican drugstore online

  23. StevenSen说道:

    canada cloud pharmacy: Certified Canadian Pharmacies – canadian drugs

  24. JustinTut说道:

    top 10 online pharmacy in india https://indiaph24.store/# Online medicine order
    indianpharmacy com

  25. Jamila说道:

    I’m no longer positive the place you’re getting your info, however great topic.
    I must spend a while learning much more or understanding more.
    Thanks for excellent info I was searching for this info for my mission.

  26. RickyAlage说道:

    top 10 online pharmacy in india buy medicines from India reputable indian pharmacies

  27. Michaelsew说道:

    http://canadaph24.pro/# canadianpharmacymeds com

  28. Marcelcrolf说道:

    https://indiaph24.store/# reputable indian online pharmacy

  29. Michaelsew说道:

    http://indiaph24.store/# best india pharmacy

  30. RickyAlage说道:

    is canadian pharmacy legit canadian pharmacy cheap ed drugs online from canada

  31. StevenSen说道:

    online pharmacy india: best online pharmacy india – buy medicines online in india

  32. Marcelcrolf说道:

    https://indiaph24.store/# india online pharmacy

  33. RickyAlage说道:

    india online pharmacy top 10 pharmacies in india top online pharmacy india

发表回复

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