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

/ 191,948评论 / 537867阅读 / 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. KennethRorie说道:

    When Taylor Swift https://shake-it-off.taylor-swift-ar.com released “Shake It Off” in 2014, she had no idea how much the song would impact her life and music career.

  2. ThomasInace说道:

    https://amoxildelivery.pro/# buy amoxicillin 500mg uk

  3. Robertlot说道:

    Priyanka Chopra https://baywatch.priyankachopra-ar.com is an Indian actress, singer, film producer and model who has achieved global success.

  4. Jamesjer说道:

    amoxicillin pharmacy price: can you buy amoxicillin over the counter – amoxicillin brand name

  5. MatthewBup说道:

    Liverpool https://england.liverpool-ar.com holds a special place in the history of football in England.

  6. Raymondjoirl说道:

    Автомобили Hongqi https://hongqi-krasnoyarsk.ru в наличии – официальный дилер Hongqi Красноярск

  7. New说道:

    Boom also praised the site for being inclusive of LBGTQ users and having what one reviewer called a “user-friendly design,” which Boom said, “makes it a good fit for older daters who didn’t grow up online.” While there are some great dating sites out there, the best one for you is the one that matches your goals, so if you’re looking for something long-term or are dating over 50, there is a site for you. These Valentine’s Day Dates Are Cute, Not Cheesy Women who have used online dating platforms in the past year are more likely to feel overwhelmed by the number of messages they get, while men are more likely to feel insecure about a lack of messages. Among current or recent online dating users, 54% of women say they have felt overwhelmed by the number of messages they received on dating sites or apps in the past year, while just a quarter of men say the same. By contrast, 64% of men say they have felt insecure because of the lack of messages they received, while four-in-ten women say the same.
    https://keeganokea581502.luwebs.com/28217024/speed-dating-bar
    What happens when you apply scientific research to dating behavior? A whole lotta love! But this isn’t destiny, it’s deliberate. That’s why every 14 minutes, someone finds love on eharmony. Another thing to consider is the functionality of the website itself. Your chosen dating site should be easy to use, and have all the functions that you need to feel comfortable using it. Maybe all you need is a simple text-chat function and the ability to see your potential partner’s profile, or maybe you’d like to engage in video chat with them. You could say that “the more functions there are, the better”, but again it does really all come down to personal preference. If you value simplicity over functionality, you’ll definitely want a website with fewer functions but one that is simple and easier to get around.

  8. Jamesjer说道:

    where buy clomid price: can i get clomid – where can i get clomid pill

  9. Jamesjer说道:

    can i order cheap clomid tablets: order clomid without dr prescription – where buy generic clomid no prescription

  10. Mushroom gummies说道:

    This site was… how do you say it? Relevant!! Finally I have found something that helped me. Many thanks.

  11. ThomasInace说道:

    http://clomiddelivery.pro/# buying cheap clomid without insurance

  12. ThomasInace说道:

    https://clomiddelivery.pro/# can i purchase generic clomid pill

  13. Jamesjer说道:

    buy paxlovid online: paxlovid pill – paxlovid pharmacy

  14. Jamesjer说道:

    paxlovid covid: paxlovid for sale – paxlovid buy

  15. ThomasInace说道:

    https://ciprodelivery.pro/# ciprofloxacin generic price

  16. Jamesjer说道:

    amoxicillin discount: amoxicillin 775 mg – buy amoxicillin 500mg usa

  17. Jamesjer说道:

    buy doxycycline 100mg tablets: doxycycline 200 mg pill – doxycycline 20 mg capsules

  18. ThomasInace说道:

    https://amoxildelivery.pro/# order amoxicillin 500mg

  19. Heya just wanted to give you a brief heads up and let you know a few of the images aren’t loading
    correctly. I’m not sure why but I think its a linking issue.
    I’ve tried it in two different internet browsers and both show the same outcome.

  20. ThomasInace说道:

    https://clomiddelivery.pro/# order clomid tablets

  21. Jamesjer说道:

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

  22. ThomasInace说道:

    https://doxycyclinedelivery.pro/# pharmacy prices for doxycycline

  23. Jamesjer说道:

    amoxicillin 500mg buy online canada: where can you buy amoxicillin over the counter – amoxicillin generic

  24. Jamesjer说道:

    paxlovid for sale: paxlovid cost without insurance – п»їpaxlovid

  25. ThomasInace说道:

    http://clomiddelivery.pro/# can you buy generic clomid without a prescription

  26. link bokep说道:

    I visited many web sites however the audio feature for audio songs
    existing at this web page is really wonderful.

  27. ThomasInace说道:

    https://amoxildelivery.pro/# prescription for amoxicillin

  28. CalvinGef说道:

    Juventus Football Club https://italy.juventus-ar.com is one of the most successful and decorated clubs in the history of Italian and world football.

  29. DonaldHew说道:

    Chelsea https://england.chelsea-ar.com is one of the most successful English football clubs of our time.

  30. Williamacrog说道:

    The history of one of France’s https://france.paris-saint-germain-ar.com most famous football clubs, Paris Saint-Germain, began in 1970, when capitalist businessmen Henri Delaunay and Jean-Auguste Delbave founded the club in the Paris Saint-Germain-en-Laye area.

  31. DonaldCon说道:

    Zinedine Zidane https://real-madrid.zinedine-zidane-ar.com the legendary French footballer, entered the annals of football history as a player and coach.

  32. JamesMyday说道:

    Travis Scott https://astroworld.travis-scott-ar.com is one of the brightest stars in the modern hip-hop industry.

  33. asbestos说道:

    Pretty! This was a really wonderful post. Many thanks for supplying this info.

  34. ThomasInace说道:

    https://clomiddelivery.pro/# can i get generic clomid without rx

  35. ThomasInace说道:

    https://amoxildelivery.pro/# amoxil pharmacy

  36. bokep viral说道:

    Very shortly this web site will be famous among all
    blogging and site-building viewers, due to it’s pleasant articles

  37. ThomasInace说道:

    https://clomiddelivery.pro/# how can i get cheap clomid price

  38. Jamesjer说道:

    cheapest 40 mg doxycycline: doxycycline cost australia – doxycycline tablets over the counter

  39. ThomasInace说道:

    http://paxloviddelivery.pro/# buy paxlovid online

  40. Jamesjer说道:

    clomid generic: can i get clomid pills – where to get clomid price

  41. ThomasInace说道:

    https://paxloviddelivery.pro/# paxlovid generic

  42. Jamesjer说道:

    over the counter amoxicillin canada: prescription for amoxicillin – amoxicillin cephalexin

  43. ThomasInace说道:

    http://amoxildelivery.pro/# amoxicillin generic

  44. Jamesjer说道:

    doxycycline where to get: doxycycline online purchase – doxycycline 100mg tablets no prescription

  45. ThomasInace说道:

    https://doxycyclinedelivery.pro/# doxycycline 100mg best buy

  46. ThomasInace说道:

    https://amoxildelivery.pro/# order amoxicillin online no prescription

  47. Jamesjer说道:

    amoxicillin azithromycin: amoxicillin price without insurance – amoxicillin 500mg price

  48. ThomasInace说道:

    http://paxloviddelivery.pro/# Paxlovid buy online

发表回复

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