CentOS 7, Debian 8 및 Ubuntu 16.04에 Nginx 용 ModSecurity를 ​​설치하는 방법

ModSecurity는 다양한 웹 애플리케이션의 잠재적 취약성을 대상으로하는 다양한 사이버 공격으로부터 Apache, Nginx 및 IIS를 보호하는 데 유용한 오픈 소스 웹 애플리케이션 방화벽 (WAF) 모듈입니다.

이 기사에서는 CentOS 7, Debian 8 및 Ubuntu 16.04에 Nginx 용 ModSecurity를 ​​설치하고 구성합니다.

전제 조건

  • - - 날짜 CentOS는 7, 데비안 8, 우분투 16.04 64 비트 설치.
  • 로 로그인 중 root입니다.

1 단계 : 시스템 업데이트

다음은 이 가이드 , 서버의 커널과 최신 버전의 패키지를 업데이트합니다.

2 단계 : 종속성 설치

Nginx 및 ModSecurity를 ​​성공적으로 컴파일하려면 다음과 같이 여러 소프트웨어 패키지를 설치해야합니다.

a) CentOS 7 :

yum groupinstall -y "Development Tools"
yum install -y httpd httpd-devel pcre pcre-devel libxml2 libxml2-devel curl curl-devel openssl openssl-devel
shutdown -r now

b) 데비안 8 또는 우분투 16.04 :

apt-get install -y git build-essential libpcre3 libpcre3-dev libssl-dev libtool autoconf apache2-dev libxml2-dev libcurl4-openssl-dev automake pkgconf

3 단계 : ModSecurity 컴파일

Nginx 마스터 브랜치 용 ModSecurity에보고 된 여러 가지 불안정성 때문에 현재로서는 nginx_refactoring가능한 한 최신 버전의 브랜치 를 사용하는 것이 공식적으로 권장됩니다 .

nginx_refactoringNginx 용 ModSecurity 브랜치를 다운로드하십시오 .

cd /usr/src
git clone -b nginx_refactoring https://github.com/SpiderLabs/ModSecurity.git

컴파일 모드

a) CentOS 7 :

cd ModSecurity
sed -i '/AC_PROG_CC/a\AM_PROG_CC_C_O' configure.ac
sed -i '1 i\AUTOMAKE_OPTIONS = subdir-objects' Makefile.am
./autogen.sh
./configure --enable-standalone-module --disable-mlogc
make

참고 : sed위 의 두 명령은 최신 automake 버전을 사용할 때 경고 메시지를 방지하는 데 사용됩니다.

b) 데비안 8 또는 우분투 16.04 :

cd ModSecurity
./autogen.sh
./configure --enable-standalone-module --disable-mlogc
make

4 단계 : Nginx 컴파일

Nginx 1.10.3작성 당시의 최신 Nginx 릴리스를 다운로드하여 보관 해제하십시오 .

cd /usr/src
wget https://nginx.org/download/nginx-1.10.3.tar.gz
tar -zxvf nginx-1.10.3.tar.gz && rm -f nginx-1.10.3.tar.gz

a) CentOS 7 :

먼저 Nginx 전용 사용자 nginx와 전용 그룹 을 생성해야합니다 nginx.

groupadd -r nginx
useradd -r -g nginx -s /sbin/nologin -M nginx

그런 다음 ModSecurity 및 SSL 모듈을 활성화하면서 Nginx를 컴파일하십시오.

cd nginx-1.10.3/
./configure --user=nginx --group=nginx --add-module=/usr/src/ModSecurity/nginx/modsecurity --with-http_ssl_module
make
make install

Nginx의 기본 사용자를 수정하십시오.

sed -i "s/#user  nobody;/user nginx nginx;/" /usr/local/nginx/conf/nginx.conf

b) 데비안 8 또는 우분투 16.04 :

먼저 기존 사용자 www-data와 기존 그룹을 사용해야합니다 www-data.

그런 다음 ModSecurity 및 SSL 모듈을 활성화하면서 Nginx를 컴파일하십시오.

cd nginx-1.10.3/
./configure --user=www-data --group=www-data --add-module=/usr/src/ModSecurity/nginx/modsecurity --with-http_ssl_module
make
make install

Nginx의 기본 사용자를 수정하십시오.

