728x90

Ubuntu 16.04 LTS ModSecurity2.9.2 Install



서론

아파치에는 ModSecurity 라는 자체적인 Security Firewall 이 존재하는데 (GNU, GPL) 기반의 Open Source Firewall 이다. 기존에 ModSecurity2 자체는 Apache에 타겟팅하여 나타난 형태이기 때문에, 다른 서버를 쓴다면 ModSecurity3 을 install 해야한다. 하지만 ModSecurity3 는 아직 stable 버전이 존재하지 않는다. 


1. 의존 패키지 설치


해당 라이브러리들은 dependency 를 가지는 패키지들로써, 이들이 없다면 자체적으로 소스 컴파일이 되지 않는다.

apt-get install gcc gcc-c++ make perl zip unzip wget git zlib-devel libxml2 libxml2-devel ncurses ncurses-devel expat expat-devel


Installation for Apache

Prerequisites

ModSecurity 2.x works only with Apache 2.0.x or higher

The ModSecurity team works hard to ensure that ModSecurity version 2.x will work with all versions of Apache 2.x and higher. If you find incompatibilities on any version (2.2.x, 2.4.x, or 2.6.x) please immediately inform the ModSecurity team

mod_uniqueid

Make sure you have mod_unique_id installed. mod_unique_id is packaged with Apache httpd.

libapr and libapr-util

libapr and libapr-util - http://apr.apache.org/

libpcre

http://www.pcre.org/

libxml2

http://xmlsoft.org/downloads.html

liblua v5.x.x

This library is optional and only needed if you will be using the new Lua engine - http://www.lua.org/download.html

Note : that ModSecurity requires the dynamic libraries. These are not built by default in the source distribution, so the binary distribution is recommended.
Note : libModSecurity (aka v3) is compatible with Lua 5.2+.

libcurl v7.15.1 or higher

If you will be using the ModSecurity Log Collector (mlogc) to send audit logs to a central repository, then you will also need the curl library.

http://curl.haxx.se/libcurl/

Note : Many have had issues with libcurl linked with the GnuTLS library for SSL/TLS support. It is recommended that the openssl library be used for SSL/TLS support in libcurl.


여기서 liblua 는 option적인 항목으로써 반드시 적어주지 않아도 된다.


위의 대부분의 라이브러리들은 httpd (Apache2)를 설치할때 자동으로 의존성에 의해서 같이 설치되긴 하나, 필자의 경우 소스컴파일로 각자 다른 디렉토리에 불러들였기 때문에, 직접 일일히 지정해줘야한다. 


만약 apache 가 /etc/apache 위에 설치되어있는 아주 편안한 상황이라면 굳이 이 메뉴얼을 쓰지 않았다.



2. mod_uniqueid 를 활성화한다. 

 httpd.conf 파일에 접근한다.

#vi /home/apache/conf/httpd.conf


그리고 LoadModule 을 검색해보면


#LoadModule unique_id_module modules/mod_unique_id.so 

가 주석처리 되어있다. 주석처리를 해제해준다.


또, 다음과 같은 모듈도 주석처리 해준다. (있다가 설치한 이후에, 이놈이 주석처리 되어있지 않다면, 에러가 뜬다.)

#LoadModule slotmem_shm_module modules/mod_slotmem_shm.so


위의 사항들을 다 마쳤다면 (제대로 따라오고 있다면), 다음의 페이지에 접근한다.


3. https://github.com/SpiderLabs/ModSecurity/releases  에 접속한다.

v2.9.2

@zimmerle zimmerle released this on 19 Jul 2017

