防盜鏈就是防止別人的網(wǎng)站代碼里面盜用服務(wù)器的圖片、文件、視頻等相關(guān)資源
創(chuàng)新互聯(lián)建站專注于遂寧網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供遂寧營(yíng)銷型網(wǎng)站建設(shè),遂寧網(wǎng)站制作、遂寧網(wǎng)頁(yè)設(shè)計(jì)、遂寧網(wǎng)站官網(wǎng)定制、微信小程序定制開(kāi)發(fā)服務(wù),打造遂寧網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供遂寧網(wǎng)站排名全網(wǎng)營(yíng)銷落地服務(wù)。
如果別人盜用網(wǎng)站的這些靜態(tài)資源,明顯的是會(huì)增大服務(wù)器的帶寬壓力
* %{HTTP_ _REFERER}:瀏覽header中的鏈接字段,存放一一個(gè)鏈接的URL,代表是從哪個(gè)鏈接訪問(wèn)所需的網(wǎng)頁(yè)
!^:不以后面的字符串開(kāi)頭
.*$:以任意字符結(jié)尾
NC:不區(qū)分大寫(xiě)
R:強(qiáng)制跳轉(zhuǎn)
RewriteEngine On:打開(kāi)網(wǎng)頁(yè)重寫(xiě)功能
RewriteCond:設(shè)置匹配規(guī)則
RewriteRule:設(shè)置跳轉(zhuǎn)動(dòng)作
如果相應(yīng)變量的值匹配所設(shè)置的規(guī)則,則逐條往下處理;如果不匹配,則往后的規(guī)則不再匹配。
(1)安裝DNS服務(wù)的軟件包bind。
[root@localhost ~]# yum install bind -y
......//省略安裝過(guò)程
[root@localhost ~]#
(2)對(duì)DNS服務(wù)的主配置文件進(jìn)行修改。
[root@localhost ~]# vim /etc/named.conf
options {
listen-on port 53 { any; }; //127.0.0.1改為any
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
recursing-file "/var/named/data/named.recursing";
secroots-file "/var/named/data/named.secroots";
allow-query { any; }; //localhost改為any
(3)對(duì)DNS服務(wù)的區(qū)域配置文件進(jìn)行修改。
[root@localhost ~]# vim /etc/named.rfc1912.zones
zone "abc.com" IN { //添加一個(gè)域名信息
type master;
file "abc.com.zone";
allow-update { none; };
};
(4)查看一下IP地址。
[root@localhost named]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.52.133 netmask 255.255.255.0 broadcast 192.168.52.255
inet6 fe80::3e1d:31ba:f66a:6f80 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:27:1c:3f txqueuelen 1000 (Ethernet)
RX packets 14532 bytes 20210558 (19.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 6054 bytes 399142 (389.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
(5)保留權(quán)限復(fù)制一份DNS服務(wù)的區(qū)域數(shù)據(jù)配置文件,進(jìn)行修改。
[root@localhost ~]# cd /var/named/ //切換目錄
[root@localhost named]# ls //查看
data dynamic named.ca named.empty named.localhost named.loopback slaves
[root@localhost named]# cp -p named.localhost abc.com.zone //復(fù)制
[root@localhost named]# vim abc.com.zone
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 127.0.0.1
www IN A 192.168.52.133 //添加IPv4的域名解析
(6)開(kāi)啟named服務(wù)。
[root@localhost named]# systemctl start named //開(kāi)啟服務(wù)
[root@localhost named]# systemctl stop firewalld.service //關(guān)閉防火墻
[root@localhost named]# setenforce 0 //關(guān)閉增強(qiáng)性安全功能
[root@localhost named]#
(7)在宿主機(jī)將我們所需的工具包共享出去。
(8)通過(guò)Samba服務(wù)將工具包掛載到Linux系統(tǒng)。
[root@localhost ~]# smbclient -L //192.168.100.50/ //查看共享
Enter SAMBA\root's password: //匿名共享,沒(méi)有密碼,直接回車
OS=[Windows 10 Enterprise LTSC 2019 17763] Server=[Windows 10 Enterprise LTSC 2019 6.3]
Sharename Type Comment
--------- ---- -------
IPC$ IPC 遠(yuǎn)程 IPC
share Disk
tools Disk
Users Disk
Connection to 192.168.100.50 failed (Error NT_STATUS_RESOURCE_NAME_NOT_FOUND)
NetBIOS over TCP disabled -- no workgroup available
[root@localhost ~]# mkdir /mnt/tools //創(chuàng)建掛載目錄
[root@localhost ~]# mount.cifs //192.168.100.50/tools /mnt/tools/ //掛載
Password for root@//192.168.100.50/tools:
[root@localhost ~]# cd /mnt/tools/ //進(jìn)入掛載目錄
[root@localhost tools]# ls //查看
awstats-7.6.tar.gz extundelete-0.2.4.tar.bz2 forbid.png jdk-8u191-windows-x64.zip LAMP-C7
cronolog-1.6.2-14.el7.x86_64.rpm fiddler.exe intellijideahahau2018.rar john-1.8.0.tar.gz picture.jpg
[root@localhost tools]#
(9)將源碼編譯安裝Apache服務(wù)的壓縮包解壓到“/opt/”目錄。
[root@localhost tools]# cd LAMP-C7/ //切換目錄
[root@localhost LAMP-C7]# ls
apr-1.6.2.tar.gz Discuz_X2.5_SC_UTF8.zip LAMP-php5.6.txt php-5.6.11.tar.bz2
apr-util-1.6.0.tar.gz httpd-2.4.29.tar.bz2 MySQL-5.6.26.tar.gz
[root@localhost LAMP-C7]# tar jxvf httpd-2.4.29.tar.bz2 -C /opt/ //解壓
......//省略解壓詳情
[root@localhost LAMP-C7]# tar zxvf apr-1.6.2.tar.gz -C /opt/ //解壓
......//省略解壓詳情
[root@localhost LAMP-C7]# tar zxvf apr-util-1.6.0.tar.gz -C /opt/ //解壓
......//省略解壓詳情
(10)進(jìn)入“/opt/”目錄,將兩個(gè)apr包移動(dòng)到“httpd-2.4.29/srclib/”目錄,并重命名。
[root@localhost LAMP-C7]# cd /opt/
[root@localhost opt]# ls
apr-1.6.2 apr-util-1.6.0 httpd-2.4.29 rh
[root@localhost opt]# mv apr-1.6.2/ httpd-2.4.29/srclib/apr
[root@localhost opt]# mv apr-util-1.6.0/ httpd-2.4.29/srclib/apr-util
(11)進(jìn)入“httpd-2.4.29/”目錄,然后安裝編譯所需環(huán)境包。
[root@localhost opt]# ls
httpd-2.4.29 rh
[root@localhost opt]# cd httpd-2.4.29/
[root@localhost httpd-2.4.29]# ls
ABOUT_APACHE ap.d CHANGES docs httpd.spec libhttpd.dep Makefile.win README srclib
acinclude.m4 build CMakeLists.txt emacs-style include libhttpd.dsp modules README.cmake support
Apache-apr2.dsw BuildAll.dsp config.layout httpd.dep INSTALL libhttpd.mak NOTICE README.platforms test
Apache.dsw BuildBin.dsp configure httpd.dsp InstallBin.dsp LICENSE NWGNUmakefile ROADMAP VERSIONING
apache_probes.d buildconf configure.in httpd.mak LAYOUT Makefile.in os server
[root@localhost httpd-2.4.29]#
[root@localhost httpd-2.4.29]# yum -y install \
> gcc \
> gcc-c++ \
> make \
> pcre \
> pcre-devel \
> expat-devel \
> zlib-devel \
> perl
......//省略安裝過(guò)程
(12)進(jìn)行對(duì)Apache服務(wù)器的配置。
[root@localhost httpd-2.4.29]# ./configure \
> --prefix=/usr/local/httpd \ //安裝路徑
> --enable-deflate \ //啟用壓縮模塊支持
> --enable-expires \ //啟用緩存模塊支持
> --enable-so \ //啟用動(dòng)態(tài)加載模塊支持
> --enable-rewrite \ //啟用網(wǎng)頁(yè)地址重寫(xiě)功能
> --enable-charset-lite \ //啟用字符集支持
> --enable-cgi //啟用CGI腳本程序支持
(13)編譯安裝Apache服務(wù)。
[root@localhost httpd-2.4.29]# make && make install
......//省略編譯安裝過(guò)程
[root@localhost httpd-2.4.29]#
(14)對(duì)Apache服務(wù)配置文件進(jìn)行修改
[root@localhost httpd-2.4.29]# ln -s /usr/local/httpd/conf/httpd.conf /etc/httpd.conf //創(chuàng)建軟鏈接,方便使用
[root@localhost httpd-2.4.29]#
Listen 192.168.50.133:80 //開(kāi)啟IPv4監(jiān)聽(tīng)
#Listen 80 //注釋IPv6監(jiān)聽(tīng)
#
ServerName www.abc.com:80 //設(shè)置域名
(15)將“/mnt/tools/”目錄下的兩張圖片,復(fù)制到Apache服務(wù)站點(diǎn)目錄“/usr/local/httpd/htdocs/”下。
[root@localhost httpd-2.4.29]# cd /mnt/tools/
[root@localhost tools]# ls
awstats-7.6.tar.gz extundelete-0.2.4.tar.bz2 forbid.png jdk-8u191-windows-x64.zip LAMP-C7
cronolog-1.6.2-14.el7.x86_64.rpm fiddler.exe intellijideahahau2018.rar john-1.8.0.tar.gz picture.jpg
[root@localhost tools]# cp picture.jpg /usr/local/httpd/htdocs/
[root@localhost tools]# cp forbid.png /usr/local/httpd/htdocs/
[root@localhost tools]# cd /usr/local/httpd/htdocs/
[root@localhost htdocs]# ls
forbid.png index.html picture.jpg
[root@localhost htdocs]#
(16)修改主頁(yè)文件,將圖片“picture.jpg”添加到首頁(yè)。
[root@localhost htdocs]# vim index.html
<html><body><h2>It works!</h2>
<img src="picture.jpg"/>
</body></html>
(17)將“/usr/local/httpd/bin/”目錄下的“apachectl”文件移動(dòng)到“/etc/init.d/”目錄下,并在文件開(kāi)頭添加chkconfig識(shí)別配置,然后將其添加為標(biāo)準(zhǔn)的Linux系統(tǒng)服務(wù)
[root@localhost htdocs]# cd /opt/httpd-2.4.29/ //切換目錄
[root@localhost httpd-2.4.29]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd //復(fù)制
[root@localhost httpd-2.4.29]# vim /etc/init.d/httpd //在配置文件添加兩行聲明
# chkconfig: 35 85 21 //服務(wù)識(shí)別參數(shù),在級(jí)別3、5中啟動(dòng):?jiǎn)?dòng)和關(guān)閉的順序分別為85、21
# description: Apache is a World Wide Web server //服務(wù)描述信息
[root@localhost httpd-2.4.29]# chkconfig --add httpd //將httpd服務(wù)添加為系統(tǒng)服務(wù)
[root@localhost httpd-2.4.29]#
[root@localhost httpd-2.4.29]# ln -s /usr/local/httpd/bin/* /usr/local/bin/ //將Apache服務(wù)的命令文件,建立軟鏈接到易于系統(tǒng)識(shí)別的目錄
[root@localhost htdocs]# apachectl -t //檢查Apache服務(wù)配置文件格式
Syntax OK //格式正確
[root@localhost httpd-2.4.29]# service httpd start //啟動(dòng)Apache服務(wù)
[root@localhost httpd-2.4.29]#
(18)我們將win10-1主機(jī)的DNS地址改為L(zhǎng)inux系統(tǒng)的IP地址,然后去訪問(wèn)域名“www.abc.com”,訪問(wèn)成功。
(19)再給win10-2主機(jī)配置靜態(tài)IP地址,與LinuxIP地址同網(wǎng)段。然后配置DNS地址為L(zhǎng)inux系統(tǒng)IP地址。然后訪問(wèn)域名“www.abc.com”,訪問(wèn)成功。
(20)右擊圖片,點(diǎn)擊屬性。獲取圖片的URL,復(fù)制下來(lái)。
(21)進(jìn)入控制面板,按下列圖片進(jìn)行操作,在win10-2主機(jī)搭建web服務(wù)。
(22)新建一個(gè)TXT文本文件,輸入下圖的內(nèi)容。然后保存,更改文件名為“index.html”。并將其移動(dòng)到web服務(wù)的默認(rèn)站點(diǎn)目錄內(nèi)。
(23)我們?cè)儆脀in10-1主機(jī)去訪問(wèn),win10-2主機(jī)搭建的站點(diǎn),可以看到成功盜鏈的“www.abc.com”站點(diǎn)的圖片。
(24)對(duì)Apache服務(wù)配置文件進(jìn)行修改,用“ / ”查找關(guān)鍵詞“rewrite”,將“ # ”刪除,開(kāi)啟防盜鏈模塊。然后在下面的標(biāo)簽內(nèi)添加規(guī)則。
[root@localhost httpd-2.4.29]# vim /etc/httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so //開(kāi)啟防盜鏈模塊
DocumentRoot "/usr/local/httpd/htdocs"
<Directory "/usr/local/httpd/htdocs"> //標(biāo)簽最后添加規(guī)則
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Require all granted
RewriteEngine On //以下為規(guī)則
RewriteCond %{HTTP_REFERER} !^http://abc.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://abc.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.abc.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.abc.com/$ [NC]
RewriteRule .*\.(gif|jpg|swf)$ http://www.abc.com/forbid.png //跳轉(zhuǎn)到我們的防盜鏈圖片
</Directory>
(25)重啟Apache服務(wù)。
[root@localhost httpd-2.4.29]# service httpd stop
[root@localhost httpd-2.4.29]# service httpd start
[root@localhost httpd-2.4.29]#
(26)用win10-1主機(jī)分別訪問(wèn),Linux系統(tǒng)的域名為“www.abc.com”的站點(diǎn),和win10-2主機(jī)的站點(diǎn)。
此時(shí)win10-2主機(jī)已經(jīng)不能盜鏈圖片。
Apache的版本信息,透露了一定的漏洞信息,從而給網(wǎng)站帶來(lái)安全隱患
生產(chǎn)環(huán)境中要配置Apache隱藏版本信息
(1)接著上個(gè)實(shí)驗(yàn)往下做,我們用win10-1主機(jī)去訪問(wèn)“www.abc.com”站點(diǎn)。同時(shí)用Fiddler抓包工具進(jìn)行抓包。此時(shí)我們?cè)貶eaders里可以看到Apache的版本號(hào)。
(2)對(duì)Apache服務(wù)主配置文件進(jìn)行修改,開(kāi)啟子配置文件。
[root@localhost httpd-2.4.29]# vim /etc/httpd.conf
# Various default settings
Include conf/extra/httpd-default.conf //開(kāi)啟子配置文件
(3)進(jìn)入默認(rèn)子配置文件,修改配置文件。然后重啟Apache服務(wù)。
[root@localhost httpd-2.4.29]# cd /usr/local/httpd/conf/ //切換目錄
[root@localhost conf]# ls //查看
extra httpd.conf magic mime.types original
[root@localhost conf]# cd extra/ //切換目錄
[root@localhost extra]# ls //查看
httpd-autoindex.conf httpd-default.conf httpd-languages.conf httpd-mpm.conf httpd-ssl.conf httpd-vhosts.conf
httpd-dav.conf httpd-info.conf httpd-manual.conf httpd-multilang-errordoc.conf httpd-userdir.conf proxy-html.conf
[root@localhost extra]# vim httpd-default.conf //編輯配置文件
#
# ServerTokens
# This directive configures what you return as the Server HTTP response
# Header. The default is 'Full' which sends information about the OS-Type
# and compiled in modules.
# Set to one of: Full | OS | Minor | Minimal | Major | Prod
# where Full conveys the most information, and Prod the least.
#
ServerTokens Prod //將Full該為Pord
#
# Optionally add a line containing the server version and virtual host
# name to server-generated pages (internal error documents, FTP directory
# listings, mod_status and mod_info output etc., but not CGI generated
# documents or custom error documents).
# Set to "EMail" to also include a mailto: link to the ServerAdmin.
# Set to one of: On | Off | EMail
#
ServerSignature Off //關(guān)閉簽名(默認(rèn)關(guān)閉)
[root@localhost extra]# service httpd stop //關(guān)閉服務(wù)
[root@localhost extra]# service httpd start //開(kāi)啟服務(wù)
[root@localhost extra]#
(4)再次用win10-1主機(jī)訪問(wèn)站點(diǎn),查看Fiddler抓包工具抓取的數(shù)據(jù)包頭部,此時(shí)Apache服務(wù)的版本號(hào)已經(jīng)隱藏。
網(wǎng)頁(yè)名稱:Apache網(wǎng)頁(yè)優(yōu)化(二)--------防盜鏈和隱藏版本
URL鏈接:http://jinyejixie.com/article44/pochhe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開(kāi)發(fā)、網(wǎng)站建設(shè)、建站公司、網(wǎng)站收錄、軟件開(kāi)發(fā)、營(yíng)銷型網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)