CentOS 7 Apache 2.4 에 mod_security 모듈 설치 > 개발

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

개발

CentOS 7 Apache 2.4 에 mod_security 모듈 설치

페이지 정보

profile_image
작성자 관리자 (61.♡.222.236)
댓글 0건 조회 3,597회 작성일 19-07-05 12:51

본문

SQL Injection  공격에 대비해서 mod_security 를 설치해 본다.
역시나 세상이 좋아져서, yum 으로 설치가 가능하다.


ㅁ mod_security 모듈 설치

# yum install mod_security

의존성 패키지 없이 홀로 설치가 된다.
모듈 및 설정파일들이 추가가 되는데, 주요한 파일들은 아래와 같다.

/etc/httpd/modules/mod_security2.so
/etc/httpd/conf.modules.d/10-mod_security.conf
/etc/httpd/conf.d/mod_security.conf
/etc/httpd/modsecurity.d/*


ㅁ 설정파일들

메인 설정 파일은 /etc/httpd/conf.d/mod_security.conf 이다.
일단, 열어서
SecRuleEngine On

SecRuleEngine DetectionOnly
로 변경하자.
차단시키지는 않고, 감지만 하겠다는 뜻이다.
무턱대고 차단했다가는 멘붕이 올 수가 있다.

phpMyAdmin 같은 것들은 필히 Off 시켜 놓아야 한다.
[code]
<Directory "/var/www/wp-admin">
    <IfModule security2_module>
        SecRuleEngine Off
    </IfModule>
</Directory>
[/code]


ㅁ OWASP ModSecurity Core Rule Set (CRS) 설치

https://modsecurity.org/crs/  -> 여긴 없어졌다. End-of-Sale (EOS) 예정이라서 그런 듯 하다. github 로 옮겨간 듯..
https://coreruleset.org/
https://github.com/SpiderLabs/ModSecurity

git 으로 받을 수 있다.
# git clone https://github.com/SpiderLabs/owasp-modsecurity-crs.git

/etc/httpd/modsecurity.d/* 에 직접 받아도 되고,
다른 곳에 받아서 복사해 넣을 수도 있다.

폴더 안에 들어가 보면, 여러 파일들이 있는데, 아래 2가지가 필요하다.
crs-setup.conf.example
rules/*.conf

복사한 후에 .example 이 붙은 것은 떼어 준다. rules 폴더 안에도 있다.
crs-setup.conf
rules/*.conf

아파치 설정파일 mod_security.conf 에서 위 두가지를 include 시켜 준다.
yum 으로 설치했으면, 설정이 추가되어 있다.


ㅁ CRS 운용하기 - 403 Forbidden 에러 예외 처리 방법
# 참고 : https://jimnong.tistory.com/749

ㅇ 아파치 로그파일 error_log 에서
Access denied with code 403 ....
의 로그가 남는 것의 rule id 를 찾는다.

ㅇ 특정 폴더나 특정 url 에서 예외 추가하기
<Directory "/home/bbs/install">
    <IfModule mod_security2.c>
        SecRuleRemoveById 941310
    </IfModule>
</Directory>
<Locatioin "/bbs/update.php">
    <IfModule mod_security2.c>
        SecRuleRemoveById 941310
    </IfModule>
</Location>

ㅇ VirtualHost 설정에도 예외 추가할 수 있다.
<VirtualHost *:80>
    ServerName www.domain.com
    ....
    SecRuleRemoveById 941310
</VirtualHost>




ㅁ 참고
https://sepiros.tistory.com/16
https://www.digitalocean.com/community/tutorials/how-to-set-up-mod_security-with-apache-on-debian-ubuntu
https://www.modsecurity.org/crs/

추천0

댓글목록

등록된 댓글이 없습니다.

Total 386건 8 페이지
  • RSS

검색


사이트 정보

Copyright © Baragi.Net. All rights reserved.