Bug fixes

  • IIS build refactoring and dependencies update
    [Issue #1487 - @victorhora]
  • Best practice: Initialize msre_var pointers
    [Commit fbd57 - Allan Boll]
  • nginx: Obtain port from r->connection->local_sockaddr. As reported by Przemyslaw Duda the lack of this commit may lead to a DoS. This patch is now merged on all nginx trees. But we still recommend nginx users to move forward to version 3.
    [Commit 51314 - @defanator and Przemyslaw Duda]
  • Updates libinjection to v3.10.0
    [Issue #1412 - @client9@zimmerle and @bjdijk]
  • Avoid log flood while using SecConnEngine
    [Issue #1436 - @victorhora]
  • Make url path absolute for SecHashEngine only when it is relative in the first place.
    [Issue #752#1071 - @hideaki]
  • Fix the hex digit size for SHA1 on msc_crypt implementation.
    [Issue #1354 - @zimmerle and @parthasarathi204]
  • Avoid to flush xml buffer while assembling the injected html.
    [Issue #742 - @zimmerle]
  • Avoid additional operator invokation if last transform of a multimatch doesn't modify the input
    [Issue #1086#1087 - Daniel Stelter-Gliese]
  • Adds a sanity check before use ctl:ruleRemoveTargetByTag.
    [Issue #1353 - @LukeP21 and @zimmerle]
  • Uses an optional global lock while manipulating collections.
    [Issues #1224 - @mturk and @zimmerle]
  • Fix collection naming problem while merging collections.
    [Issue #1274 - Coty Sutherland and @zimmerle]
  • Fix --enable-docs adding missing Makefile, modifying autoconf and filenames
    [Issue #1322 - @victorhora]
  • Change from using rand() to thread-safe ap_random_pick.
    [Issue #1289 - Robert Bost]
  • Cosmetics: added comments on odd looking code to prevent future scrutiny
    [Issue #1279 - Coty Sutherland]
  • {dis|en}able-server-context-logging: Option to disable logging of server info (log producer, sanitized objects, ...) in audit log.
    [Issue #1069 - Marc Stern]
  • Allow drop to work with mod_http2
    [Issue #1308#992 - @bazzadp]
  • Fix SecConn(Read|Write)StateLimit on Apache 2.4
    [Issue #1340#1337#786 - Sander Hoentjen]
  • {dis|en}able-stopwatch-logging: Option to disable logging of stopwatches
    in audit log.
    [Issue #1067 - Marc Stern]
  • {dis|en}able-dechunk-logging: Option to disable logging of dechunking in audit log when log level < 9.
    [Issue #1068 - Marc Stern]
  • Updates libinjection to: da027ab52f9cf14401dd92e34e6683d183bdb3b4
    [ModSecurity team]
  • {dis|en}able-handler-logging: Option to disable logging of Apache handler in audit log
    [Issue #1070#1381 - Marc Stern]
  • {dis|en}able-collection-delete-problem-logging: Option to disable logging of collection delete problem in audit log when log level < 9.
    [Issue #1380 - Marc Stern]
  • Adds rule id in logs whenever a rule fail.
    [Issue #1379#391 - Marc Stern]
  • {dis|en}able-server-logging: Option to disable logging of "Server" in audit log when log level < 9.
    [Issue #1070 - Marc Stern]
  • {dis|en}able-filename-logging: Option to disable logging of filename in audit log.
    [Issue #1065 - Marc Stern]
  • Reads fuzzy hash databases on init
    [Issue #1339 - Robert Paprocki and @Rendername]
  • Changes the configuration to recognize soap+xml as XML
    [Issue #1374 - @emphazer and Chaim Sanders]
  • Fix building with nginx >= 1.11.11
    [Issue #1373#1359 - Andrei Belov and Thomas Deutschmann]
  • Using Czechia instea of Czech Republic
    [Issue #1258 - Michael Kjeldsen]
  • {dis|en}able-rule-id-validation: Option to disable rule id validation
    [Issue #1150 - Marc Stern and ModSecurity team]
  • JSON Log: Append a newline to concurrent JSON audit logs
    [Issue #1233 - Robert Paprocki]
  • JSON Log: Don't unnecessarily rename request body parts in cleanup
    [Issue #1223 - Robert Paprocki]
  • Fix error message inside audit logs
    [Issue #1216 and #1073 - Armin Abfalterer]
  • Remove port from IPV4 address when running under IIS.
    [Issue #1220#1109 and #734 - Robert Culyer]
  • Remove logdata and msg fields from JSON audit log rule.
    [Issue #1190 and #1174 - Robert Paprocki]
  • Better handle the json parser cleanup
    [Issue #1204 - Ephraim Vider]
  • Fix status failing to report in Nginx auditlogs
    [Issue #977#1171 - @charlymps and Chaim Sanders]
  • Fix file upload JSON audit log entry
    [Issue #1181 and #1173 - Robert Paprocki and Christian Folini]
  • configure: Fix detection whether libcurl is linked against gnutls and, move verbose_output declaration up to the beginning.
    [Issue #1158 - Thomas Deutschmann (@Whissi)]
  • Treat APR_INCOMPLETE as APR_EOF while receiving the request body.
    [Issue #1060#334 - Alexey Sintsov]

Security Issues

  • Allan Boll reported an uninitialize variable that may lead to a crash on Windows platform.
  • Brian Adeloye reported an infinite loop on the version of libInjection used on ModSecurity 2.9.1.


그렇다. ModSecurity2 는 2.9.2 가 마지막 버전이다. 링크를 따온다. 

 #wget hhttps://github.com/SpiderLabs/ModSecurity/releases/download/v2.9.2/modsecurity-2.9.2.tar.gz

 #tar -xvf modsecurity-2.9.2.tar.gz


이렇게 되면 modsecurity-2.9.2 라는 directory 가 생성되는데, 해당 디렉토리로 이동한다.

 # cd modsecurity-2.9.2


여러가지로 난잡하게 되어있다. 여기서 httpd 가 소스컴파일을 통하여 되었을 경우라면 일일히 위치들을 잡아 lib를 지정해줘야한다.


총 지정해줘야 될 관문은 apxs 의 경로, apr-1-config 의 경로, pcre-config의 경로 (필자의 경우는 apache 폴더에서 찾을 수 없어 find 로 찾아서 가져다 넣었다), apu-1-config 의 경로이다. 이 중에 하나라도 제대로 인식되지 않는다면, ./configure 에서 다양한 에러메세지를 관광가능하니 반드시 참고한다.


# ./configure --prefix=/home/apache --with-apxs=/home/apache/bin/apxs --with-apr=/home/apache/bin/apr-1-config --with-pcre=/usr/bin/pcre-config --with-apu=/home/apache/bin/apu-1-config


# make && make install

--prefix 로 /home/apache 를 잡아주게 되면 /home/apache/modules 에 자동으로 mod-security2.so 파일이 올라가게 된다.


4. 이제 거의 다왔다. 조금만 더 힘내자.


아까 tar 에서 풀었던 디렉토리로 다시 처들어간다. 
// 설정파일 복사
# cp modsecurity.conf-recommended /home/apache/conf/modsecurity.conf
# cp unicode.mapping /home/apache/conf/
 
// 권한 변경
# chmod 755 /home/apache/modules/mod_security2.so
 
// 룰 다운로드 * OWASP 에서 지정한 Core Rull Set 이다. OWASP 에 대해선 알아서 알아보라.
# cd /home/apache/
# git clone https://github.com/spiderLabs/owasp-modsecurity-crs.git
# mv owasp-modsecurity-crs/ modsecurity-crs
# cd modsecurity-crs
# cp crs-setup.conf.example crs-setup.conf

 


5. httpd.conf 파일 수정에 들어간다. 마지막 라운드다.

$ vi /home/apache/conf/httpd.conf
// 모듈 추가
LoadModule security2_module modules/mod_security2.so
 
// 최하단에 아래 내용 추가
# ModSecurity configuration
<IfModule security2_module>
    Include conf/modsecurity.conf
    Include modsecurity-crs/crs-setup.conf
    Include modsecurity-crs/rules/*.conf
</IfModule>

마지막으로 httpd 를 재가동 한다.
# ./httpd -k restart



'LINUX' 카테고리의 다른 글

libkeccak-tiny  (0) 2018.06.15
ModSecurity-CRS config  (0) 2018.06.15
httpd library load check  (0) 2018.06.14
apache 2.x + openssl 설치시 오류 해결 방법  (0) 2018.06.08
Tshark Usage  (0) 2018.06.04

+ Recent posts