CentOS 5.0에 apache방화벽 Modsecurity 설치 > server

본문 바로가기
사이트 내 전체검색

server

CentOS 5.0에 apache방화벽 Modsecurity 설치

페이지 정보

작성자 서방님 댓글 0건 조회 165회 작성일 12-01-09 16:33

본문

 
몇일전 관리하는 사이트인 포리터가 웹해킹을 당해서 사이트가 안뜨는 사태가 발생하였다.
cafe24.com의 한 호스트에서 클라이언트로 파일을 밀어서 까는 방식의 트로이형태의 코드가 사이트 어딘가에
삽입된듯하다.. DB와 각 파일들을 뒤져보았으나 찾지못하였다.
장기적으로 찾아보려고 하고는 있다.

서버에대한 보안은 철통같이 한듯하지만.. 웹에서 뚤리는건 생각을 안하고 있었다.
이번사태로 웹방화벽을 설치해보자는 생각에 무료 웹서버보안툴인 ModSecurity를 설치해보았다.

Modsecurity는 http://www.modsecurity.org에서 무료로 다운로드 할수 있다.
modsecurity-apache_2.1.1.tar.gz 파일을 다운로드하여 /usr/local/src/내에서 풀었다.

# tar -zxvf modsecurity-apache_2.1.1.tar.gz
# cd modsecurity-apache_2.1.1

기존의 관련문서를보니 DSO설치와 소스컴파일 설치 두가지가 있다..
네이버 정보보안카페의 홍석범|오늘과내일차장 님이 쓰신글이 있는데 그 글을 보니
1.x버전은 2가지 방식을 지원하고 2.x부터는 DSO방식만 지원한단다..
apache1.x/apache2.x 모두 지원하는 1.x와
apache2.x만 지원하는 2.x 를 두고 고민했는데.. 머 새버전이니 좋은게 있겠지 하고 2.x를 깔았다.
doc폴더의 index.html파일을 웹으로 열어보면 인스톨방법이 나와있다.

아래는 installation 내용이다.
  • ModSecurity 2.x works with Apache 2.0.x or better.
  • Make sure you have mod_unique_id installed.
  • (Optional) Install the latest version of libxml2, if it isn't already installed on the server.
  • Unpack the ModSecurity archive
  • Edit Makefile to configure the path to the Apache ServerRoot directory. You can check this by identifying the ServerRoot directive setting in your httpd.conf file. This is the path that was specified with the "--install-path=" configuration flag during compilation (for example, in Fedora Core4: top_dir = /etc/httpd).
  • (Optional) Edit Makefile to enable ModSecurity to use libxml2 (uncomment line DEFS = -DWITH_LIBXML2) and configure the include path (for example: INCLUDES=-I/usr/include/libxml2)
  • Compile with make
  • Stop Apache
  • Install with make install
  • (Optional) Add one line to your configuration to load libxml2: LoadFile /usr/lib/libxml2.so
  • Add one line to your configuration to load ModSecurity: LoadModule security2_module modules/mod_security2.so
  • Configure ModSecurity
  • Start Apache
  • You now have ModSecurity 2.x up and running

# vi Makefile

top_dir      = /etc/httpd
rpm으로 깔았으니 아파치의 루트는 저렇게 된다.

#DEFS = -DWITH_LIBXML2 #
위에 부분을 주석처리 하였다.. 그냥 설치했더니 먼기 오류가 나서 아파치 실행이 안된다.
그냥 설치해도 된다면 그냥설치해보고 안된다면 주석처리해보라

# make
make가 안되고 /usr/lib/build/special.mk를 못찾는다고나온다면..
yum --enablerepo=centosplus install httpd-devel.i386
개발툴을 깔아줘라.. 깔아주는김에 php도 있는지 확인해보고 없으면 깔아 줘라..

# make install
make[1]: Entering directory '/usr/local/src/modsecurity-apache_2.1.1/apache2'
/bin/sh /usr/lib/apr/build/libtool --silent --mode=install cp mod_security2.la /usr/lib/httpd/modules
make[1]: Leaving directory '/usr/local/src/modsecurity-apache_2.1.1/apache2'
위처럼 나온다.

정상설치되면 /usr/lib/httpd/modules/mod_security2.so 파일이 생성된다.
다음 httpd.conf 파일에서 해당 파일을 로드모듈해줘야 한다.

#vi /etc/httpd/conf/httpd.conf
LoadFile /usr/lib/libxml2.so   #xml을 사용하나보다 libxml2가 깔려있는지 검사부터 하고 깔아야 한다.
LoadModule security2_module modules/mod_security2.so

