一.防盗链概述
- 防盗链就是防止别人的网站代码里面盗用服务器的图片、文件、视频等相关资源;如果别人盗用网站的这些静态资源,明显的是会增大服务器的带宽压力;作为网站的维护人员,要杜绝服务器的静态资源被其他网站盗用
- HTTP标准协议中专门的Referer字段记录,它的作用是可以追溯上一个入站地址是什么,此外,对于资源文件,可以追踪到包含显示它的网页地址是什么。因此,防盗链方法基于这个Referer字段
- Apache防盗链需要安装mod_rewrite模块
二.隐藏版本信息概述
- 一般情况下,Apache的版本信息,透露了一定的漏洞信息,从而给网站带来安全隐患
- 在生产环境中要配置Apache的隐藏版本信息
- 可以使用Fiddler抓包工具分析,网站的版本信息
三.网页防盗链和隐藏版本信息实验
yum install bind -y
#配置主配置文件
vim /etc/named.conf
#13行,和21行
127.0.0.1改为any
localhost改为any
#配置区域文件
vim /etc/named.rfc1912.zones
#
zone "kgc.com" IN {
type master;
file "kgc.com.zone";
allow-update { none; };
};
#配置区域数据文件
cd /var/named
cp -p named.localhost kgc.com.zone
vim kgc.com.zone
www IN A 192.168.43.211
systemctl start named
systemctl stop firewalld
setenforce 0
- 验证DNS域名解析功能(windows10,需要将客户的DNS服务器的IP地址改为192.168.43.211)
#获取apache相关软件包,解压
tar zxvf apr-1.6.2.tar.gz -C /opt
tar zxvf apr-util-1.6.0.tar.gz -C /opt
tar jxvf httpd-2.4.29.tar.bz2 -C /opt
- 将apr和apr-util组件放到httpd的srclib目录中去
cd /opt
mv apr-util-1.6.0/ httpd-2.4.29/srclib/apr-util
mv apr-1.6.2/ httpd-2.4.29/srclib/apr
yum install gcc gcc-c++ pcre pcre-devel zlib-devel expat-devel make perl -y
- 配置Apache服务,防盗链需要mod_rewrite模块
cd /cd/ httpd-2.4.29
./configure \
--prefix=/usr/local/httpd \
--enable-deflate \
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi
make && make install
grep -v "#" /usr/local/httpd/bin/apachectl > /etc/init.d/httpd
vim /etc/init.d/httpd
#!/bin/bash
# chkconfig:2345 85 15
# description:Apache is a World Wide Web server.
chmod +x /etc/init.d/httpd
chkconfig --add httpd
chkconfig --list httpd
chkconfig --level 35 httpd on
vim /usr/local/httpd/conf/httpd.conf
Listen:192.168.43.211:80
ServerName:www.kgc.com
#开启rewrite模块
LoadModule rewrite_modules modules/mod_rewrite.so
#配置mod_rewrite模块的内容
<Directory "/usr/local/httpd/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
RewriteEngine On //引擎
RewriteCond %{HTTP_REFERER} !^http://kgc.com/.*$ [NC] //规则
RewriteCond %{HTTP_REFERER} !^http://kgc.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.kgc.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.kgc.com/$ [NC]
RewriteRule .*\.(gif|jpg|swf)$ http://www.kgc.com/error.png //跳转
</Directory>
cd /usr/local/httpd/bin
./apachectl -t -D DUMP_MODULES | grep "rewrite"
rewrite_module (shared)
vim /usr/local/httpd/conf/httpd.conf
Include conf/extra/httpd-default.conf
vim /usr/local/httpd/conf/extra/httpd-default.conf
#只显示名称
ServerTokens Prod
[root@192 htdocs]# ls
1.jpg error.png index.html
[root@192 htdocs]# vim index.html
<html><body>
<h1>It works!</h1>
<img style height=200px;width=300px src="1.jpg"/>
</body></html>
[root@192 htdocs]# systemctl restart httpd
yum install httpd -y
[root@192 conf]# vim /var/www/html/index.html
<html>
<body>
<h1>It works!</h1>
<img src=”http://www.kgc.com/1.jpg”/>
</body>
</html>
systemctl start httpd