본문 바로가기
서버

[아파치] mod_security 설치하여 서버정보 제거방법

by snow_hong 2024. 1. 26.

Apache Tomcat(이하 톰캣)8 버전 이하에서는 응답 헤더(Resposne Header)에 Server값을 노출하는 보안취약점이 있다.

※ 톰캣8.5 버전부터는 해당 설정을 보여주지 않으므로 수정할 필요 없음

 

https://hong42.tistory.com/151

 

[아파치] Response Header에서 Server 노출 해결방안

Apache Tomcat(이하 톰캣)8 버전 이하에서는 응답 헤더(Resposne Header)에 Server값을 노출한다. 톰캣은 기본적으로 Apache-Coyote라는 값이 쓰여져 있어 공격자는 해당 취약점을 악용할 수 있다. Response Header

hong42.tistory.com

 

해당 Response Header에서 Server 노출해결방안을 했지만 정보보안 정책상 웹서버 이름(apache)까지 노출이 되지않아야한다고 한다. 😥

 

Response Header에서 Server 정보 완전 제거를 하려면 mod_security를 설치하는 방법이 유일하다.

 

 

ModSecurity는 Trustwave의 SpiderLabs에서 개발한 오픈 소스 크로스 플랫폼 웹 애플리케이션 방화벽(WAF)으로 웹서버의 이름(Apache)조차 노출 제거 가능하다.

https://github.com/owasp-modsecurity/ModSecurity/wiki

 

Home

ModSecurity is an open source, cross platform web application firewall (WAF) engine for Apache, IIS and Nginx that is developed by Trustwave's SpiderLabs. It has a robust event-based programmin...

github.com

 


🛠 mod_security 모듈 설치

1. 기존 기동되는 서버 & 아파치 중지

아파치 중지
$ systemctl stop httpd

 

2. # yum install mod_security

mod_security를 다운받자!

중간에 용량설명이 뜨면서 설치여부를 뭍는데 Y로 설정하면 설치가 완료된다.

[root@localhost /]# yum install mod_security
Loaded plugins: fastestmirror
Determining fastest mirrors
epel/x86_64/metalink                                                           | 3.8 kB  00:00:00
 * base: mirror.kakao.com
 * epel: ftp.iij.ad.jp
 * extras: mirror.kakao.com
 * remi-php74: ftp.riken.jp
 * remi-safe: ftp.riken.jp
 * updates: mirror.kakao.com
base                                                                           | 3.6 kB  00:00:00
epel                                                                           | 4.7 kB  00:00:00
extras                                                                         | 2.9 kB  00:00:00
mariadb                                                                        | 2.9 kB  00:00:00
remi-php74                                                                     | 3.0 kB  00:00:00
remi-safe                                                                      | 3.0 kB  00:00:00
updates                                                                        | 2.9 kB  00:00:00
(1/6): epel/x86_64/updateinfo                                                  | 1.0 MB  00:00:00
(2/6): epel/x86_64/primary_db                                                  | 6.9 MB  00:00:00
(3/6): remi-php74/primary_db                                                   | 235 kB  00:00:00
(4/6): extras/7/x86_64/primary_db                                              | 232 kB  00:00:00
(5/6): updates/7/x86_64/primary_db                                             | 7.1 MB  00:00:01
(6/6): remi-safe/primary_db                                                    | 1.9 MB  00:00:01
Resolving Dependencies
--> Running transaction check
---> Package mod_security.x86_64 0:2.9.2-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================
 Package                    Arch                 Version                     Repository          Size
======================================================================================================
Installing:
 mod_security               x86_64               2.9.2-1.el7                 base               249 k

Transaction Summary
======================================================================================================
Install  1 Package

Total download size: 249 k
Installed size: 980 k
Is this ok [y/d/N]: y
Downloading packages:
mod_security-2.9.2-1.el7.x86_64.rpm                                            | 249 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mod_security-2.9.2-1.el7.x86_64                                                    1/1
  Verifying  : mod_security-2.9.2-1.el7.x86_64                                                    1/1

Installed:
  mod_security.x86_64 0:2.9.2-1.el7

Complete!
[root@localhost /]#
  • mod_security의 모듈 mod_security2.so는 /usr/lib64/httpd/module
  • /etc/httpd/conf.modules.d 의 10-mod_security.conf에 의해서 로드

📂 mod_security 모듈 설치확인

# apachectl -M | grep security

 

결과에 security2_module과 같은 텍스트가 나타나면 mod_security가 설치완료된 상태이다.

 


⚙ mod_security 모듈 설정

1. Apache httpd.conf 찾기

$ find / -name httpd.conf

 

2. Apache httpd.conf 수정

  • 기존에 추가한  ServerTokens Prod 설정 삭제
  • 내용 추가! - 위치는 아무곳이나 상관없지만 가장 마지막 줄에 넣는 걸 추천드려요
<IfModule security2_module>
   SecRuleEngine on
   ServerTokens Full
   SecServerSignature "None"
</IfModule>

 

3. 서버 및 아파치 기동

아파치 시작 
$ systemctl start httpd

 


 

mod_security 모듈 설치 및 설정을 통하여 웹서버 정보가 None으로 전송된다.

서버의 정보를 공백으로 하고 싶다면 ' ' 공백 하나를 넣어두자!

 

mod_security 모듈은 웹서버 정보 제거 외에도 다양한 보안설정이 가능하니 확인해보면 좋을 것 같다. 

(한국 인터넷진흥원에서도 정보를 얻을 수 있음 / https://github.com/owasp-modsecurity/ModSecurity/wiki )


 

 

출처 : https://aegypius.tistory.com/entry/아파치-웹-서버의-정보-숨기기 [기억과 흔적:티스토리]

728x90

댓글