# service httpd restart
Stopping httpd :              [OK]
Starting httpd :             [OK]
정상적으로 깔린거다..

기존버전 1.x는 httpd.conf 내에


의 중간에 옵션을 적어넣는게 기본으로 되어있지만 2.x부터는 rules의 폴더안에 기본적인 룰을 제공한다.

# mv /usr/local/src/modsecurity-apache_2.1.1/rules/ /etc/httpd/conf/
셋업폴더의 rules폴더를 아파치 conf폴더에 넣는다

# vi /etc/httpd/conf/httpd.conf
Include conf/rules/*.conf

# service httpd restart
정상적으로 된다면 다 깔린거다..

제대로 깔린것인지 확인하는 방법은
# vi modsecurity_crs_10_config.conf
적용된룰들중 10번 config파일을 열어서
#SecServerSignature "Apache/2.2.0 (Fedora)"
SecServerSignature "Microsoft-IIS/5.0"

위에부분을 Microsoft-IIS/5.0으로 바꾼후 아파치 제시작하고난후

 # curl --head http://127.0.0.1
HTTP/1.1 403 Forbidden
Date: Wed, 20 Jun 2007 08:00:40 GMT
Server: Microsoft-IIS/5.0
Accept-Ranges: bytes
Content-Length: 5044
Content-Type: text/html; charset=UTF-8

위와 같이 나온다면 잘 적용된거다..
위가 아니라 Server: Apache/2.2.4(Unix) 라고 나온다면 적용이 안된거다.

룰부분에 대해서는 관련문서를 참고하여 수정하면 되겠다.


또하나 modsecurity 와 관련하여 https://bns.breach.com에서 modsecurity 로그관리툴이 있다.
우선적으로 JDK를 설치해줘야 한다 1.5이상 설치하란다.
JDK설치 방법은 JSP 땜시 설치할때 모아놓은 자료에 있다.JDK검색하면 많이 나온다.
해당 사이트에서 modsecurity-console_1_0_2_linux.rpm을 다운로드한후..
# rpm -Uvh modsecurity-console_1_0_2_linux.rpm  깔게되면
# find / -name 'modsecurity-console'
/usr/local/bin/modsecurity-console
/opt/modsecurity-console
/opt/modsecurity-console/modsecurity-console
에 깔리게 되고..
# ./modsecurity-console 실행하게 되면 동작한다..
8886포트로 동작하기 때문에 방화벽에서 8886포트를 열어줘야 한다.

# vi /etc/sysconfig/iptables
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8886 -j ACCEPT
전체포르를 닫아버리는 부분 이전에 위라인을 추가해준다.
# /etc/rc.d/init.d/iptalbes restart
방화벽을 다시 시작한다.

그다음 브라우저에서 http://서버도메인:8886 에 접속할수 있다.
초기 관리자 비번은 admin/admin 이다

접속해본 결과 


아직은 어떻게 써먹는지는 모르겠으나.. 인젝션버그등 잡다한거는 죄다 막아 준다고 했다.
로그파일을 뒤지는것보다 저게 편하기는 하겠는데 어떻게 보는줄 모르니.. 좀더 연구해봐야 한
참고로 breach.com 에서 modsecurity를 인수했다고 한다. 기존의 것은 오픈소스로 제공하고
새로나오는것들은 팔아먹을 모양이다. 머 지금까지 다들 잘써왔다고 하니 계속 쓰면 될듯하다.

또하나 홍석범님의 글을 보니
- REMO : http://remo.netnea.com/
modsecurity 에 대한 규칙설정을 웹 기반으로 편집할수 있는 프로그램이다.
-WeBekci : http://www.owasp.org/index.php/Category:OWASP_WeBekci_Project
modsecurity에 대한 규칙설정 등의 관리를 웹기반으로 수행할수 있는 프로그램으로, php+mysql의 기반 프로그램이다 또한 유료기술지원으로 modsecurity를 인수한 www.breach.com에서 리눅스 기반의
ModSecurity Pro와 WebDefend라는 웹 파이어월 어플라이언트 제품도 판매한단다.

댓글목록

등록된 댓글이 없습니다.

Total 356건 19 페이지
게시물 검색

회원로그인

접속자집계

오늘
145
어제
225
최대
1,347
전체
154,904
Latest Crypto Fear & Greed Index

그누보드5
Copyright © 서방님.kr All rights reserved.