sed -i "s/#user  nobody;/user www-data www-data;/" /usr/local/nginx/conf/nginx.conf

Nginx가 성공적으로 설치되면 관련 파일은 다음 위치에 있습니다.

nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"

다음을 사용하여 설치를 테스트 할 수 있습니다.

/usr/local/nginx/sbin/nginx -t

아무 것도 잘못되면 출력은 다음과 같아야합니다

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

편의를 위해 Nginx에 대한 시스템 단위 파일을 설정할 수 있습니다.

cat <<EOF>> /lib/systemd/system/nginx.service
[Service]
Type=forking
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
KillStop=/usr/local/nginx/sbin/nginx -s stop

KillMode=process
Restart=on-failure
RestartSec=42s

PrivateTmp=true
LimitNOFILE=200000

[Install]
WantedBy=multi-user.target
EOF

다음과 같이 Nginx를 시작 / 중지 / 다시 시작할 수 있습니다.

systemctl start nginx.service
systemctl stop nginx.service
systemctl restart nginx.service

4 단계 : ModSecurity 및 Nginx 구성

4.1 Nginx 구성 :

vi /usr/local/nginx/conf/nginx.conf

세그먼트 내에서 다음 세그먼트를 찾으십시오 http {}.

location / {
    root   html;
    index  index.html index.htm;
}

아래 줄을 location / {}세그먼트에 삽입하십시오 .

ModSecurityEnabled on;
ModSecurityConfig modsec_includes.conf;
#proxy_pass http://localhost:8011;
#proxy_read_timeout 180s;

최종 결과는 다음과 같아야합니다.

location / {
    ModSecurityEnabled on;
    ModSecurityConfig modsec_includes.conf;
    #proxy_pass http://localhost:8011;
    #proxy_read_timeout 180s;
    root   html;
    index  index.html index.htm;
}

저장하고 종료하십시오 :

:wq!

참고 : 위의 Nginx 구성은 리버스 프록시가 아닌 웹 서버로 Nginx를 사용하기위한 샘플 구성 일뿐입니다. Nginx를 리버스 프록시로 사용하는 경우 #마지막 두 줄에서 문자를 제거하고 적절히 수정하십시오.

4.2 /usr/local/nginx/conf/modsec_includes.conf:

