You cannot see this page without javascript.

modsecurity

Linux 조회 수 475 추천 수 0 2017.12.06 10:06:59

1. 의존라이브러리 설치


yum -y install gcc-c++ libxml2 libxml2-devel httpd-devel apr-devel apr-util pcre-devel

 
 1-2 pcre / pcre-devel
  ./configure --prefix=/usr/local/pcre
  make
  make install


 1-3 mod_unique_id.so
  apache source file => /modules/metadata
  apxs -cia mod_unique_id.c
 


2. modsecurity 설치

 
 2-1 modsecurity
 ./configure --with-apxs=/usr/sbin/apxs --with-apr=/usr/bin/apr-1-config --with-apu=/usr/bin/apu-1-config --with-pcre=/usr/bin/
 make
 make install
 

 2-2 httpd.conf
 vi /etc/httpd/conf/httpd.conf


 LoadModule unique_id_module /usr/lib/httpd/modules/mod_unique_id.so
 LoadFile /usr/lib/libxml2.so
 LoadModule security2_module modules/mod_security2.so
 include conf.d/modsecurity/modsecurity.conf


 

 

 2-3 modsecurity.conf 적용
 /etc/httpd/conf/modsecurity.conf


 2-4 apache restart

 

 

 

 

 

ModSecurity-console

 

 

3. modsecurity-console 설치

 3-1 JDK 1.4버전 이상 설치
 ./jdk.bin

 

 3-1-1 JDK 설정
  ln -s [JDK설치 디렉토리] /usr/local/java

  vi /etc/profile

 

  JAVA_HOME=/usr/local/java

 

  pathmunge $JAVA_HOME/bin 

  export JAVA_HOME


 

 

  source /etc/profile

 

  3-2 modconsole port open(default 8886)
  vi /etc/sysconfig/ipstables


  #Modsecurity-Console
  -A RH-Firewall-1-INPUT -p tcp --dport 8886 -j ACCEPT
  -A RH-Firewall-1-INPUT -p tcp --sport 8886 -j ACCEPT
  -A RH-Firewall-1-OUTPUT -p tcp --dport 8886 -j ACCEPT
  -A RH-Firewall-1-OUTPUT -p tcp --sport 8886 -j ACCEPT



 

 

 3-3 Install

 

 3-3-1 mod-console source
 tar zxvf modconsole.tar.gz
 vi modconsole/etc/console.conf.default 설정 확인

 

 Property port "8886"

 



 ln -s [modsecurity-console 디렉토리]/modsecurity-console /usr/sbin/modsecurity-console
 modsecurity-console start

 

 

 

 3-3-2 mod-console RPM
 rpm -Uvh modsecurity-console_1_0_5_linux.rpm
 modsecurity-console start

 
 3-4 Lisence / Sensor Add

 

 

 

 

4. modsec-auditlog-collector.pl

 4-1 mkdir /etc/httpd/logs/data
  chmod 705 /var/log/httpd
  chmod 750 /var/log/httpd/data
  chown apache.apache /var/log/httpd/data

 
 4-2 cp modsec-auditlog-collector.pl /usr/local/bin
  vi modsec-auditlog-collector.pl

 


 

 

  my $CONSOLE_URI = "/rpc/auditLogReceiver";
  my $CONSOLE_HOST = "192.168.0.66";
  my $CONSOLE_PORT = "8886";
  my $CONSOLE_USERNAME = "[Sensor]";
  my $CONSOLE_PASSWORD = "[SensorPW]";

 


 

 

  4-3 vi /etc/httpd/conf/modsecurity.conf

 


 

  # 로그 파일 구조
  SecAuditLogType Concurrent
  SecDataDir /etc/httpd/logs/data
  SecAuditLogStorageDir /etc/httpd/logs/data
  SecAuditLog "|/usr/local/bin/modsec-auditlog-collector.pl /etc/httpd/logs/data/ /etc/httpd/logs/modsec_audit.log

  # 로그에 남길 부분
  SecAuditLogParts "ABFHZ

 



  modsecurity-console stop
  modsecurity-console start

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ModSecurity 설치도중 에러 발생시 Tip

 

pcre 설치시 gcc / g++ 필요

=> gcc / gcc-c++ 설치( yum )

 

apxs / apr / apu / pcre 가 없거나 찾지못해서 configure error

 => apxs / apr / apu 없을시 : httpd-devel / apr-devel / apr-util 설치

 => pcre : source

 => 경로를 지정해줌 (which apxs apr-1-config apu-1-config)  : --with-apxs=/usr/sbin/apxs --with-apr=/usr/bin/apr-1-config --with-apu=/usr/bin/apu-1-config --with-pcre=/usr/local/pcre

 

libxml2 / libxml2-devel 이 없어서 configure error

=> yum설치

 

------------------------------------------------------------------------------------

yum -y install gcc-c++ libxml libxml2 httpd-devel apr-devel apr-util

 

 

 

httpd.conf에 모듈 적재 후 아파치 재시작 시 ServerName error

=> /etc/sysconfig/network 에 HOSTNAME=localhost 로 수정 or setup에서 수정

=> 안되면 httpd.conf에 #ServerName 127.0.0.1로 수정

 

아파치 재시작 후 modsecurity가 패턴매치를 못하고 비정상 작동

=> modsec_audit.log엔 log가 남지 않고 error_log를 확인하면 mod_unique_id 모듈을 요청.

=>해당 아파치 소스파일/modules/metadata 에서 apxs -cia mod_unique_id.c (httpd.conf에 모듈 자동 적재)

=>아파치 재시작

 

/etc/httpd/logs/data (/var/log/httpd/data)아래에 log 생성시 httpd /  data의 퍼미션을 755 

 

엮인글 :
List of Articles
번호 제목 글쓴이 날짜 조회 수sort

XE Login