Apache implements hotlinking, hotlinking and hidden version information


To realize anti-leech, we must first understand the implementation principle of anti-leech. When it comes to the implementation principle of anti-leech, we have to start with the HTTP protocol. In the HTTP protocol, there is a header field called referer, which is in the format of URL. Indicates where to link to the current web page or file. In other words, through the referer, the website can detect the source page accessed by the target page, and if it is a resource file, it can track the address of the web page that displays it. With the referer tracking the source, it is easy to handle. At this time, it can be processed by technical means. Once it is detected that the source is not this site, it will be blocked or returned to the specified page.

1: Hotlink practical steps

For the host that provides website services, I have done DNS resolution and access it using the domain name www.abc.com

Client IP address: Hotlink machine IP address:

Server configuration

1.1: Configure DNS service

[root@localhost ~]# iptables -F
[root@localhost ~]# setenforce 0
#Configure DNS
[root@localhost ~]# yum -y install bind
  • Configure DNS Main Profile
options {
        listen-on port 53 { 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; };
  • configuration area
[root@localhost ~]# vim /etc/named.rfc1912.zones
zone "ab.com" IN {        type master;
        file "ab.com.zone";
        allow-update { none; };
  • Configure area data
[root@localhost ~]# cd /var/named/
[root@localhost named]# cp -p named.localhost ab.com.zone
[root@localhost named]# vim ab.com.zone

@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      @
www IN  A
#restart the service
[root@localhost named]# systemctl restart named

1.2: win 10 test dns resolution


1.3: First, you need to manually compile and install Apache

  • Extract the three packages into an empty folder /opt
[root@localhost opt]# tar zxvf apr-1.6.2.tar.gz
[root@localhost opt]# tar zxvf apr-util-1.6.0.tar.gz 
[root@localhost opt]# tar jxvf httpd-2.4.29.tar.bz2
#Copy the decompressed /apr-1.4.6 and /apr-util-1.4.1 folders to /httpd-2.4.2/srclib/ and name them apr and apr-util, apr-1.4.6 and  apr-util-1.4.1 can alleviate the concurrent connection process to a certain extent
[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
#Install the required basic environment packages with yum, including five packages: gcc, gcc-c++, make, pcre, and pcre-devel (pcre: a Perl library that supports regular expressions)
[root@localhost opt]# yum install gcc gcc-c++ pcre pcre-devel perl expat-devel zlib-devel
 exist/opt/httpd-2.4.29 Execute in the directory
[root@localhost httpd-2.4.29]# ./configure \
> --prefix=/usr/local/httpd \                       #installation path       
> --enable-deflate \
> --enable-so \                                     #Dynamic module loading
> --enable-rewrite \                                #rewrite directly
> --enable-charset-lite \                           #Enable character set
> --enable-cgi                                      #Enable generic gateway interface

1.4: make compile and install make install

[root@localhost httpd-2.4.29]# make '//compile'
...omit content
[root@localhost httpd-2.4.29]# make install '//install'
...omit content

1.5: Editing configuration files

  • It is convenient to manage here, you can establish a soft connection and directly edit the link file
[root@localhost httpd-2.4.29]# ln -s /usr/local/httpd/conf/httpd.conf  /etc/httpd.conf
[root@localhost httpd-2.4.29]# cd /usr/local/httpd/
[root@localhost httpd]# cd htdocs/
[root@localhost htdocs]# ls
#copy a picture
[root@localhost htdocs]# rz -E
rz waiting to receive.
[root@localhost htdocs]# ls
1389753641370.jpg  index.html
[root@localhost htdocs]# vim index.html
#Write homepage information
<html><body><h1>It works!</h1></body></html>
<img src="1389753641370.jpg"/>

#Set the listening address Enter the machine IP Address, which means listening to the machine IP Add address below port 80#Note is to listen on IPv6
#Listen 80
#set domain name
ServerName www.shuai.com:80
##start the service
[root@localhost htdocs]# cd ..
[root@localhost httpd]# cd bin/
#turn off service on
[root@localhost bin]# ./apachectl stop
#The port is not open when shutting down the service
[root@localhost bin]# netstat -ntap | grep httpd
#open port
[root@localhost bin]# ./apachectl start
[root@localhost bin]# netstat -ntap | grep httpd
tcp        0      0  *               LISTEN      121958/httpd        

1.6: The client test accesses its main home page normally

Two: hotlink host settings

2.1: Prepare the environment

[root@localhost ~]# iptables -F
[root@localhost ~]# setenforce 0
[root@localhost ~]# yum install httpd -y

2.2: Modify the listening address and domain name

#listen address
#Listen 80
#set domain name
ServerName www.shuai.com:80

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf 
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# vim index.html 

<img src="http://www.ab.com/1389753641370.jpg"/>

[root@localhost html]# echo "nameserver" > /etc/resolv.conf

2.3: Restart the service

[root@localhost html]# systemctl start httpd.service
[root@localhost html]# netstat -ntap | grep httpd
tcp        0      0  *               LISTEN      21810/httpd 

2.4: Conduct a hotlink test

Three: The normal host opens the anti-leech function

Apache The realization method of anti-theft chain, you can use rewrite accomplish
 Make sure it's on rewrite module configure
#/Search for rewrite to open the rewrite module
LoadModule rewrite_module modules/mod_rewrite.so
##DocumenRoot is the site directory to configure later
DocumentRoot "/usr/local/httpd/htdocs"
Go to the last line and insert the following

 RewriteEngine On
    RewriteCond %{HTTP_REFERER} !^http://ab.com/.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://ab.com$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.ab.com/.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.ab.com$ [NC]
    RewriteRule .*\.(gif|jpg|swf)$ http://www.ab.com/MZY7BWZN(6~~KTS5MILYXAX.png

3.1: Configure site information

[root@localhost bin]# cd ..
[root@localhost httpd]# pwd
[root@localhost httpd]# cd htdocs/
[root@localhost htdocs]# ls
1389753641370.jpg  index.html
#copy an image
[root@localhost htdocs]# rz -E
rz waiting to receive.
[root@localhost htdocs]# ls
1389753641370.jpg  index.html  MZY7BWZN(6~~KTS5MILYXAX.png

[root@localhost htdocs]# cd ..
[root@localhost httpd]# cd bin/
#Service is off and on
[root@localhost bin]# ./apachectl stop
[root@localhost bin]# ./apachectl start

3.2: Check if you can hotlink

Anti-leech setting is successful

Four: Hide version information

Attackers often scan the version information of the software and then conduct targeted attacks. After the apache installation is completed, its version information should be hidden for the first time.

4.1: Configure Apache to hide version information

  • Apache version information, which discloses certain vulnerability information, thus giving
    Website brings security risks
  • To configure Apache to hide version information in the production environment

4.2: Modify version information

  • Uncomment the following lines in the main configuration file httpd.conf
[root@localhost conf]# pwd
[root@localhost conf]# vim httpd.conf
#/Search Include conf uncomment
Include conf/extra/httpd-default.conf

[root@localhost conf]# cd extra/
[root@localhost extra]# ls
httpd-autoindex.conf  httpd-mpm.conf
httpd-dav.conf        httpd-multilang-errordoc.conf
httpd-default.conf    httpd-ssl.conf
httpd-info.conf       httpd-userdir.conf
httpd-languages.conf  httpd-vhosts.conf
httpd-manual.conf     proxy-html.conf
[root@localhost extra]# vim httpd-default.conf 
#/Token search is modified to
ServerTokens Prod       #software name only
##restart the service
[root@localhost extra]# cd ..
[root@localhost conf]# cd ..
[root@localhost httpd]# cd bin/
[root@localhost bin]# ./apachectl stop
[root@localhost bin]# ./apachectl start

4.3: Access Verification

The karma is diligent, the waste is in the play; the action is achieved in the thinking, and the destruction is in the follow-up.

Tags: Apache

Posted by Eiolon on Mon, 23 May 2022 03:11:55 +0300