cat <<EOF>> /usr/local/nginx/conf/modsec_includes.conf
include modsecurity.conf
include owasp-modsecurity-crs/crs-setup.conf
include owasp-modsecurity-crs/rules/*.conf
EOF

참고 : 위의 구성은 owasp-modsecurity-crs/rules/디렉토리의 모든 OWASP ModSecurity 핵심 규칙을 적용합니다 . 선택적 규칙 만 적용하려면 include owasp-modsecurity-crs/rules/*.conf행을 제거한 다음 4.5 단계 후에 필요한 정확한 규칙을 지정해야합니다.

4.3 ModSecurity 구성 파일 가져 오기 :

cp /usr/src/ModSecurity/modsecurity.conf-recommended /usr/local/nginx/conf/modsecurity.conf
cp /usr/src/ModSecurity/unicode.mapping /usr/local/nginx/conf/

4.4 /usr/local/nginx/conf/modsecurity.conf파일 수정

sed -i "s/SecRuleEngine DetectionOnly/SecRuleEngine On/" /usr/local/nginx/conf/modsecurity.conf

4.5 OWASP ModSecurity CRS (Core Rule Set) 파일 추가 :

cd /usr/local/nginx/conf
git clone https://github.com/SpiderLabs/owasp-modsecurity-crs.git
cd owasp-modsecurity-crs
mv crs-setup.conf.example crs-setup.conf
cd rules
mv REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf.example REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf
mv RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf.example RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf

5 단계 : ModSecurity 테스트

Nginx를 시작하십시오 :

systemctl start nginx.service

외부 액세스를 허용하려면 포트 80을여십시오.

a) CentOS 7 :

firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --reload

b) 데비안 8 :

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP
touch /etc/iptables
iptables-save > /etc/iptables

c) 우분투 16.04에서 :

ufw allow OpenSSH
ufw allow 80
ufw default deny
ufw enable    

웹 브라우저가 다음을 가리 키도록하십시오.

http://203.0.113.1/?param="><script>alert(1);</script>

grep다음과 같이 오류 메시지를 가져 오는 데 사용하십시오 .

grep error /usr/local/nginx/logs/error.log

출력에는 다음과 유사한 몇 가지 오류 메시지가 포함되어야합니다.

2017/02/15 14:07:54 [error] 10776#0: [client 104.20.23.240] ModSecurity: Warning. detected XSS using libinjection. [file "/usr/local/nginx/conf/owasp-modsecurity-crs/rules/REQUEST-941-APPLICATION-ATTACK-XSS.conf"] [line "56"] [id "941100"] [rev "2"] [msg "XSS Attack Detected via libinjection"] [data "Matched Data:  found within ARGS:param: \x22><script>alert(1);</script>"] [severity "CRITICAL"] [ver "OWASP_CRS/3.0.0"] [maturity "1"] [accuracy "9"] [tag "application-multi"] [tag "language-multi"] [tag "platform-multi"] [tag "attack-xss"] [tag "OWASP_CRS/WEB_ATTACK/XSS"] [tag "WASCTC/WASC-8"] [tag "WASCTC/WASC-22"] [tag "OWASP_TOP_10/A3"] [tag "OWASP_AppSensor/IE1"] [tag "CAPEC-242"] [hostname ""] [uri "/index.html"] [unique_id "ATAcAcAkucAchGAcPLAcAcAY"]

그게 다야. 보다시피, ModSecurity 모듈은 기본 동작 정책에 따라이 공격을 성공적으로 기록했습니다. 더 많은 사용자 정의 설정을 확인하려면주의 깊게 편집 및 검토하시기 바랍니다 /usr/local/nginx/conf/modsecurity.conf/usr/local/nginx/conf/owasp-modsecurity-crs/crs-setup.conf파일을.



CentOS 7 서버에 CyberPanel을 설치하고 구성하는 방법

CentOS 7 서버에 CyberPanel을 설치하고 구성하는 방법

다른 시스템을 사용하십니까? 소개 CyberPanel은 오픈 소스이며 OpenLiteSpeed를 사용하는 최초의 제어판 중 하나입니다. 무슨 티

CentOS 7에 채팅 서버를 배포하는 방법

CentOS 7에 채팅 서버를 배포하는 방법

Lets Chat은 소규모 팀을위한 자체 호스팅 메시징 서비스를 제공하도록 설계된 오픈 소스 채팅 응용 프로그램입니다. 채팅이 NodeJS 및 MongoDB를 기반으로 함

CentOS 7에 예약 스케줄러를 설치하는 방법

CentOS 7에 예약 스케줄러를 설치하는 방법

다른 시스템을 사용하십니까? 전제 조건 Vultr CentOS 7 서버 인스턴스. sudo 사용자 1 단계 : 시스템 업데이트 먼저 시스템 서버를 업데이트하십시오.

CentOS 7에 Netdata 설치

CentOS 7에 Netdata 설치

다른 시스템을 사용하십니까? Netdata는 실시간 시스템 메트릭 모니터링 분야에서 떠오르는 별입니다. 같은 종류의 다른 도구 인 Netdata와 비교하면 :

CentOS 7에 DreamFactory 오픈 소스를 설치하는 방법

CentOS 7에 DreamFactory 오픈 소스를 설치하는 방법

DreamFactory는 모든 데이터베이스를 RESTful API 플랫폼으로 전환 할 수있는 오픈 소스 프로그램입니다. DreamFactory는 다양한 플랫폼에 배포 할 수 있습니다. 티에서

CentOS 7에 JC2-MP (Just Cause 2) 서버를 설치하는 방법

CentOS 7에 JC2-MP (Just Cause 2) 서버를 설치하는 방법

이 튜토리얼에서는 Just Cause 2 멀티 플레이어 서버를 설정하는 방법을 배웁니다. 전제 조건 시작하기 전에 시스템이 완전히 업데이트되었는지 확인하십시오

CentOS 7에서 Leanote 서버를 설정하는 방법

CentOS 7에서 Leanote 서버를 설정하는 방법

Leanote는 Golang으로 작성된 Evernote의 무료, 경량 및 오픈 소스 대안입니다. 사용자 경험을 염두에두고 Leanote는 사용자에게 재치를 제공합니다.

CentOS 7에 Starbound Server를 설치하는 방법

CentOS 7에 Starbound Server를 설치하는 방법

다른 시스템을 사용하십니까? 이 튜토리얼에서는 CentOS 7에서 Starbound 서버를 설정하는 방법을 설명하겠습니다. 전제 조건이 게임을 소유해야합니다

CentOS 8, Ubuntu 18.04, Debian 10 및 Fedora 31에 Golang 1.13을 설치하는 방법 31

CentOS 8, Ubuntu 18.04, Debian 10 및 Fedora 31에 Golang 1.13을 설치하는 방법 31

Go (Golang이라고도 함)는 Google에서 개발 한 정적으로 형식이 지정된 컴파일 된 C 유사 프로그래밍 언어입니다. 단순성과 다목적 성으로 인해 b가되었습니다.

CentOS 7에 Django를 설치하는 방법

CentOS 7에 Django를 설치하는 방법

Django는 웹 응용 프로그램을 작성하는 데 널리 사용되는 Python 프레임 워크입니다. Django를 사용하면 휠을 재발 명하지 않고도 응용 프로그램을 더 빠르게 구축 할 수 있습니다. 당신이 원하는 경우

CentOS 6에서 SA-MP San Andreas 멀티 플레이어 서버 설정

CentOS 6에서 SA-MP San Andreas 멀티 플레이어 서버 설정

다른 Vultr 튜토리얼에 오신 것을 환영합니다. 여기에서는 SAMP 서버를 설치하고 실행하는 방법에 대해 설명합니다. 이 안내서는 CentOS 6 용으로 작성된 것입니다. 전제 조건

CentOS 7 LAMP VPS에 TextPattern CMS를 설치하는 방법

CentOS 7 LAMP VPS에 TextPattern CMS를 설치하는 방법

다른 시스템을 사용하십니까? TextPattern CMS 4.6.2는 간단하고 유연하며 무료이며 오픈 소스 CMS (콘텐츠 관리 시스템)로 웹 디자이너는

CentOS 7에 Elgg 설치

CentOS 7에 Elgg 설치

다른 시스템을 사용하십니까? Elgg는 캠퍼스 소셜 네트워크와 같은 소셜 환경을 만들 수있는 오픈 소스 소셜 네트워킹 엔진입니다.

CentOS 7 개발을위한 Sails.js 설정

CentOS 7 개발을위한 Sails.js 설정

다른 시스템을 사용하십니까? 소개 Sails.js는 Ruby on Rails와 비슷한 Node.js 용 MVC 프레임 워크입니다. 그것은 현대적인 응용 프로그램을 개발할 수 있습니다

CentOS 7에 PufferPanel (무료 Minecraft 제어판)을 설치하는 방법

CentOS 7에 PufferPanel (무료 Minecraft 제어판)을 설치하는 방법

소개이 자습서에서는 Vultr VPS에 PufferPanel을 설치하십시오. PufferPanel은 사용자를 관리하기위한 무료 오픈 소스 제어판입니다.

PHP를 5에서 7로 업데이트하는 방법 (NGINX / Apache, CentOS 7)

PHP를 5에서 7로 업데이트하는 방법 (NGINX / Apache, CentOS 7)

소개이 튜토리얼은 NGINX 또는 Apache로 PHP 5 *를 7로 업데이트하는 방법을 다룹니다. 전제 조건 시작하기 전에 저장소를 추가해야합니다.

CentOS 7에 MoinMoin을 설치하는 방법

CentOS 7에 MoinMoin을 설치하는 방법

MoinMoin은 Python으로 작성된 오픈 소스 파일 시스템 기반 위키 엔진입니다. 오늘날 MoinMoin은 오픈 소스 커뮤니티에서 널리 사용됩니다. 많은 공급 업체

CentOS 7에 SonarQube를 설치하는 방법

CentOS 7에 SonarQube를 설치하는 방법

다른 시스템을 사용하십니까? SonarQube는 품질 시스템 개발을위한 오픈 소스 도구입니다. Java로 작성되었으며 여러 데이터베이스를 지원합니다. 그것은 제공

OS 선택 : CentOS, Ubuntu, Debian, FreeBSD, CoreOS 또는 Windows Server

OS 선택 : CentOS, Ubuntu, Debian, FreeBSD, CoreOS 또는 Windows Server

이 기사는 Vultr에서 템플릿으로 제공되는 서버 운영 체제에 대한 간략한 개요를 제공합니다. CentOS CentOS는 RHEL의 공개 소스 버전입니다 (Re

CentOS 7에 phpPgAdmin 설치

CentOS 7에 phpPgAdmin 설치

phpPgAdmin은 널리 사용되는 PostgreSQL 관리 도구입니다. 직관적 인 웹 인터페이스에서 PostgreSQL 데이터베이스를 관리하는 데 사용할 수 있습니다. 이 기사에서 우리는

AI가 랜섬웨어 공격의 증가와 싸울 수 있습니까?

AI가 랜섬웨어 공격의 증가와 싸울 수 있습니까?

랜섬웨어 공격이 증가하고 있지만 AI가 최신 컴퓨터 바이러스를 처리하는 데 도움이 될 수 있습니까? AI가 답인가? AI boone 또는 bane인지 여기에서 읽으십시오.

ReactOS: 이것이 Windows의 미래입니까?

ReactOS: 이것이 Windows의 미래입니까?

오픈 소스이자 무료 운영 체제인 ReactOS가 최신 버전과 함께 제공됩니다. 현대 Windows 사용자의 요구 사항을 충족하고 Microsoft를 무너뜨릴 수 있습니까? 이 구식이지만 더 새로운 OS 환경에 대해 자세히 알아보겠습니다.

WhatsApp 데스크톱 앱 24*7을 통해 연결 유지

WhatsApp 데스크톱 앱 24*7을 통해 연결 유지

Whatsapp은 마침내 Mac 및 Windows 사용자용 데스크톱 앱을 출시했습니다. 이제 Windows 또는 Mac에서 Whatsapp에 쉽게 액세스할 수 있습니다. Windows 8 이상 및 Mac OS 10.9 이상에서 사용 가능

AI는 어떻게 프로세스 자동화를 다음 단계로 끌어올릴 수 있습니까?

AI는 어떻게 프로세스 자동화를 다음 단계로 끌어올릴 수 있습니까?

인공 지능이 소규모 회사에서 어떻게 인기를 얻고 있으며 어떻게 인공 지능이 성장할 가능성을 높이고 경쟁자가 우위를 점할 수 있는지 알아보려면 이 기사를 읽으십시오.

macOS Catalina 10.15.4 추가 업데이트로 인해 해결보다 더 많은 문제가 발생함

macOS Catalina 10.15.4 추가 업데이트로 인해 해결보다 더 많은 문제가 발생함

최근 Apple은 문제를 해결하기 위해 macOS Catalina 10.15.4 추가 업데이트를 출시했지만 이 업데이트로 인해 Mac 컴퓨터의 브릭킹으로 이어지는 더 많은 문제가 발생하는 것 같습니다. 자세히 알아보려면 이 기사를 읽어보세요.

빅데이터의 13가지 상용 데이터 추출 도구

빅데이터의 13가지 상용 데이터 추출 도구

빅데이터의 13가지 상용 데이터 추출 도구

저널링 파일 시스템이란 무엇이며 어떻게 작동합니까?

저널링 파일 시스템이란 무엇이며 어떻게 작동합니까?

우리 컴퓨터는 모든 데이터를 저널링 파일 시스템이라고 하는 체계적인 방식으로 저장합니다. 검색을 누르는 즉시 컴퓨터에서 파일을 검색하고 표시할 수 있는 효율적인 방법입니다.https://wethegeek.com/?p=94116&preview=true

기술적 특이점: 인류 문명의 먼 미래?

기술적 특이점: 인류 문명의 먼 미래?

과학이 빠른 속도로 발전하고 우리의 많은 노력을 인수함에 따라 설명할 수 없는 특이점에 처할 위험도 높아집니다. 특이점이 우리에게 무엇을 의미할 수 있는지 읽어보십시오.

26가지 빅 데이터 분석 기법에 대한 통찰: 1부

26가지 빅 데이터 분석 기법에 대한 통찰: 1부

26가지 빅 데이터 분석 기법에 대한 통찰: 1부

2021년 의료 분야에서 인공 지능의 영향

2021년 의료 분야에서 인공 지능의 영향

의료 분야의 AI는 지난 수십 년 동안 큰 도약을 했습니다. 따라서 의료 분야에서 AI의 미래는 여전히 나날이 성장하고 있습니다.