@font-face{
- font-family:"Times New Roman";
}
@font-face{
font-family:"宋体";
}
@font-face{
font-family:"Calibri";
}
@font-face{
font-family:"PingFangSC-Light";
}
p.MsoNormal{
mso-style-name:正文;
mso-style-parent:"";
margin:0pt;
margin-bottom:.0001pt;
mso-pagination:none;
text-align:justify;
text-justify:inter-ideograph;
font-family:Calibri;
mso-fareast-font-family:宋体;
mso-bidi-font-family:'Times New Roman';
font-size:10.5000pt;
mso-font-kerning:1.0000pt;
}
h3{
mso-style-name:"标题 3";
mso-style-noshow:yes;
mso-style-next:正文;
margin-top:5.0000pt;
margin-bottom:5.0000pt;
mso-margin-top-alt:auto;
mso-margin-bottom-alt:auto;
mso-pagination:none;
text-align:left;
font-family:宋体;
font-weight:bold;
font-size:13.5000pt;
}
h5{
mso-style-name:"标题 5";
mso-style-noshow:yes;
mso-style-next:正文;
margin-top:5.0000pt;
margin-bottom:5.0000pt;
mso-margin-top-alt:auto;
mso-margin-bottom-alt:auto;
mso-pagination:none;
text-align:left;
font-family:宋体;
font-weight:bold;
font-size:10.0000pt;
}
span.10{
font-family:'Times New Roman';
}
span.15{
font-family:'Times New Roman';
font-weight:bold;
}
span.16{
font-family:'Times New Roman';
color:rgb(0,0,255);
text-decoration:underline;
text-underline:single;
}
span.msoIns{
mso-style-type:export-only;
mso-style-name:"";
text-decoration:underline;
text-underline:single;
color:blue;
}
span.msoDel{
mso-style-type:export-only;
mso-style-name:"";
text-decoration:line-through;
color:red;
}
@page{mso-page-border-surround-header:no;
mso-page-border-surround-footer:no;}@page Section0{
margin-top:72.0000pt;
margin-bottom:72.0000pt;
margin-left:90.0000pt;
margin-right:90.0000pt;
size:595.3000pt 841.9000pt;
layout-grid:15.6000pt;
}
div.Section0{page:Section0;}
防盗链技术现状:
1、通过识别Referer确认请求来源页面
2、Apache,squid等都能对Referer进行识别
3、通过ActiveX显示的内容不向服务器提供Referer Header(例如,Flash,WindowsMedia视频等)
4、流媒体的RTSP协议也不向服务器提供Referer Header
5、通过服务器端程序代码实现
防盗链应用现状:
1、对图片、HTML等可以实现防盗链
2、无法对Flash,WindowsMedia视频(MMS,RTSP)实现防盗链
3、服务器端程序代码实现的防盗链无法通过CDN加速
对于Flash,WindowsMedia视频这种占用流量较大的服务无法实现防盗链,对一个依靠这类内容作为盈利点的网站来说是非常头疼的,俺通过一些研究以及测试实现了采用Cookie技术的防盗链解决方案,完美的解决了对Flash,WindowsMedia视频的防盗链。
首先发现虽然ActiveX插件不传递Referer,但是却忠实的传递Cookie。于是在显示ActiveX的页面的<head></head>标签内嵌入一段代码:
<script> document.cookie="Cache=vod;domain=domain.com;path=/"; </script>
这段代码用 javascript 设置了一段 Cookie: Cache=vod
然后通过各种ACL来判断这个Cookie的存在以及验证其值的操作了
Squid:
建立脚本 /usr/local/squid/libexec/squid_cookie.pl
#!/usr/bin/perl -w
# programmed by oknethttp://blog.sina.com.cn/m/oknet
# 这个脚本仅仅是验证了Cache这个cookie的存在,没有严格的校验其值。
# This is the cookie to check for.
$COOKIE="Cache=";
# disable output buffering
$|=1;
# cookie matches?
while (<STDIN>) {
chop;
$cookie=$_;
if( $cookie =~ /$COOKIE/i) {
print "OK\n";
} else { print "ERR\n"; }
}
然后在squid.conf添加:
external_acl_type download children=15 %{Cookie} /usr/local/squid/libexec/squid_cookie.pl
acl dl external download
然后选择需要进行防盗链的文件类型:
acl filetype url_regex -i .wmv
acl filetype url_regex -i .wma
acl filetype url_regex -i .asf
acl filetype url_regex -i .asx
acl filetype url_regex -i .avi
acl filetype url_regex -i .mp3
acl filetype url_regex -i .smi
acl filetype url_regex -i .rm
acl filetype url_regex -i .ram
acl filetype url_regex -i .rmvb
acl filetype url_regex -i .swf
acl filetype url_regex -i .mpg
acl filetype url_regex -i .mpeg
acl filetype url_regex -i .mov
acl filetype url_regex -i .zip
acl filetype url_regex -i .mid
如果仅仅只是禁止用户访问的话,就没意思了,要让盗链者帮我们宣传我们的网站,特别是发现盗链比较多的时候,这个时候,可以让任何盗链的网站帮我们免费宣传~那就是把盗链的url重定向到我们的网站宣传页
建立脚本:/usr/local/squid/libexec/squid_redir.pl
#!/usr/bin/perl -T -w
#
# rredir.pl
#
# Author: Peter Eisenhauer <[email protected]>
First Version: 26. May 1997
Modified by oknet[http://blog.sina.com.cn/m/oknet]\(http://blog.sina.com.cn/m/oknet)
#
# Description: Direct all request to files who are in a local dir to
# this directory
#
use File::Basename;
use URI::URL;
# flush after every print
$| = 1;
# Process lines of the form 'URL ip-address/fqdn ident method'
# See release notes of Squid 1.1 for details
while ( <> ) {
$r302=0;
($url, $addr, $fqdn, $ident, $method) = m:(\S*) (\S*)/(\S*) (\S*) (\S*):;
$url = url $url;
$host = lc($url->host);
if ( $host !~ /./ ) {
next;
}
if ( $host =~ /vod.domain.com/ ) {
白名单配置须知
若请求的referer字段匹配白名单设置的内容,则CDN节点正常返回请求信息;
若请求的referer字段不匹配白名单设置的内容,则CDN节点拒绝返回该请求信息,会直接返回状态码403;
当设置白名单时,CDN节点只能返回符合该白名单内字符串内容的请求;
当勾选包含空referer选项时,此时若请求referer字段为空或无referer字段(如浏览器请求),则CDN正常返回请求信息。
黑名单配置须知
若请求的referer字段匹配黑名单内设置的内容,CDN节点拒绝返回该请求信息,直接返回403状态码;
若请求的referer不匹配黑名单内设置的内容,则CDN节点正常返回请求信息;
当勾选【包含空referer】选项时,此时若请求referer字段为空或无referer字段(如浏览器请求),则CDN节点拒绝返回该请求信息,返回403状态码。
注意事项
referer黑名单、白名单二者不兼容,同一时间只能生效一种类型;
防盗链输入内容最多可输400条,以换行符相隔,一行输入一个。
防盗链支持域名/IP规则,匹配方式为前缀匹配,即假设名单为 www.abc.com,则 www.abc.com/123、www.abc.com.cn 也会匹配;假设配置名单为 127.0.0.1,则 127.0.0.1/123 也会匹配;
防盗链支持通配符匹配,即假设名单为 *.qq.com,则 www.qq.com、a.qq.com均会匹配。