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

/ 191,932评论 / 537627阅读 / 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. Podcast LOL说道:

    Hey there! I could have sworn I’ve been to this website before but after browsing through some of
    the post I realized it’s new to me. Anyhow, I’m definitely happy I found it and I’ll be bookmarking and checking back frequently!

  2. Jamesjer说道:

    buy amoxicillin: amoxicillin buy no prescription – amoxicillin cephalexin

  3. очень классное порево https://www.klassny-sex.ru .

  4. Jamesjer说道:

    buy generic ciprofloxacin: antibiotics cipro – buy cipro online without prescription

  5. Jamesjer说道:

    п»їpaxlovid: Paxlovid over the counter – paxlovid for sale

  6. えろ人形说道:

    Being connected to how your body feels is your reference point for knowing what you want and where your boundaries are.Be present.オナドール

  7. LarryLip说道:

    подъемное оборудование лифты грузовые подъемники стоечные

  8. ThomasInace说道:

    http://ciprodelivery.pro/# buy generic ciprofloxacin

  9. Victoredize说道:

    Bayern Munich’s https://bayern.jamal-musiala-ar.com young midfielder, Jamal Musiala, has become one of the brightest talents in European football.

  10. Davidfax说道:

    Thibaut Courtois https://real-madrid.thibaut-courtois-ar.com was born on May 11, 1992 in Belgium.

  11. ThomasInace说道:

    http://ciprodelivery.pro/# ciprofloxacin mail online

  12. Oscarerard说道:

    Arsenal https://arsenal.mesut-ozil-ar.com made a high-profile signing in 2013, signing star midfielder Mesut Ozil from Real Madrid.

  13. Kennethrhync说道:

    EuroAvia24.com – Cheap flights, hotels and transfers around the world!

  14. Robertfen说道:

    The Saudi Football League https://saudi-arabian-championship.saudi-pro-league-ar.com known as the Saudi Professional League, is one of the most competitive and dynamic leagues in the world.

  15. Isaiasminue说道:

    Rodrigo Goes https://real-madrid.rodrygo-ar.com better known as Rodrigo, is one of the brightest young talents in modern football.

  16. ThomasInace说道:

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

  17. Jamesjer说道:

    antibiotic amoxicillin: purchase amoxicillin 500 mg – amoxicillin 500mg no prescription

  18. MartinLoort说道:

    In an era when many young footballers struggle to find their place at elite clubs, Javi’s https://barcelona.gavi-ar.com story at Barcelona stands out as an exceptional one.

  19. Jamesjer说道:

    ciprofloxacin 500 mg tablet price: where can i buy cipro online – buy cipro

  20. ThomasInace说道:

    https://ciprodelivery.pro/# ciprofloxacin order online

  21. ThomasInace说道:

    http://doxycyclinedelivery.pro/# doxycycline brand name canada

  22. ThomasInace说道:

    http://ciprodelivery.pro/# cipro pharmacy

  23. Jamesjer说道:

    buy paxlovid online: Paxlovid over the counter – paxlovid buy

  24. Jamesjer说道:

    order clomid: where to buy clomid online – clomid no prescription

  25. ThomasInace说道:

    http://doxycyclinedelivery.pro/# doxycycline no prescription best prices

  26. Jamesjer说道:

    buy cipro online usa: cipro 500mg best prices – cipro pharmacy

  27. Jamesjer说道:

    doxycycline 100 mg tablets: doxycycline online canada – how to get doxycycline

  28. Robertimica说道:

    In recent years, the leading positions in the Spanish https://spanish-championship.laliga-ar.com championship have been firmly occupied by two major giants – Barcelona and Real Madrid.

  29. BrettJeaby说道:

    In the German football https://german-championship.bundesliga-football-ar.com championship known as the Bundesliga, rivalries between clubs have always been intense.

  30. Davidburce说道:

    The Italian football championship https://italian-championship.serie-a-ar.com known as Serie A, has seen an impressive revival in recent years.

  31. DonaldRak说道:

    The road to the Premier League https://english-championship.premier-league-ar.com begins long before a team gets promoted to the English Premier League for the first time

  32. Jamesjer说道:

    cost doxycycline: doxycycline 100mg capsules – doxycycline costs uk

  33. Georgeres说道:

    The golf https://arabic.golfclub-ar.com industry in the Arab world is growing rapidly, attracting players from all over the world.

  34. ThomasInace说道:

    http://ciprodelivery.pro/# buy generic ciprofloxacin

  35. Jamesjer说道:

    amoxicillin 1000 mg capsule: cost of amoxicillin 875 mg – buy amoxicillin 500mg

  36. ThomasInace说道:

    http://doxycyclinedelivery.pro/# doxycycline 100mg uk

  37. Jamesjer说道:

    doxycycline 40 mg capsules: doxycycline 1000 mg best buy – buy doxycycline without prescription uk

  38. ThomasInace说道:

    http://clomiddelivery.pro/# generic clomid online

  39. Jamesjer说道:

    where can i buy doxycycline: doxycycline 50mg tablets – where to buy doxycycline in singapore

  40. エロ 中国说道:

    prioritize thoughtfully,えろ 人形and look out for each other.

  41. Jamesjer说道:

    paxlovid price: paxlovid generic – п»їpaxlovid

  42. ThomasInace说道:

    http://amoxildelivery.pro/# amoxicillin azithromycin

  43. エロ人形说道:

    Chinese sexual intercourse doll makers’ export orders doubled this calendar year throughout初音 ミク ラブドール the COVID-19 pandemic as a result of loneliness introduced about by rigorous social distancing steps, media experiences said.

发表回复

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