본문 바로가기
server/Cent_os

ModSecurity (owasp core rule) setting

설치 환경
OS           :  CentOs 5.9 64BIT
APACHE   :  Apache/2.2.17
MYSQL     :  Mysql 5.0.45
PHP          :  PHP 5.2.17

ModSecurity 설치를 위한 의존성 라이브러리 설치

[root@localhost src]# yum -y install libxml2 libxml2-devel httpd-devel pcre-devel curl-devel



ModSecurity 설치

[root@localhost / ]# cd /usr/local/src
[root@localhost src]# wget https://www.modsecurity.org/tarball/2.8.0/modsecurity-2.8.0.tar.gz
(최신 버전 다운 로드 https://www.modsecurity.org/download.html 
다운이 안될 경우 직접 링크로 가서 다운 후 직접 이동 해야함)

[root@localhost src]# tar xzvf modsecurity-2.8.0.tar.gz 
[root@localhost src]# cd modsecurity-2.8.0
[root@localhost modsecurity-2.8.0]#
./configure \
--with-apr=/usr/local/apache/bin/apr-1-config \
--with-apu=/usr/local/apache/bin/apu-1-config

여기서 에러 많이 나고 있음!!!!!! 


configure: error: NOTE: libxml2 library must be at least 2.6.29
--> libxml2버전이 2.6.29 이하일 경우 에러가 나옴


[root@localhost modsecurity-2.8.0]# rpm -qa | grep libxml2-2.*
libxml2-2.6.26-2.1.21.el5_9.3
libxml2-2.6.26-2.1.21.el5_9.3


[root@localhost modsecurity-2.8.0]# cd /usr/local/src
[root@localhost src]# wget ftp://xmlsoft.org/libxml2/libxml2-2.7.7.tar.gz
[root@localhost src]# tar xvzf libxml2-2.7.7.tar.gz 
[root@localhost src]# cd libxml2-2.7.7
[root@localhost libxml2-2.7.7]# ./configure --prefix=/usr/local/xml 
[root@localhost libxml2-2.7.7]# make && make install

정상적으로 설치 되었다면 아래와 같은 모듈이 있어야 함!! 
안되어 있을 경우 에러 처리해야함
[root@localhost modsecurity-2.8.0]make && make install
[root@localhost modsecurity-2.8.0]# ls -alH /usr/local/apache/modules/mod_security2.so
-r--r--r-- 1 root root 2050703 11월  5 09:29 /usr/local/apache/modules/mod_security2.so

modsecurity.conf 복사 
[root@localhost modsecurity-crs]# cp /usr/local/src/modsecurity-2.8.0/modsecurity.conf-recommended  /usr/local/apache/conf/modsecurity.conf



OWASP Core rule 추가 

[root@localhost modsecurity-2.8.0]# cd /usr/local/apache/

[root@localhost apache]# git clone https://github.com/SpiderLabs/owasp-modsecurity-crs.git
[root@localhost apache]# mv owasp-modsecurity-crs modsecurity-crs
[root@localhost apache]# cd modsecurity-crs/

기본 룰 에서 필요한 룰만 activated_rules 에 복사 한다.
[root@localhost modsecurity-crs]# cp -aR base_rules/modsecurity_40_generic_attacks.data activated_rules/
[root@localhost modsecurity-crs]# cp -aR base_rules/modsecurity_crs_41_xss_attacks.conf activated_rules/
[root@localhost modsecurity-crs]# cp -aR base_rules/modsecurity_crs_41_sql_injection_attacks.conf activated_rules/
[root@localhost modsecurity-crs]# cp -aR base_rules/modsecurity_crs_45_trojans.conf activated_rules/  
[root@localhost modsecurity-crs]# mv modsecurity-crs/modsecurity_crs_10_setup.conf.example  modsecurity-crs/modsecurity_crs_10_config.conf


아래 지시자 추가

[root@localhost modsecurity-2.8.0]# vi /usr/local/apache/conf/httpd.conf

## Load mod_security ###################################
LoadModule security2_module modules/mod_security2.so
Include conf/modsecurity.conf

<IfModule security2_module>
    Include modsecurity-crs/modsecurity_crs_10_config.conf
    Include modsecurity-crs/activated_rules/*.conf
</IfModule>

##########################################################

아래와 같이 SecRuleEngine DetectionOnly 되어 있을 경우 Detection mode 로 작동 on으로 변경후 아파치 재시작 해야 정상적으로 탐지 차단이 됨
 
[root@localhost apache]# vi /usr/local/apache/conf/modsecurity.conf 



  1 # -- Rule engine initialization ----------------------------------------------
  2
  3 # Enable ModSecurity, attaching it to every transaction. Use detection
  4 # only to start with, because that minimises the chances of post-installation
  5 # disruption.
  6 #
  7 SecRuleEngine DetectionOnly




[root@localhost apache]# /usr/local/apache/bin/apachectl restart

### 아래와 같이 서버에 웹쉘을 삽입 한후 적용 되는것을 확인 (현재 탐지만 진행)

 
적용후 아래와 같이 거부 되는것을 확인 

  로그로도 확인 가능하다.

 [root@localhost apache]# tail -f /var/log/modsec_audit.log

 

위상황은 테스트 환경에서 웹쉘 삽입을 통한, 테스트를 진행 하였다.
하지만, 실제 운영상의 웹서버 적용시 많은 오탐이 발생 할 수 있으므로 적용은 충분한 오탐 확인 및 테스트를 진행후
적용 하는 것이 좋다.


##WhiteList 추가


아이피 마다 ID값을 다르게 해야함!!(대역대도 가능 테스트 완료)
[root@localhost modsecurity-crs]# vi ../conf/modsecurity.conf
SecRule REMOTE_ADDR "^192.168.119.1$"  phase:1,nolog,allow,id:123412345,ctl:ruleEngine=Off


반응형

'server > Cent_os' 카테고리의 다른 글

cent os local_port_range 확장  (0) 2016.03.12
Telegram_cli를 이용한 centos cil 메신저 이용하기  (0) 2016.03.03
centos nat lvs구성  (0) 2015.05.27
geo-ip setting  (0) 2015.05.27
glusterfs3.5 설치  (0) 2015.05.27