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

/ 191,896评论 / 537311阅读 / 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. StevenSof说道:

    Thai Company Directory https://thaicorporates.com List of companies and business information.

  2. Jamesjer说道:

    can i purchase generic clomid: where to get generic clomid pill – can you buy cheap clomid

  3. Jamesjer说道:

    how can i get doxycycline over the counter: doxycycline order canada – order doxycycline no prescription

  4. Jamesjer说道:

    rx clomid: generic clomid without rx – can i buy generic clomid pills

  5. ThomasInace说道:

    https://clomiddelivery.pro/# can you get generic clomid without dr prescription

  6. ThomasInace说道:

    http://clomiddelivery.pro/# cost cheap clomid

  7. ThomasInace说道:

    https://doxycyclinedelivery.pro/# doxycycline online with no prescription

  8. Jamesjer说道:

    п»їpaxlovid: Paxlovid buy online – paxlovid pill

  9. Jamesjer说道:

    how to get clomid without insurance: where buy generic clomid no prescription – clomid rx

  10. Jamesjer说道:

    buy cipro online canada: buy generic ciprofloxacin – buy cipro no rx

  11. MichaelLix说道:

    FC Bayern Munich (Munich) https://germany.bayern-munchen-ar.com is one of the most famous and recognized football clubs in Germany and Europe

  12. RandallWhirm说道:

    Arsenal https://england.arsenal-ar.com is one of the most famous and successful football clubs in the history of English football.

  13. Jamesjer说道:

    can i get clomid no prescription: where can i get generic clomid without rx – how to get generic clomid tablets

  14. Jamesjer说道:

    clomid price: buy generic clomid without rx – where can i buy cheap clomid without prescription

  15. золотая коллекция порно porn-library.ru .

  16. ThomasInace说道:

    http://amoxildelivery.pro/# how to get amoxicillin over the counter

  17. Jamesjer说道:

    doxycycline for sale online uk: doxycycline otc drug – doxycycline 40 mg cost

  18. Jamesjer说道:

    can i buy clomid without prescription: get generic clomid – cheap clomid without a prescription

  19. Выбор авто из Кореи | Секреты выбора авто из Кореи | Корейские авто: плюсы и минусы | Топ-5 автомобилей из Кореи | За что полюбили автомобили Кореи | Топ-3 востребованных автомобиля из Кореи | Выбор экономичных корейских автомобилей | Ценовая политика корейских автомобилей | Какой авто из Кореи подойдет именно вам? | Лучшие внедорожники из Кореи | Выбор современного кроссовера Кореи | Корейские авто для долгих поездок: комфорт и безопасность | Советы по выбору городского авто из Кореи | Секреты осмотра авто из Кореи | Тюнинг авто из Кореи: особенности и возможности
    энкар авто из кореи энкар авто из кореи .

  20. ThomasInace说道:

    https://amoxildelivery.pro/# purchase amoxicillin online

  21. ThomasInace说道:

    https://ciprodelivery.pro/# buy cipro cheap

  22. porno video_mkml说道:

    топовые порно видео http://www.apteka-porno.ru .

  23. ThomasInace说道:

    https://amoxildelivery.pro/# where can i buy amoxicillin online

  24. This excellent website truly has all the information and facts I wanted about this subject and didn’t know who to ask.

  25. ThomasInace说道:

    https://clomiddelivery.pro/# can i get cheap clomid without prescription

  26. Jamesjer说道:

    buy paxlovid online: п»їpaxlovid – paxlovid cost without insurance

  27. ThomasInace说道:

    http://doxycyclinedelivery.pro/# buy doxycycline mexico

  28. Jamesjer说道:

    paxlovid price: paxlovid for sale – paxlovid covid

  29. KeithPex说道:

    FC Barcelona https://spain.fc-barcelona-ar.com is undoubtedly one of the most famous and well-known football clubs in the world.

  30. Jamesjer说道:

    amoxicillin buy canada: amoxicillin 800 mg price – buy amoxicillin canada

  31. ThomasInace说道:

    http://amoxildelivery.pro/# can i buy amoxicillin over the counter

  32. Jamesjer说道:

    buy doxycycline for dogs: doxycycline 3142 – doxycycline 50 medicine

  33. ThomasInace说道:

    http://clomiddelivery.pro/# can you buy clomid now

  34. Josephpeeri说道:

    Al-Nasr Club https://saudi.al-hilal-ar.com from Riyadh has a rich history of success, but its growth has been particularly impressive in recent years.

  35. Jamesjer说道:

    amoxicillin 50 mg tablets: medicine amoxicillin 500mg – can i buy amoxicillin over the counter in australia

  36. Michaeladume说道:

    Al-Ittihad https://saudi.al-ittihad-ar.com is one of the most famous football clubs in Saudi Arabia. Founded in 1927, the Saudi football giant has come a long way to the pinnacle of success.

  37. BrianLax说道:

    Al-Nasr https://saudi.al-nassr-ar.com is one of the most famous football teams in the Kingdom of Saudi Arabia.

  38. ThomasInace说道:

    https://amoxildelivery.pro/# buy amoxicillin

  39. Jamesjer说道:

    order amoxicillin online: can i buy amoxicillin over the counter in australia – amoxicillin 500mg capsules price

  40. Frankpox说道:

    Luis Suarez https://inter-miami.luis-suarez-ar.com the famous Uruguayan footballer, ended his brilliant career in European clubs and decided to try his hand at a new challenge – Major League Soccer.

  41. Jamesjer说道:

    purchase cipro: buy cipro online without prescription – buy cipro online

  42. ThomasInace说道:

    http://clomiddelivery.pro/# where to get clomid now

  43. Jamesjer说道:

    ciprofloxacin generic price: where can i buy cipro online – buy cipro cheap

发表回复

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