Apache Web Server 보안관련 module 설치하기
1. DDoS Attack 막기 - mod_evasive 설치
$ sudo apt-get install libapache2-mod-evasive
module은 자동으로 enabled 된다. ( 필요한경우 a2enmod mod-evasive 를 실행 )
$ sudo vi /etc/apache2/conf.d/mod-evasive
다음과 같이 config 파일을 생성해준다.
<ifmodule mod_evasive20.c>
DOSHashTableSize 3097
DOSPageCount 2
DOSSiteCount 50
DOSPageInterval 1
DOSSiteInterval 1
DOSBlockingPeriod 10
DOSEmailNotify your.email@yahoo.com
DOSLogDir /var/log/mod-evasive
#DOSWhitelist 127.0.0.*
</ifmodule>
mod-evasive 파일에서 지정한 DOSLogDir(log directory) 를 생성해준다.
$ sudo mkdir /var/log/mod-evasive
$ sudo chown -R www-data:www-data /var/log/mod-evasive
apache를 재시작한다.
mod_evasive 작동을 Test 하기 위해서 /var/www 디렉토리를 웹 브러우져에서 호출하고 refreshe(F5 key를 계속 눌러본다) 해보면
Forbidden
You don’t have permission to access / on this server.
라는 메세지가 나오면 정상적으로 작동하는 것이다. /var/log/mod-evasive/dos-ip…. 라는 파일이 생성되어 있는 것을 볼 수 있을 것이다.
2. mod_security 설치하기
$ sudo apt-get install libapache-mod-security
$ sudo vi /etc/apache2/conf.d/mod-security
<IfModule security2_module>
Include modsecurity-rules/*.conf
Include modsecurity-rules/base_rules/*.conf
</IfModule>
$ sudo mkdir /etc/apache2/modsecurity-rules
$ cd
$ wget http://downloads.sourceforge.net/project/mod-security/modsecurity-apache/2.5.12/modsecurity-apache_2.5.12.tar.gz
$ tar zxvf modsecurity-apache_2.5.12.tar.gz
압축을 해제하고 /rules 에 있는 모든것을 /etc/apache2/modsecurity-rules 로 복사하고 불필요한 파일(CHANGELOG LICENSE READ util)을 삭제한다.
Apache를 재시작 한다.
mod_security가 재대로 설치되었는지 다음과 같이 확인해 본다.
$ vi /var/www/indecured.php
<?php
$secret_file = $_GET['secret_file'];
include ( $secret_file);
?>
파일을 생성하고 웹브라우져에서 스크립트를 실행해 본다.
http://localhost/insecured.php?secret_file=/etc/passwd
스크립트를 실행했을 때 다음과 같이 나오면 설치가 된것이다.
Forbidden
You don’t have permission to access /insecure.php on this server.









Leave your response!