有这样一种情况,有些站点和论坛是允许上传图片到服务器,但是这就给黑客留下了可进入服务器的大门,他们上传一些php或者js到服务器,然后被我们执行加载,有些函数可以让黑客获取最大的权限,从而对数据造成威胁!
为了避免这种事情的发生,我们需要限制上传类型。1. 打开配置文件 httpd-vhosts.conf
在虚拟服务器中增加如下配置:
[root@xavi ~]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
<Directory /data/wwwroot/xavi.com/upload>
php_admin_flag engine off //禁止php解析,所有访问都报403错误
<FilesMatch (.*)\.php(.*)>//需要转义字符
Order allow,deny //不加deny,它会访问源代码
Deny from all
</FilesMatch>
[root@xavi ~]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@xavi ~]# /usr/local/apache2.4/bin/apachectl graceful
httpd not running, trying to start
[root@xavi ~]# /usr/local/apache2.4/bin/apachectl start
httpd (pid 2838) already running
[root@xavi ~]# /usr/local/apache2.4/bin/apachectl graceful
[root@xavi ~]# mkdir upload
[root@xavi ~]# ls
123.txt anaconda-ks.cfg httpd-2.4.29.tar.gz rsync test2
321.txt awk index.php sed upload
556.txt grep initial-setup-ks.cfg split_dir xaa
admin httpd-2.4.29 [root@localhost test1
[root@xavi ~]# cp index.php upload/
[root@xavi ~]# curl -x127.0.0.1:80 ‘http://xavi.cpm
[root@xavi ~]# curl -x127.0.0.1:80 ‘http://xavi.com/admin.php?adadede‘ -I
HTTP/1.1 404 Not Found
Date: Sun, 11 Mar 2018 03:33:57 GMT
Server: Apache/2.4.29 (Unix) PHP/7.1.6
Content-Type: text/html; charset=iso-8859-1
这里之所以没有得到403 fobiden的提示,是因为在练习测试过程我忽略了,指令执行的环境。[root@xavi xavi.com]上述操作正确的过程是应该在/xavi.comde 文件夹下操作,而不是在默认的文件路径下
以下是重新操作的过程
[root@xavi ~]# cd /data/wwwroot/xavi.com
[root@xavi xavi.com]# ls
123.php admin index.php xavi.jpg xavi.txt
[root@xavi xavi.com]# mkdir uplaod
[root@xavi xavi.com]# ls
123.php admin index.php uplaod xavi.jpg xavi.txt
[root@xavi xavi.com]# mv uplaod upload
[root@xavi xavi.com]# ls
123.php admin index.php upload xavi.jpg xavi.txt
[root@xavi xavi.com]# cp 123.php /upload
[root@xavi xavi.com]# !vim
vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
[root@xavi xavi.com]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@xavi xavi.com]# /usr/local/apache2.4/bin/apachectl graceful
[root@xavi xavi.com]# !curl
curl -x127.0.0.1:80 ‘http://xavi.com/upload/123.php‘ -I
HTTP/1.1 403 Forbidden
Date: Sun, 11 Mar 2018 05:31:04 GMT
Server: Apache/2.4.29 (Unix) PHP/7.1.6
Content-Type: text/html; charset=iso-8859-1
[root@xavi xavi.com]# !vim
vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
[root@xavi xavi.com]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@xavi xavi.com]# /usr/local/apache2.4/bin/apachectl graceful
[root@xavi xavi.com]# curl -x127.0.0.1:80 ‘http://xavi.com/upload/123.php‘
<?php
echo "123.php";
User Agent中文名为用户代理,简称 UA,它是一个特殊字符串头,使得服务器能够识别客户使用的操作系统及版本、CPU 类型、浏览器及版本、浏览器渲染引擎、浏览器语言、浏览器插件等。
cc攻击:是我们经常见到的最常见的一种攻击,几乎每天每个时段都会存在。CC攻击就是黑客利用所能利用的肉鸡(就是所谓的黑客利用技术手段攻击下来的他人服务器)去攻击(正常的访问)你的站点,导致你的站点不可以被正常的用户所浏览。但是也不是不可防止,在攻击的时候有一个规律的特征,user_agent是一致的(其referer和访问页面是一致的,并且在一秒内发动N次访问)!
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} .*curl.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*baidu.com.* [NC]
RewriteRule .* - [F]
</IfModule>
RewriteCond %{HTTP_USER_AGENT} .*curl.* [NC,OR] //匹配Curl的访问 [NC,OR] NC:忽略大小写。 OR:是或者的意思,要么这一条,要么下一条满足情况
RewriteCond %{HTTP_USER_AGENT} .*baidu.com.* [NC]
RewriteRule .* - [F] // F:Forbidden 禁止
[root@xavi xavi.com]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@xavi xavi.com]# /usr/local/apache2.4/bin/apachectl graceful
[root@xavi xavi.com]# curl -x127.0.0.1:80 ‘http://xavi.com/upload/123.php‘ -I
HTTP/1.1 403 Forbidden
Date: Sun, 11 Mar 2018 07:04:12 GMT
Server: Apache/2.4.29 (Unix) PHP/7.1.6
Content-Type: text/html; charset=iso-8859-1
[root@xavi xavi.com]# curl -A "xavilinux xavilinux" -x127.0.0.1:80 ‘http://xavi.com/123.php‘ -I
HTTP/1.1 200 OK
Date: Sun, 11 Mar 2018 07:21:42 GMT
Server: Apache/2.4.29 (Unix) PHP/7.1.6
X-Powered-By: PHP/7.1.6
Content-Type: text/html; charset=UTF-8
[root@xavi xavi.com]# tail /usr/local/apache2.4/logs/xavi.com-access_20180311.log
192.168.72.1 - - [11/Mar/2018:14:02:02 +0800] "GET /upload/123.php HTTP/1.1" 200 22 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36"
192.168.72.1 - - [11/Mar/2018:14:02:02 +0800] "GET /upload/123.php HTTP/1.1" 200 22 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36"
127.0.0.1 - - [11/Mar/2018:15:04:12 +0800] "HEAD http://xavi.com/upload/123.php HTTP/1.1" 403 - "-" "curl/7.29.0"
127.0.0.1 - - [11/Mar/2018:15:04:12 +0800] "HEAD http://xavi.com/upload/123.php HTTP/1.1" 403 - "-" "curl/7.29.0"
127.0.0.1 - - [11/Mar/2018:15:05:32 +0800] "GET http://xavi.com/upload/123.php HTTP/1.1" 403 223 "-" "curl/7.29.0"
127.0.0.1 - - [11/Mar/2018:15:05:32 +0800] "GET http://xavi.com/upload/123.php HTTP/1.1" 403 223 "-" "curl/7.29.0"
127.0.0.1 - - [11/Mar/2018:15:21:42 +0800] "HEAD http://xavi.com/123.php HTTP/1.1" 200 - "-" "xavilinux xavilinux"
127.0.0.1 - - [11/Mar/2018:15:21:42 +0800] "HEAD http://xavi.com/123.php HTTP/1.1" 200 - "-" "xavilinux xavilinux"
127.0.0.1 - - [11/Mar/2018:15:22:18 +0800] "GET http://xavi.com/123.php HTTP/1.1" 200 7 "-" "xavilinux xavilinux"
127.0.0.1 - - [11/Mar/2018:15:22:18 +0800] "GET http://xavi.com/123.php HTTP/1.1" 200 7 "-" "xavilinux xavilinux"
实用扩展:
apache 禁止trace或track防止xss攻击
http://ask.apelearn.com/question/1045
原文地址:http://blog.51cto.com/12995218/2085335