์น ์๋ฒ์ 80์ ์ ์ธํ ํฌํธ์ ๋ชจ๋ ํธ๋ํฝ์ ์ญ์ ํฉ๋๋ค.
iptables์ ์ด์ ๊ฐ์ ๊ท์น์ด ์์ต๋๋ค.
iptables -A INPUT -p tcp -m tcp --dport 80 -m string --string "cgi" --algo bm --to 1000 -j DROP
๋ ๋ง์ ์ฌ๋์ด ๊ณต์ ํ ์ ์์ต๋๊น? ๋๋ ํญ์ ๋์ ํด์ปค๋ค์ด ์ฌ์ ํ ์ ๋ฐ์ดํธํ๊ณ ์๋ค๋ ๊ฒ์ ์๊ณ ์์ง๋ง ๊ทธ๋ค ์ค ์ผ๋ถ๋ ํญ์ ๊ฐ์ ์ฝ๋๋ก ์์ํฉ๋๋ค. ์ผ๋ถ ๊ธฐ์ค์ ๋ฐ๋ผ ์ฐ๊ฒฐ์ ๋์ด์ผํฉ๋๋ค. ๋ค์์ ์ผ๋ถ Apache ๋ก๊ทธ์ ๋๋ค (ips๋ ์ ๊ฑฐํ์ง๋ง ๊ฐ ๊ณต๊ฒฉ์ ๋์ผํฉ๋๋ค).
๊ณต๊ฒฉ 1 : ์ด๊ฒ์ ๋ฌด์์ํ๋ ค๊ณ ํ๋์ง ๋ชจ๋ฅด๊ฒ ์ง๋ง ๊ฐ์ IP์์ 50 ๋ฒ ๋ง๋ญ๋๋ค.
GET / HTTP/1.1 301 224 - Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.152 Safari/537.22
GET / HTTP/1.1 302 3387 - Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.152 Safari/537.22
๊ณต๊ฒฉ 2 : ์๋ฒ์ ๋ํ ์ ๋ณด ๋ง ์ป์ผ๋ ค๊ณ ํฉ๋๋ค.
GET / HTTP/1.1 301 224 http://myip:80/ Go-http-client/1.1
GET / HTTP/1.1 302 3228 http mywebsite Go-http-client/1.1
GET /es/ HTTP/1.1 200 40947 https mywebsite Go-http-client/1.1
๊ณต๊ฒฉ 3 : ๋ก๊ทธ์ธ ํ์ด์ง ์ทจ์ฝ์ ์ ์ ๊ทผํ๋ ค๊ณ ํฉ๋๋ค.
GET /userlogin/login.aspx HTTP/1.1 302 186 - -
๊ณต๊ฒฉ 4 : ์ฒซ ๋ฒ์งธ ์์ฒญ์์ cgi์ ์ก์ธ์คํ๋ ค๊ณ ํฉ๋๋ค (์ด๋ฅผ ์ญ์ ํ๋ ค๋ฉด ์ฒซ ๋ฒ์งธ iptables ๊ท์น ์ฐธ์กฐ).
GET /hndUnblock.cgi HTTP/1.0 302 186 - Wget(linux)
GET /tmUnblock.cgi HTTP/1.0 302 186 - Wget(linux)
๋๋์ด ์๋ก์ด ๊ณต๊ฒฉ์ด ์ง๋ 12 ์๊ฐ ๋์ ๋ง ์ด๋ฃจ์ด์ง ์๋ฒ์ ๋ํด ๋งค์ฐ ์๋กญ๋ค.
๋ต๋ณ
์ ๋ฐ์ดํธ : ํ์ฌ ๋ต๋ณ์ด ์์ ํ ์ ๋ฐ์ดํธ๋์์ต๋๋ค.
์ด ํ ๋ก ์ ๋ฐ๋ฅด๋ฉด WWW Security Assistant ๋ผ๋ GitHub ๋ฆฌํฌ์งํ ๋ฆฌ๋ฅผ ๋ง๋ค์์ต๋๋ค .
ask_ubuntu
์ด ๋ต๋ณ์ ์ ๋ ํ๋ ์ง์ ์ด ์์ต๋๋ค. ์ด์ ์ ์ฌ๊ธฐ์ ์ฌ์ฉ ๊ฐ๋ฅํ๋ ๋ชจ๋ ์ฐธ์กฐ ๋ ๋ฌธ์ ์ ํ์ผ๋ก ์ธํด ์ ๊ฑฐ๋ฉ๋๋ค. GitHub์์ ์ฌ์ฉ ๊ฐ๋ฅํฉ๋๋ค.
๋ค์์ Ubuntu 16.04 ๋ด์์ Apache2 ๋ณด์์ ๊ฐํํ๋ ๋ฐฉ๋ฒ ์ธ ์์ ํ ๋ฉ์ปค๋์ฆ๊ณผ ๊ด๋ จ๋ ๋ช ๊ฐ์ง ๋ฐฉ๋ฒ์ ๊ฐ๊ณผ ํ ๊ฒ์ ๋๋ค.
๋ด์ฉ์ ํ ์ด๋ธ:
- WWAS (WWW Security Assistant Script) โบ IP ํ ์ด๋ธ
- IPtables โ ๊ธฐ๋ณธ ๊ตฌ์ฑ โ ์ ์ฅ ๋ฐ ๋ณต์
- Apache2 ์ฉ ModEvasive
- ModEvasive โบ WSAS โบ IP ํ ์ด๋ธ
- Apache2 ์ฉ ModSecurity 2.9
- ModSecurity OWASP ํต์ฌ ๊ท์น ์ธํธ 3.x
- ModSecurity ๊ท์น ํ์ฉ ๋ชฉ๋ก
- ModSecurity ๊ท์น โบ WSAS โบ IP ํ ์ด๋ธ
- ModSecurity ๋ฐ Apache ๋ก๊ทธ ํ์ผ
- ModSecurity ๋ก๊ทธ ํ์ผ โบ Fail2Ban โบ Iptables
- ModSecurity GuardianLog โบ HTTPD Guardian โบ WSAS โบ IP ํ ์ด๋ธ
- ModSecurity GuardianLog โบ HTTPD ์ฌ์ฉ์ ์ ์ ๋ถ์ โบ WSAS โบ IP ํ ์ด๋ธ
๋ํ ํญ์ HTTPS๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด ์ข๋ค๊ณ ๊ฐ์ ํด ๋ด ์๋ค.
WWW ๋ณด์ ๋์ฐ๋ฏธ ์คํฌ๋ฆฝํธ โบ IP ํ ์ด๋ธ
๋ค์์ ์คํฌ๋ฆฝํธ www-security-assistant.bash
์
๋๋ค. ์
์์ ์ธ IP ์ฃผ์๋ฅผ ์ฒ๋ฆฌํ๋ ๋ฐ ๋์์ด ๋ ์ ์์ต๋๋ค. ์คํฌ๋ฆฝํธ์๋ ๋ ๊ฐ์ง ๋ชจ๋๊ฐ ์์ต๋๋ค.
์๋ ๋ชจ๋
Apache์ ์ธ๋ถ ํ๋ก๊ทธ๋จ mod_security
์ด ์
์ฑ $IP
์ฃผ์๋ฅผ ์ ๊ณตํ๋ ๊ฒฝ์ฐ ์ด ๊ฒฝ์ฐ ์คํฌ๋ฆฝํธ๋ฅผ ํธ์ถํ๋ ๊ตฌ๋ฌธ์ ๋ค์๊ณผ ๊ฐ์์ผํฉ๋๋ค.
www-security-assistant.bash <ip-address> Guardian
www-security-assistant.bash <ip-address> ModSecurity
www-security-assistant.bash <ip-address> ModEvasive
www-security-assistant.bash <ip-address> a2Analyst
์ด ๋ชจ๋์์ ์คํฌ๋ฆฝํธ๋ ๋ ๊ฐ์ง ์์ ๋จ๊ณ๋ฅผ ์ ๊ณต ํ๋ฉฐ ๋ชจ๋ ์์ ์ ๋ํด ๊ด๋ฆฌ์ ์๊ฒ ์ ์ ๋ฉ์ผ ์ ๋ณด๋ ๋๋ค .
-
์ฒซ ๋ฒ์งธ ๋จ๊ณ : ์ฒ์ ๋ช ๊ฐ์ โ๋ฒ์ฃโ์ ๋ํด ์์ค ์ ๊ฐ๊ณผ ๋์ผํ ๊ธฐ๊ฐ ๋์ ์์ค
$IP
๊ฐ ์ฐจ๋จ๋ฉ๋๋ค$BAN_TIME
. ์ด ๋ชจ๋๋ ๋ช ๋ น์ ์ฌ์ฉํฉ๋๋คat
. -
๋ ๋ฒ์งธ ๋จ๊ณ : ํน์ ๋ฒ์ฃ์ ์ซ์
$IP
๊ฐ์ ๊ฐ๊ณผ ๊ฐ์$LIMIT
๋์ด$IP
์ฃผ์๋ IP ํ ์ด๋ธ์ ํตํด ์๊ตฌ์ ์ผ๋ก ๊ธ์ง ๋๋ฉฐ์ ์ถ๊ฐ๋ฉ๋๋ค$BAN_LIST
.
์๋ ๋ชจ๋
์ด ๋ชจ๋๋ ๋ค์ ์ต์ ์ ํ์ฉํฉ๋๋ค.
-
www-security-assistant.bash <ip-address>
--DROP "log notes"
ํ์ผ์ ํญ๋ชฉ์ ์์ฑ
/var/www-security-assistant/iptables-DROP.list
ํ๊ณ ๋ค์๊ณผ ๊ฐ์ ๊ท์น์ ์์ฑํฉ๋๋ค.iptables -A GUARDIAN -s $IP -j DROP
-
www-security-assistant.bash <ip-address>
--DROP-CLEAR "log notes"
ํ์ผ์ ํญ๋ชฉ์ ์์ฑํ๊ณ
/var/www-security-assistant/iptables-DROP-CLEAR.list
, ํน์ Iptables ๊ท์น์ ์ ๊ฑฐํ๊ณ$IP
, ๊ธฐ๋ก์์ ๋ค์์ ์ ๊ฑฐ ํฉ๋๋ค$BAN_LIST
.iptables -D GUARDIAN -s $IP -j DROP
-
www-security-assistant.bash <ip-address>
--ACCEPT "log notes"
ํ์ผ์ ํญ๋ชฉ ๋ง ์์ฑํฉ๋๋ค
/var/www-security-assistant/iptables-ACCEPT.list
. -
www-security-assistant.bash <ip-address>
--ACCEPT-CHAIN "log notes"
ํ์ผ์ ํญ๋ชฉ์ ์์ฑ
/var/www-security-assistant/iptables-ACCEPT.list
ํ๊ณ ๋ค์๊ณผ ๊ฐ์ ๊ท์น์ ์์ฑํฉ๋๋ค.iptables -A GUARDIAN -s $IP -j ACCEPT
์์กด์ฑ
์คํฌ๋ฆฝํธ๋ ๋ค์ ์น์
์์ ์ค๋ช
iptables-save.sh
ํ๋ iptables
์ฒด์ธ์ ์ฌ์ฉ GUARDIAN
ํฉ๋๋ค. ๊ทธ๊ฒ์ ์์ ๋ช ๊ฐ์ ํ์ผ์ ์์ฑํ๊ณ ์ ์งํฉ๋๋ค $WORK_DIR
:
www-security-assistant.history
-์ด์ IP์ ๋ฒ์ฃ์ ๋ํ ๋ฐ์ดํฐ๋ฅผ ํฌํจํฉ๋๋ค.www-security-assistant.mail
-์คํฌ๋ฆฝํธ๊ฐ ๋ณด๋ธ ๋ง์ง๋ง ์ด๋ฉ์ผ์ ๋ด์ฉ.iptables-ACCEPT.list
;iptables-DROP.list
๊ทธ๋ฆฌ๊ณiptables-DROP-CLEAR.list
.
์ด๋ฉ์ผ์ ๋ณด๋ด๋ ค๋ฉด ์คํฌ๋ฆฝํธ๋ฅผ ์ต์ํ์ผ๋ก ๊ตฌ์ฑํด์ผํฉ๋๋ค.
sudo apt install s-nail mutt mailutils postfix
sudo dpkg-reconfigure postfix # For General type: Internet Site
echo 'Test passed.' | mail -s Test-Email email@example.com
๊ตฌ์ฑ๋ HTTPS ์๋น์ค๊ฐ ์์ผ๋ฉด Postfix ์๋น์ค ๋ด์์ TLS ์ธ์ฆ์๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
๋ํ ์คํฌ๋ฆฝํธ๋ at
๋ค์์ ์ฌ์ฉํฉ๋๋ค sudo apt install at
.
์ค์น
-
์์ ๋๋ ํ ๋ฆฌ๋ฅผ ๋ง๋ค๊ณ ํธ์ถํ์
/var/www-security-assistant
. ๋ค์ด๋ก๋www-security-assistant.bash
ํ์ฌ ์คํ ๊ฐ๋ฅํ๊ฒํ์ญ์์ค.sudo mkdir /var/www-security-assistant sudo wget https://raw.githubusercontent.com/pa4080/www-security-assistant/ask_ubuntu/www-security-assistant.bash -O /var/www-security-assistant/www-security-assistant.bash sudo chmod +x /var/www-security-assistant/www-security-assistant.bash
-
ํ์ธ
www-security-assistant.bash
์ฌ์ฉ์ ์ ์ ๋ช ๋ น์ผ๋ก ์ฌ์ฉํ ์ :sudo ln -s /var/www-security-assistant/www-security-assistant.bash /usr/local/bin/
-
๋ฅผ ํตํด ๋น๋ฐ๋ฒํธ์์ด
www-data
์คํํ ์์๋ ๊ถํ์ ๋ถ์ฌํ์ญ์์ค . ๋ค์ ๋ช ๋ น์ ์ฌ์ฉ ํ์ฌ ์ถ๊ฐ โ โ๊ท์น์ ์ฌ์ฉํ์ฌ ์ ํ์ผ์ ์์ ํ๊ฒ ์์ฑํ๊ณ ํธ์ง ํ์ญ์์ค .www-security-assistant.bash
sudo
sudoers
sudo visudo -f /etc/sudoers.d/www-security-assistant
ํ์ผ ์์ ๋ค์ ์ค์ ์ถ๊ฐํ์ญ์์ค-ํ์ผ์ ์ ์ฅํ๊ณ ์ข ๋ฃํ์ญ์์ค :
www-data ALL=(ALL) NOPASSWD: /var/www-security-assistant/www-security-assistant.bash
-
์กฐ์
www-security-assistant.bash
. ์ ์ด๋ ๋ณ์ ๊ฐ์ ๋ณ๊ฒฝํ์ญ์์ค$EMAIL_TO
.
๊ฑด๊ฐ ์ง๋จ
-
์์ ์
$AGENT
๋ํ๋ด๊ณ ์๋ ๋ชจ๋๊ฐ ์ ๋๋ก ์๋ํ๋์ง ํ์ธํ์ญ์์ค.www-security-assistant.bash 192.168.1.177 Guardian
๊ทธ๋ฐ ๋ค์ ์ ์ ๋ฉ์ผ์ ํ์ธํ๊ณ ์ ์ ๋ ฅ ํ
iptables -L GUARDIAN -n
๋ค์ ํ์ผ์ ๊ฒํwww-security-assistant.history
ํ๊ณwww-security-assistant.mail
. ์์ ๋ช ๋ น 5 ๋ฒ ์คํํ๊ณ ํ์ผ์ ๊ฒํiptables-DROP.list
ํ๊ณiptables-CURRENT.conf
. -
์๋ ๋ชจ๋๊ฐ ์ ๋๋ก ์๋ํ๋์ง ํ์ธํ์ญ์์ค. ํ์ดํธ๋ฆฌ์คํธ์ ๋ก์ปฌ ํธ์คํธ๋ฅผ ์ถ๊ฐํ์ญ์์ค.
www-security-assistant.bash 127.0.0.1 --ACCEPT "Server's localhost IP"
๊ทธ๋ฐ ๋ค์ ํ์ผ์ ํ์ธํ์ญ์์ค
iptables-ACCEPT.list
.
์ด ํ์ต์์ ๋๋จธ์ง ๋ถ๋ถ์
www-security-assistant
์์คํ ๊ณผ ํตํฉํ๋ ๋ฐฉ๋ฒ ์ ๋๋ค.
IPtables โ ๊ธฐ๋ณธ ๊ตฌ์ฑ โ ์ ์ฅ ๋ฐ ๋ณต์
๊ธฐ๋ณธ ๊ตฌ์ฑ
๋ค์ ๊ท์น์ ์ถ๊ฐํ๊ธฐ ์ ์์ด ์ค๋ช ์ ๋ฅผ ์ฝ์ผ์ญ์์ค .
sudo iptables -F
sudo iptables -I INPUT 1 -i lo -j ACCEPT
sudo iptables -I INPUT 2 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
# This rule may lock you out of the system!
sudo iptables -P INPUT DROP
sudo iptables -P OUTPUT ACCEPT
๋ค์ ์์ ์ ์ํํ๊ธฐ ์ ์ ์ SSH ์ฐ๊ฒฐ์ ์ด๊ณ ์์คํ ์ ๋ก๊ทธ์ธํ์ฌ ๋ชจ๋ ๊ฒ์ด ์ ๋๋ก ์๋ํ๋์ง ํ์ธํ์ญ์์ค!
์ ์ฅ ๋ฐ ๋ณต์
์ด๊ฒ์ iptables
์์คํ
์ ์ ์ง-์์ (๋๋ ์ฌ๋ถํ
) ๊ณผ์ ์์ coning์ ์ ์ฅํ๊ณ ๋ณต์ํ๋ ์ฌ์ฉ์ ์ง์ ์คํฌ๋ฆฝํธ๋ฅผ ํตํด ๋ฌ์ฑ ํ ์ ์์ต๋๋ค . (UFW๋ฅผ ์ฌ์ฉํ์ฌ IPtables ๊ท์น์ ์ค์ ํ๋ ๊ฒฝ์ฐ์ด ๋จ๊ณ๋ ํ์ํ์ง ์์ต๋๋ค.)
printf '#!/bin/sh\n/sbin/iptables-save > /var/www-security-assistant/iptables-CURRENT.conf\nexit 0\n' | sudo tee /var/www-security-assistant/iptables-save.sh
printf '#!/bin/sh\n/sbin/iptables-restore < /var/www-security-assistant/iptables-CURRENT.conf\nexit 0\n' | sudo tee /var/www-security-assistant/iptables-restore.sh
sudo chmod +x /var/www-security-assistant/iptables-restore.sh /var/www-security-assistant/iptables-save.sh
sudo ln -s /var/www-security-assistant/iptables-save.sh /etc/network/if-post-down.d/iptables-save
sudo ln -s /var/www-security-assistant/iptables-restore.sh /etc/network/if-pre-up.d/iptables-restore
์๋ก์ด ์ฒด์ธ ๋ง๋ค๊ธฐ
ํธ์ถ ๋ ์ ์ฒด์ธ์ ์์ฑํ๊ณ ์ฒด์ธ์ GUARDIAN
๋ฒํธ 3์ผ๋ก ์ฝ์
ํ์ญ์์ค INPUT
.
sudo iptables -N GUARDIAN
sudo iptables -I INPUT 3 -j GUARDIAN
๊ฑด๊ฐ ์ง๋จ
์์คํ
์ ์ฌ๋ถํ
ํ๊ณ ๊ตฌ์ฑ์ ํ์ธํ์ญ์์ค. ์ฌ์ฉํ์๊ธฐ ๋ฐ๋๋๋ค sudo systemctl reboot
(๊ฐ์ ์ต์
์ ์ฌ์ฉํ์ง ๋ง์ญ์์ค reboot -f
). ์์คํ
์ด ์จ๋ผ์ธ ์ํ๊ฐ๋๋ฉด ์๋ก ์์ฑ ๋ ์ฒด์ธ์ด ์กด์ฌํ๋์ง ํ์ธํ ์ ์์ต๋๋ค.
sudo iptables -L GUARDIAN -n
Apache2 ์ฉ ModEvasive
ModEvasive๋ HTTP DoS ๋๋ DDoS ๊ณต๊ฒฉ ๋๋ ๋ฌด์ฐจ๋ณ ๋์ ๊ณต๊ฒฉ์ Apache๊ฐ ํํผ ์กฐ์น๋ฅผ ์ ๊ณตํ๋ ํํผ ๊ธฐ๋ ๋ชจ๋์ ๋๋ค. ๋ ์ฝ์ด๋ณด๊ธฐ โฆ
์ค์น
-
๋ชจ๋์ ์ค์นํ๊ณ ํ์ฑํํ์ญ์์ค :
sudo apt install libapache2-mod-evasive sudo a2enmod evasive
-
๋ก๊ทธ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํ์ฌ ๋ค์์ ์ก์ธ์ค ํ ์์๊ฒํ์ญ์์ค
www-data
.sudo mkdir -p /var/log/apache2_mod_evasive sudo chown www-data /var/log/apache2_mod_evasive
-
๊ธฐ๋ณธ ๊ตฌ์ฑ์ ์กฐ์ โ ๊ตฌ์ฑ ํ์ผ์์ ํน์ ์ง์๋ฌธ์ ์ฃผ์ ํด์ ํ๊ณ ํธ์งํ์ญ์์ค.
/etc/apache2/mods-enabled/evasive.conf
-
Apache๋ฅผ ๋ค์ ์์ํ์ญ์์ค
sudo systemctl restart apache2.service
.
๊ฑด๊ฐ ์ง๋จ
- ์๋ฒ์์ ์น ํ์ด์ง๋ฅผ ์ด๊ณ ๋ธ๋ผ์ฐ์ ์ฐฝ์ ์ง์ค์ ์ผ๋ก ๋ช ๋ฒ ์๋ก ๊ณ ์น์ญ์์ค (๋ฅผ ๋๋ฅด์ญ์์ค
F5
) . 403 Forbidden ์ค๋ฅ ๋ฉ์์ง๊ฐ ํ์ ๋์ด์ผํฉ๋๋ค . ๋ก๊ทธ ๋๋ ํ ๋ฆฌ์ ์๋ก์ด ์ ๊ธ ํ์ผ์ด ์์ฑ๋ฉ๋๋ค. ์ด IP ์ฃผ์์์ ์ถ๊ฐ ์๋ฐ์ ๊ฐ์งํ๋ ค๋ฉด์ด ํ์ผ์ ์ญ์ ํด์ผํฉ๋๋ค.
ModEvasive โบ WSAS โบ IP ํ ์ด๋ธ
์ฌ๊ธฐ์ ์ฐ๋ฆฌ๋ ์ ์น์
์์ ์์ฑ mod_evasive
๋๋ฅผ iptables
ํตํด ๋ํ ํ๋๋ก ๊ตฌ์ฑ ํ ๊ฒ www-security-assistant.bash
์
๋๋ค.
-
/etc/apache2/mods-available/evasive.conf
์ด ๋ฐฉ๋ฒ์ผ๋ก ํธ์งํ์ญ์์ค :<IfModule mod_evasive20.c> DOSHashTableSize 3097 DOSPageCount 9 DOSSiteCount 70 DOSPageInterval 2 DOSSiteInterval 2 DOSBlockingPeriod 10 #DOSEmailNotify your@email.foo DOSLogDir "/var/log/apache2_mod_evasive" DOSSystemCommand "sudo /var/www-security-assistant/www-security-assistant.bash %s 'ModEvasive' 'AutoMode' >> /var/www-security-assistant/www-security-assistant.execlog 2>&1" </IfModule>
-
๋ก๊ทธ ํ์ผ์ ์์ฑํ๊ณ Apache๋ฅผ ๋ค์ ์์ํ์ญ์์ค.
sudo touch /var/www-security-assistant/www-security-assistant.execlog && sudo chown www-data /var/www-security-assistant/www-security-assistant.execlog
์ฐ๋ฆฌ๋์ ํตํด DDoS ๊ณต๊ฒฉ์ ์๋ฎฌ๋ ์ด์
ํ ์ ์์ต๋๋ค์ด ๊ตฌ์ฑ์ ํ
์คํธํ๊ธฐ ์ํด F5
๋ฐฉ๋ฒ์, ์์์ ์ธ๊ธ ํ, ๋๋ ์ฐ๋ฆฌ๋ ๊ฐ์ ๋ช
๋ น์ ์ฌ์ฉํ ์ ์์ต๋๋ค ab
, hping3
๋ฑ
์ฃผ์ :iptables
WSAS์์ ์ฌ์ฉ๋๋ ๊ท์น์ SSH ์ฐ๊ฒฐ์ ํฌํจํ์ฌ ์์ค์ ๋ชจ๋ ์ ์ฐ๊ฒฐ์ ์ญ์ ํ๋ฏ๋ก ์ฃผ์ ํ์ญ์์ค $IP
. ํ
์คํธํ๋ ๋์ ์๋ฒ์ ์ฐ๊ฒฐํ๋ ๋ฐฑ์
๋ฐฉ๋ฒ์ด ์ข์ต๋๋ค. HTTP / HTTPS ํฌํธ์์๋ง ์๋ํ๋๋ก์ด ๊ท์น์ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค.
Apache2 ์ฉ ModSecurity 2.9
ModSecurity ๋ ์์ฒด์ ์ผ๋ก ๊ฑฐ์ ๋ณดํธ ๊ธฐ๋ฅ์ ์ ๊ณตํ์ง ์๋ ์น ์์ฉ ํ๋ก๊ทธ๋จ ๋ฐฉํ๋ฒฝ ์์ง์ ๋๋ค. ์ ์ฉํ๊ฒ ์ฌ์ฉํ๋ ค๋ฉด ModSecurity๋ฅผ โโ๊ท์น์ผ๋ก ๊ตฌ์ฑํด์ผํฉ๋๋ค. Trustwave์ Spider Labs๋ ์ฌ์ฉ์๊ฐ ์ฆ์ ModSecurity๋ฅผ โโ์ต๋ํ ํ์ฉํ ์ ์๋๋ก ๋ฌด๋ฃ๋ก ์ธ์ฆ ๋ ๊ท์น ์ธํธ๋ฅผ ์ ๊ณตํฉ๋๋ค .
์ค์น
-
๋ชจ๋์ ์ค์นํ๊ณ ํ์ฑํํ์ญ์์ค :
sudo apt install libapache2-mod-security2 sudo a2enmod security2
-
๊ตฌ์ฑ ํ์ผ์ ์์ฑํ์ญ์์ค.
sudo cp /etc/modsecurity/modsecurity.conf ๊ถ์ฅ /etc/modsecurity/modsecurity.conf
/etc/modsecurity/modsecurity.conf
์ฃผ์ ๊น๊ฒ ์ฝ๊ณ ํธ์งํ์ญ์์ค ! ์ต์ํ ๋ค์ ์ง์๋ฌธ์ ์ถ๊ฐํ๊ฑฐ๋ ๋ณ๊ฒฝํ์ญ์์ค.# -- Rule engine initialization ---------------------------------------------- SecRuleEngine On # -- Debug log configuration ------------------------------------------------- SecDebugLogLevel 2 SecDebugLog "/var/log/apache2_mod_security/modsec_debug.log" # -- Audit log configuration ------------------------------------------------- SecAuditLog "/var/log/apache2_mod_security/modsec_audit.log" # -- Guardian log configuration ------------------------------------------------- SecGuardianLog /var/log/apache2_mod_security/modsec_guardian.log
-
์ด ํ์ผ
/etc/apache2/mods-enabled/security2.conf
์/etc/modsecurity/modsecurity.conf
Apache ๊ตฌ์ฑ๊ณผ ๊ด๋ จ ์ด ์์ต๋๋ค. ์ด ๋จ๊ณ์์security2.conf
๋ค์๊ณผ ๊ฐ์ด ๋ณด์ผ ๊ฒ์ ๋๋ค :<IfModule security2_module> SecDataDir /var/cache/modsecurity IncludeOptional /etc/modsecurity/*.conf </IfModule>
-
๋ก๊ทธ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํ์ญ์์ค.
sudo mkdir -p /var/log/apache2_mod_security
-
์ค์ ๋ก๊ทธ ํ์ . ๋จผ์ ๊ตฌ์ฑ ํ์ผ์ ์์ฑํ์ญ์์ค.
sudo cp /etc/logrotate.d/apache2 /etc/logrotate.d/apache2-modsec
๊ทธ๋ฐ ๋ค์์ด ๋ฐฉ๋ฒ์ผ๋ก ์ โโํ์ผ์ ํธ์งํ์ญ์์ค.
/var/log/apache2_mod_security/*.log { โฆ }
-
Apache๋ฅผ ๋ค์ ์์ํ์ญ์์ค.
๊ฑด๊ฐ ์ง๋จ
-
์ ์ถ๊ฐ ๊ตฌ์ฑ ํ์ผ์ ์์ฑํ๊ณ
/etc/modsecurity
์๋ฅผ ๋ค์ด ํธ์ถ ํz-customrules.conf
ํ ๋ค์ ๊ท์น์ ์ปจํ ์ธ ๋ก ์ถ๊ฐํ์ญ์์ค.# Directory traversal attacks SecRule REQUEST_URI "../" "t:urlDecodeUni, deny, log, id:109"
์๋ฒ๋ฅผ ๋ค์ ์์ํ์ญ์์ค
sudo systemctl restart apache2.service
.. ๋ธ๋ผ์ฐ์ ๋ฅผ ์ด๊ณ ์ ์ ๋ ฅํ์ญ์์คhttps://example.com/?abc=../
. ๊ฒฐ๊ณผ : 403 Forbidden ./var/log/apache2_mod_security
์์ธํ ๋ด์ฉ ์ ๋ก๊ทธ ํ์ผ์ ํ์ธ ํ์ญ์์ค. -
๋ฌผ๊ฑด์ ๋ ์ฌ๋ฏธ์๊ฒ ๋ง๋ค๊ธฐ ์ํด ์คํฌ๋ฆฝํธ
issues.php
๋ฅผ ๊ทํ์ ์ ์ ํ ์์น์ ๋ฐฐ์นํ์ญ์์คDocumentRoot
(์ฌ๊ธฐ์๋์ด ์ฅ์๊ฐ ์๋ค๊ณ ๊ฐ์ ํฉ๋๋ค/var/www/html
).sudo wget https://raw.githubusercontent.com/pa4080/www-security-assistant/ask_ubuntu/appendix/var/www/html/issues.php -O /var/www/html/issues.php
๊ทธ๋ฐ ๋ค์ ๋ค์ ๋ฐฉ๋ฒ์ผ๋ก ์ ๊ท์น์ ์์ ํ์ญ์์ค.
# Directory traversal attacks with redirection (or use URL instead of URI: redirect:'https://example.com/issues.php') SecRule REQUEST_URI "../" "t:urlDecodeUni, deny, log, id:109, redirect:'/issues.php'"
Apache๋ฅผ ๋ค์ ์์ํ ๋ค์ ๋ธ๋ผ์ฐ์ ๋ฅผ ์ด๊ณ
https://example.com/?abc=../
;-)๋ฅผ ์ ๋ ฅํ์ญ์์ค . ์์ด๋์ด๋ SE์ ์คํฌ๋ฆฝํธ์์ ๋น ๋ ธ์ต๋๋คBotLovin.cs
. -
/etc/modsecurity/z-customrules.conf
๋ค์ ํ ๋ฒ ํธ์ง ํ๊ณ ๊ท์น์ ์ฃผ์ ์ฒ๋ฆฌ (๋นํ์ฑํ)ํฉ๋๋ค. ์ด๊ฒ์ ํ ์คํธ ์์ ์ผ ๋ฟ์ด๋ฉฐ ๋ค์ ์น์ ์์ ์ค๋ช ํ๋ OWASP CRS์ ์ํด ์ค๋ช ๋ฉ๋๋ค. -
๋ค์์ ๋ชจ๋
wp-admin
ํ์ด์ง ์์ฒญ ์ ๋ฆฌ๋๋ ์ ํ์ง๋ง ํน์ IP ์ฃผ์์ ์์ฒญ์ ์ ์ธํ ๋ค๋ฅธ ์์ ๋๋ค (์ฐธ๊ณchain
).# Block wp-admin access SecRule REQUEST_URI "^/wp-admin" "id:108, log, deny, status:403, t:lowercase, chain, redirect:'/issues.php'" SecRule REMOTE_ADDR "!@ipMatch 192.168.1.11,99.77.66.12"
์ฌ๊ธฐ์๋ (1)
deny, status:403
๊ณผ (2)์ ๋ ๊ฐ์ง ํ๊ดด์ ์ธ ํ๋์ดredirect:'/issues.php'
์์ต๋๋ค. ์ค์ ๋กdeny
์กฐ์น์ ์ํด ๋์ฒด๋๋ฏ๋ก ์กฐ์น ๊ฐ ํ์ํ์ง ์์ต๋๋คredirect
.
ModSecurity OWASP ํต์ฌ ๊ท์น ์ธํธ 3.x
Ubuntu 16.04์์๋ CSR 2.x๋ฅผ ์ค์นํ ์ ์์ต๋๋ค apt install modsecurity-crs
. ์ฌ๊ธฐ์๋ CSR 3.x ๋ฅผ ์ค์นํฉ๋๋ค . ์์ธํ ์ง์นจ์ ์ค์น ์ค๋ช
์์ ๋์ ์์ต๋๋ค ( git
ํ์).
์ค์น
-
ํด๋์์ CSR์ ๋ณต์ ํ์ญ์์ค
/usr/share/modsecurity-crs.3
.sudo git clone https://github.com/SpiderLabs/owasp-modsecurity-crs /usr/share/modsecurity-crs.3
-
GeoIP ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์ ๊ทธ๋ ์ด๋ํ๊ณ ์๋ ๊ฐฑ์ ํฉ๋๋ค. (GeoIP DB๋ ๋ ์ด์ CRS์ ํฌํจ๋์ง ์์ต๋๋ค. ๋์ ์ ๊ธฐ์ ์ผ๋ก ๋ค์ด๋ก๋ํ๋ ๊ฒ์ด ์ข์ต๋๋ค.)์ด ์คํฌ๋ฆฝํธ
util/upgrade.py
๋์ด ๊ธฐ๋ฅ์ ์ ๊ณตํฉ๋๋ค. cron-์์ ๋ค์๊ณผ ๊ฐ์ด ์ฌ์ฉํ ์ ์์ต๋๋คsudo crontab -e
.0 2 * * * /usr/share/modsecurity-crs.3/util/upgrade.py --geoip --crs --cron >> /var/log/apache2_mod_security/owasp-crs-upgrade.log 2>&1
-
๊ตฌ์ฑ ํ์ผ์ ์์ฑํ์ญ์์ค.
sudo cp /usr/share/modsecurity-crs.3/crs-setup.conf{.example,} sudo cp /usr/share/modsecurity-crs.3/rules/REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf{.example,} sudo cp /usr/share/modsecurity-crs.3/rules/RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf{.example,}
์ด ํ์ผ๋ค์์ฃผ์ ๊น๊ฒ ์ฝ๊ณ ํธ์งํ์ญ์์ค! ์ต์ํ
SecGeoLookupDB
์ง์๋ฌธ์ ์ฃผ์์ ํด์ ํ์ญ์์ค .SecGeoLookupDB util/geo-location/GeoIP.dat
-
Apache์ ๊ตฌ์ฑ์ ์ ์ฉํ์ญ์์ค.
/etc/apache2/mods-available/security2.conf
์ด ๋ฐฉ๋ฒ์ผ๋ก ํธ์งํ์ญ์์ค :<IfModule security2_module> SecDataDir /var/cache/modsecurity IncludeOptional /etc/modsecurity/*.conf IncludeOptional /usr/share/modsecurity-crs.3/crs-setup.conf IncludeOptional /usr/share/modsecurity-crs.3/rules/*.conf </IfModule>
ํ์ผ์ ์ ์ฅ ํ ๋ค์ Apache๋ฅผ ๋ค์ ์์ํ์ญ์์ค.
ModSecurity ๊ท์น ํ์ฉ ๋ชฉ๋ก
ModSecurity ๊ท์น์ ํ์ดํธ๋ฆฌ์คํธ๋ ๋ค์ ModSec ์ง์๋ฌธ์ ํตํด ์ํ ํ ์ ์์ผ๋ฉฐ, ์์คํ ์ ์ฒด ๋๋ ๊ฐ์ ํธ์คํธ ๊ตฌ์ฑ ๋ด์์ ํน์ ๋๋ ํ ๋ฆฌ ๋๋ ์์น ์ผ์น๋ฅผ ์ํด ์ ์ฒด์ ์ผ๋ก ์ฌ์ฉํ ์ ์์ต๋๋ค.
SecRuleRemoveById
SecRuleRemoveByMsg
SecRuleRemoveByTag
SecRuleUpdateTargetById
SecRuleUpdateTargetByMsg
SecRuleUpdateTargetByTag
SecRuleUpdateActionById
mod_security2
PhpMyAdmin์ ๋นํ์ฑํ ํฉ๋๋ค. /etc/phpmyadmin/apache.conf
์ด ๋ฐฉ๋ฒ์ผ๋ก ๋ณ๊ฒฝํ์ญ์์ค :
<Directory /usr/share/phpmyadmin>
<IfModule security2_module>
SecRuleEngine Off
</IfModule>
</Directory>
ํน์ ๋๋ ํ ๋ฆฌ์ ๋ํ ํน์ ๊ท์น์ ๋นํ์ฑํํ์ญ์์ค.
<Directory /var/www/html>
<IfModule security2_module>
SecRuleRemoveById 973301
</IfModule>
</Directory>
์ ์ญ ์ ์ผ๋ก ๊ท์น์ ๋นํ์ฑํํฉ๋๋ค. ์ด๋ฅผ ์ํด Apache ๊ตฌ์ฑ ํ์ผ ์ด๋๊ฐ์ ์ง์๋ฌธ์ ์ถ๊ฐํด์ผํฉ๋๋ค /etc/modsecurity/z-customrules.conf
.
-
์ ์ฒด Apache ๊ตฌ์ฑ ๋ด์์ ๊ท์น์ ๋นํ์ฑํํ์ญ์์ค.
SecRuleRemoveById 973301 950907
-
ModSecurity๋ฅผ โโํต๊ณผ ํ ์ ์๋๋ก IP ์ฃผ์๋ฅผ ํ์ดํธ๋ฆฌ์คํธ์ ์ถ๊ฐํ์ญ์์ค.
SecRule REMOTE_ADDR "@ipMatch 192.168.110.1" "phase:1,nolog,allow,ctl:ruleEngine=Off,ctl:auditEngine=Off"
-
๋๋ ํ ๋ฆฌ ์ผ์น ๋ด ๊ท์น์ ์ฌ์ฉ ์ค์งํฉ๋๋ค.
<Directory /var/www/mediawiki/core> SecRuleRemoveById 973301 950907 </Directory>
-
์์น ์ผ์น ๋ด์์ ID๋ณ๋ก ๊ท์น ๋์ ์ ๋ฐ์ดํธ :
<LocationMatch "/index.php.*"> SecRuleUpdateActionById 973301 "pass" SecRuleUpdateActionById 950907 "pass" </LocationMatch>
์์ ์์์ ์ฐ๋ฆฌ๋ ๊ฐ์ 973301
๋ฐ 950907
์ฐ๋ฆฌ์ ์น ์์ฉ ํ๋ก๊ทธ๋จ์ ์ ์ ์๋์ ๋ฐฉํด ๊ท์น ID๊ฐ ์์ต๋๋ค. ์ ๋ถ์์ ํตํด ์ด์ ๊ฐ์ ๊ท์น์ ์ฐพ์ ์ ์์ต๋๋ค modsec_audit.log
.
ModSecurity ๊ท์น โบ WSAS โบ IP ํ ์ด๋ธ
๋ค์์ ์ฌ์ฉ์ ์ ์ SecRules๋ฅผ ์์ฑํ๋ ๋ฐฉ๋ฒ๊ณผ WWAS (WWW Security Assistant Script)๋ฅผ ํธ์ถํ๋ ๋ฐฉ๋ฒ์ ๋ํ ๋ช ๊ฐ์ง ์์ ๋๋ค.
์ด๊ธฐ ์ค์
์ถ๊ฐ ์์ ์คํฌ๋ฆฝํ
์ด ํ์ํฉ๋๋ค modsecurity-assistant.sh
. ๊ทธ ์ด์ ๋ ModSecurity์ exec
๋์์ด ๋๋ฌด ๋จ์ํ๊ณ ์ ํ์ ์ธ ๊ตฌ๋ฌธ์ ๊ฐ์ง๊ณ ์๊ธฐ ๋๋ฌธ์
๋๋ค .
sudo wget https://raw.githubusercontent.com/pa4080/www-security-assistant/ask_ubuntu/modsecurity-assistant.sh -O /var/www-security-assistant/modsecurity-assistant.sh
sudo chmod +x /var/www-security-assistant/modsecurity-assistant.sh
์คํฌ๋ฆฝํธ ๋ด๋ถ๋ฅผ ๋ณด๋ฉด ModSecurity์์ ๋ด ๋ณด๋ธ ๋ณ์๊ฐ ๊ฑฐ์ ์์ต๋๋ค. ์ด๋ค์ : $REQUEST_URI
, $ARGS
, $SERVER_NAME
, $REMOTE_ADDR
, $REMOTE_HOST
์ $UNIQUE_ID
. ๋ค๋ฅธ ๋ณ์๋ ์คํฌ๋ฆฝํธ ๋ด๋ถ์ ์ค๋ช
๋์ด ์์ต๋๋ค.
์ฌ์ฉ์ ์ ์ ๊ท์น์ ์์ฑํ๊ณ ์ด๋ฅผ ํตํด ์คํฌ๋ฆฝํธ๋ฅผ ํธ์ถํ์ญ์์ค.
๋จผ์ ์์ฒญ URI์ ๋ธ๋๋ฆฌ์คํธ์ ํฌํจ ๋ ๋จ์ด๊ฐ ํฌํจ๋์ด์์ ๋ ์คํ๋ modsecurity-assistant.sh
(๋ฐ ํธ์ถ www-security-assistant.bash
) ๊ท์น์ ์์ฑํด ๋ณด๊ฒ ์ต๋๋ค . /etc/modsecurity/z-customrules.conf
์๋ ์ค์ ์ด๊ณ ์๋์ ์ถ๊ฐํ์ญ์์ค.
# REQUEST_URI words blacklist
#
SecRule REQUEST_URI "@pmFromFile /var/www-security-assistant/modsecurity-uri-black.list" \
"id:150, log, t:lowercase, chain, \
drop, deny, status:403, redirect:'/issues.php'"
SecRule REMOTE_ADDR "!@ipMatchFromFile /var/www-security-assistant/modsecurity-ip-white.list" \
"setenv:REMOTE_HOST=%{REMOTE_HOST}, \
setenv:ARGS=%{ARGS}, \
exec:/var/www-security-assistant/modsecurity-assistant.sh"
-
REQUEST_URI
-์ด ๋ณ์์๋ ํ์ฌ ์์ฒญ์ ์ ์ฒด URI๊ฐ ํฌํจ๋ฉ๋๋ค. ๊ท์น์ ๋ ๋์ต๋๋ค.SecRule REQUEST_URI|ARGS|REQUEST_BODY ...
-
@pmFromFile
modsecurity-uri-black.list
๊ฐ ํน์ ๋ฌธ๊ตฌ ๋ ๋จ์ด๊ฐ ์ ์ค์ ๋ฐฐ์น๋๋ ๋ฌธ๊ตฌ ๋ชฉ๋ก์ด ํฌํจ ๋ ํ์ผ ์ ์ฝ์ต๋๋ค . ๋ก๊ทธ ํ์ผ์์ ํฅ๋ฏธ๋ก์ด ๋จ์ด์ ๋ฌธ๊ตฌ๋ฅผ ์์ง ํ ์ ์์ต๋๋ค. ํจํด ๋ชฉ๋ก๊ณผ ํจํด ๋ชฉ๋ก ์ฌ์ด์ ํน์ ์ผ์น ํญ๋ชฉ ์ด ์์ผ๋ฉดREQUEST_URI
๊ท์น์ด ์ ์ฉ๋ฉ๋๋ค. ํ์ผ์ด ๋น์ด์์ ์ ์์ง๋ง ํ์ผ์ ์์ฑ (touch
)ํด์ผํฉ๋๋ค. -
์ด
log
์์ ์ ์ํํ๋ฉด์ด ๊ท์น์ ๋ํ ๋ก๊ทธ ํ์ผ์ ๋ก๊ทธ ํญ๋ชฉ์ด ์์ฑ๋ฉ๋๋คid:150
. -
drop
,deny
(ํฌํจstatus
) ๋ฐredirect
์์ ์ ํ๊ดด์ ์ธ ์์ ๊ทธ๋ฃน์ ์ํ๋ฉฐ ๊ท์น์ ์์ ๋ถ๋ถ์ ์์ด์ผํฉ๋๋คchain
(์ฒด์ธ์ด์๋ ๊ฒฝ์ฐ). ๋ ๋ฒ์งธ ์์ ์ ์ฒซ ๋ฒ์งธ ์์ ๋ณด๋ค ์ฐ์ ํ๊ณ ์ธ ๋ฒ์งธ ์์ ์ ๋ ๋ฒ์งธ ์์ ๋ณด๋ค ์ฐ์ ํ๋ฏ๋ก ์ํ ํ ์์ ์ ์ ํํ๊ณ ๋ค๋ฅธ ์์ ์ ์ญ์ ํ ์ ์์ต๋๋ค. -
chain
action์ ์ฒด์ธ์ ๋ค์ ๊ท์น์ ํธ์ถํฉ๋๋ค. ๋ ๋ฒ์งธ ๊ท์น์๋ ์์ต๋๋คid
. -
REMOTE_ADDR
์์ฒญ์ IP ์ฃผ์๋ฅผ ํฌํจํฉ๋๋ค. -
@ipMatchFromFile
modsecurity-ip-white.list
IP ์ฃผ์์ ํ์ดํธ๋ฆฌ์คํธ๋ฅผ ํฌํจ ํ๋ ํ์ผ ์ด ์ ์ค๋ก ๋ถ๋ฆฌ๋ฉ๋๋ค. CIDR ํญ๋ชฉ๋ ํ์ฉ๋ฉ๋๋ค. ๋๋ฌธ์ ํ๊ดด์ ์ธ ํ๋์ด ํญ์ ์ ์ฉ๋ฉ๋๋ค ์ฒด์ธ์ ์ ๋ ๊ท์น์ ์์นํ๊ณ ์์ง๋ง ํน์ IP์ด ํ์ดํธ๋ฆฌ์คํธ์์์ ๋exec
์กฐ์น๊ฐ ์ ์ฉ๋์ง ์์ต๋๋ค. ํ์ผ์ด ๋น์ด์์ ์ ์์ง๋ง ํ์ผ์ ์์ฑ (touch
)ํด์ผํฉ๋๋ค. -
exec
์ก์ ์ ์ธ๋ถ ์คํฌ๋ฆฝํธ๋ฅผ ํธ์ถํฉ๋๋ค. ์ด ์์ ์ ์ค๋จ ๋์ง ์์ผ๋ฉฐ ํ์ฌ ๊ท์น์ด true๋ฅผ ๋ฐํํ๋ฉด ์คํ๋ฉ๋๋ค. ์ด ์กฐ์น๊ฐ ์ ์ฉ๋๋ฉด ์๊ฒฉ IP๋ ์คํฌ๋ฆฝํธ๋ฅผ ํตํด ์ฒ๋ฆฌ๋ฉ๋๋ค. -
setenv
์ด ์กฐ์น๋ ํน์ ๋ด๋ถ ๋ณ์=%{...}
๋ฅผ envvar๋ก ๋ด ๋ณด๋ด๋ฉฐ ๋ด ๋ณด๋ธ ์ด๋ฆ์ ๋ด๋ถ ๋ณ์ ์ ๋ค๋ฅผ ์ ์์ต๋๋ค. ์ผ๋ถ ๋ณ์๋ ์๋์ผ๋ก ๋ด ๋ณด๋ด์ผํ๊ณ ๋ค๋ฅธ ๋ณ์๋ ์๋์ผ๋ก ๋ด ๋ณด๋ด์ผํฉ๋๋ค. ์์ ๋ฒ๊ทธsetenv:REQUEST_URI=%{REQUEST_URI}
์ผ ์ ์์ต๋๋ค ( ์ : ๊ฐ์ ์ด๋ฆ์ ๊ฐ์ง ์๋ ๋ด๋ณด๋ด๊ธฐ ๋ ๋ด ๋ณด๋ธ ๋ณ์์ ๋น ๊ฐ์ ์ ๋ฐํ ์ ์์ต๋๋ค).
๊ฑด๊ฐ ์ง๋จ
์๋ฒ์ Joomla๊ฐ ์๋ค๊ณ ๊ฐ์ ํ๊ณ ํ์ผ์ ํธ์งํ๊ณ modsecurity-uri-black.list
content ํ์ ์ถ๊ฐํ์ญ์์ค /joomla
. ๊ทธ๋ฐ ๋ค์ ๋ธ๋ผ์ฐ์ ์ ์
๋ ฅํ์ญ์์ค https://exemple.com/joomla
. Iptables๋ฅผ ํตํด ๋ฆฌ๋๋ ์
๋๊ณ ์ฐจ๋จ๋์ด์ผํฉ๋๋ค. ๊ธฐ๋ก์ ์ง์ฐ๊ณ sudo www-security-assistant.bash <your-ip> --DROP-CLEAR 'some note'
IP๋ฅผ ์ถ๊ฐ ํ modsecurity-ip-white.list
ํ ๋ค์ ์ฐ์ตํ์ญ์์ค. ์ด์ ๋ฆฌ๋๋ ์
๋์ด์ผํ์ง๋ง ์ฐจ๋จ๋์ง ์์์ผํฉ๋๋ค.
์คํฌ๋ฆฝํธ๋ฅผ OWASP Core Rule Set 3.x์ ์ฐ๊ฒฐ
์ด๋ฅผ ์ํด Anomaly Mode Rules (949110 ๋ฐ 959100) ์ ๊ธฐ๋ณธ ๋์์ ์
๋ฐ์ดํธํฉ๋๋ค . ์ด๋ฅผ ์ํด ํ์ผ์ ํธ์งํ๊ณ /usr/share/modsecurity-crs.3/rules/RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf
๋ค์ ํ์ ๋งจ ์๋์ ์ถ๊ฐํ์ญ์์ค.
# -- Anomaly Mode - Update actions by ID -----
#
SecRuleUpdateActionById 949110 "t:none, drop, deny, status:403, redirect:'/issues.php', \
setenv:REMOTE_HOST=%{REMOTE_HOST}, setenv:ARGS=%{ARGS}, \
exec:/var/www-security-assistant/modsecurity-assistant.sh"
SecRuleUpdateActionById 959100 "t:none, drop, deny, status:403, redirect:'/issues.php', \
setenv:REMOTE_HOST=%{REMOTE_HOST}, setenv:ARGS=%{ARGS}, \
exec:/var/www-security-assistant/modsecurity-assistant.sh"
# -- Anomaly Mode - Whitelist some URI and IP addresses -----
#
SecRule REQUEST_URI "^/wp-admin/admin-ajax.php*|^/index\.php\?title=.*&action=(submit|raw&ctype=text/javascript|raw&ctype=text/css)$" \
"id:'999010', t:none, phase:1, pass, \
ctl:ruleRemoveById=949110, \
ctl:ruleRemoveById=959100"
SecRule REMOTE_ADDR "@ipMatchFromFile /var/www-security-assistant/modsecurity-ip-white.list" \
"id:'999020', t:none, phase:1, pass, \
ctl:ruleRemoveById=949110, \
ctl:ruleRemoveById=959100"
๊ฑด๊ฐ ์ง๋จ
๊ตฌ์ฑ ๋ณ๊ฒฝ ์ฌํญ์ ์ ์ฉํ๊ธฐ ์ํด Apache๋ฅผ ๋ค์ ์์ํ๊ฑฐ๋ ๋ค์๋ก๋ํ๋ ๊ฒ์ ์์ง ๋ง์ญ์์ค. ํ ์คํธํ๋ ๋์ ์ ๊ธฐ์ ์ผ๋ก ๊ธฐ๋ก์ ์ง์ฐ๋ ๊ฒ์ ์์ง ๋ง์ญ์์ค. ๊ทธ๋ ์ง ์์ผ๋ฉด ์๊ตฌ์ ์ผ๋ก ์ฐจ๋จ ๋ ์ ์์ต๋๋ค ๐
๋๋ ํ ๋ฆฌ ์ํ ๊ณต๊ฒฉ์ ์๋ฎฌ๋ ์ด์ ํ์ญ์์ค.
https://example.com/?abc=../../../ # This should be redirected and blocked
https://example.com/wp-admin/admin-ajax.php?abc=../../../ # This should pass because of the whitelist rule
SQL ์ธ์ ์ ๊ณต๊ฒฉ ์๋ฎฌ๋ ์ด์ :
https://example.com/?username=1'%20or%20'1'%20=%20'1&password=1'%20or%20'1'%20=%20'1
https://example.com/index.php?username=1'%20or%20'1'%20=%20'1'))/*&password=foo
ModSecurity ๋ฐ Apache ๋ก๊ทธ ํ์ผ
Apache ์น ์๋ฒ๋ ์๋ฒ ๊ด๋ฆฌ์์๊ฒ ์๋ ๋ฐฉ์์ ๋ํ ์ค์ํ ์ ๋ณด๋ฅผ ์ ๊ณตํ๋๋ก ๊ตฌ์ฑ ํ ์ ์์ต๋๋ค. ๊ด๋ฆฌ์์๊ฒ ํผ๋๋ฐฑ์ ์ ๊ณตํ๋ ์ฃผ์ ๋ฐฉ๋ฒ์ ๋ก๊ทธ ํ์ผ์ ์ฌ์ฉํ๋ ๊ฒ์ ๋๋ค. ๋ ์ฝ์ด๋ณด๊ธฐ โฆ
ModSecurity ์๋ ๊ฐ๋ ฅํ ๋ก๊น
๋ฉ์ปค๋์ฆ์ด ์์ต๋๋ค. ์ง์๋ฌธ์ ์ํด SecGuardianLog
์ธ๋ถ ์คํฌ๋ฆฝํธ์ ํจ๊ป ์๋ํ๋๋ก ํน๋ณํ ์ค๊ณ๋ ๋ก๊ทธ ํผ๋๋ฅผ ์ ๊ณตํฉ๋๋ค.
ํ์ฌ์ ์์ ์ ์๋ ค์ง ์ ์ผํ ๋๊ตฌ ๋ณดํธ์ ๋ก๊น ์ ๋๋ค
httpd-guardian
์ ์ผ๋ถ์ ๋๋ค, ์ํ์น ์ํ์น ๋๊ตฌ ํ๋ก์ ํธ . ์ดhttpd-guardian
๋๊ตฌ๋ ์๋น์ค ๊ฑฐ๋ถ ๊ณต๊ฒฉ์ ๋ฐฉ์ดํ๋๋ก ์ค๊ณ๋์์ต๋๋ค. ๊ทธ๊ฒ์blacklist tool
iptables ๊ธฐ๋ฐ ๋ฐฉํ๋ฒฝ๊ณผ ์ํธ ์์ฉ ํ๊ธฐ ์ํด๋ฅผ ์ฌ์ฉํ์ฌ ๋ฌธ์ ์ IP ์ฃผ์๋ฅผ ๋์ ์ผ๋ก ๋ธ๋๋ฆฌ์คํธ์ ์ถ๊ฐํฉ๋๋ค. ๋ ์ฝ์ด๋ณด๊ธฐ โฆ
ModSecurity ๋ก๊ทธ ํ์ผ โบ Fail2Ban โบ Iptables
Apache ๋ก๊ทธ ํ์ผ์ ๋ฐ์ดํฐ ๊ตฌ๋ฌธ ๋ถ์์ ์ํด Fail2Ban์ ์ค์ ํ ์ ์์ต๋๋ค. modsec_audit.log
์๋ง๋ ์ต์ ์ ์ ํ ์ผ์ง ๋ชจ๋ฅด์ง๋ง์ ๋ํด ์ด์ผ๊ธฐํ๋ ์น์
๋ ์ฐธ์กฐํ์ญ์์ค SecGuardianLog
.
์ฃผ์ ๊ฐ์ง๊ณ ์์ SecAuditLogRelevantStatus
์์ด /etc/modsecurity/modsecurity.conf
์ฃผ์์. ๊ทธ๋ ์ง ์์ผ๋ฉด 404 ์ค๋ฅ ํ์ด์ง๋ฅผ ์์ ํ๋ ๋ชจ๋ ์ฌ๋์ด fail2ban์ ์ํด ์ฐจ๋จ๋ฉ๋๋ค.
SecAuditEngine RelevantOnly
#SecAuditLogRelevantStatus "^(?:5|4(?!04))"
ํ์ฌ Fail2Ban์์ด ํ๋ก์ ํธ์์ ๊ตฌํ๋์ง ์์์ต๋๋ค.
ModSecGuardianLog โบ HTTPD-Guardian โบ WSAS โบ IPtables
httpd-guardian
-์์ฒญ์ ๋ชจ๋ํฐ๋งํ์ฌ DoS ๊ณต๊ฒฉ ํ์ง Apache Security, Copyright (C) 2005 Ivan Ristic-ํ์ดํ ๋ก๊น ๋ฉ์ปค๋์ฆ์ ํตํด ๋ชจ๋ ์น ์๋ฒ ์์ฒญ์ ๋ชจ๋ํฐ๋งํ๋๋ก ์ค๊ณ๋์์ต๋๋ค. ๊ทธ๊ฒ์ ๊ฐ IP ์ฃผ์์์ ๋ณด๋ธ ์์ฒญ ์๋ฅผ ์ถ์ ํฉ๋๋ค โฆ httpd-guardian์ IP ์ฃผ์๋ฅผ ์ฐจ๋จํ๊ธฐ ์ํด ๊ฒฝ๊ณ ๋ฅผ ๋ณด๋ด๊ฑฐ๋ ์คํฌ๋ฆฝํธ๋ฅผ ์คํํ ์ ์์ต๋๋ค โฆ์ด ์คํฌ๋ฆฝํธ๋ Apache2 ๋ก๊น ๋ฉ์ปค๋์ฆ ๋๋ ModSecurity (๋ ๋์) ์ ํจ๊ป
์ฌ์ฉํ ์ ์์ต๋๋ค .
ํ์ฌ ์ํฉ์์ ์ค์น ๋ฐ ์ค์
๋ค์ด๋ก๋ httpd-guardian
ํ์ฌ ์คํ ๊ฐ๋ฅํ๊ฒํ์ญ์์ค.
sudo wget https://raw.githubusercontent.com/pa4080/www-security-assistant/ask_ubuntu/httpd-guardian.pl -O /var/www-security-assistant/httpd-guardian.pl
sudo chmod +x /var/www-security-assistant/httpd-guardian.pl
98-119
์คํฌ๋ฆฝํธ๋ฅผ WSAS ์คํฌ๋ฆฝํธ์ ์ฐ๊ฒฐํ๋ ๋ฐฉ๋ฒ์ ๋ณด๋ ค๋ฉด ํ ์ ์ฝ์ผ์ญ์์ค .
Apache ๊ตฌ์ฑ ( /etc/modsecurity/modsecurity.conf
) ๋ด์์ ๋ค์ ๋ณ๊ฒฝ ์ฌํญ์ ์ ์ฉํ ํ ๋ค์ ์์ํ์ญ์์ค.
#SecGuardianLog /var/log/apache2_mod_security/modsec_guardian.log
SecGuardianLog "|/var/www-security-assistant/httpd-guardian.pl"
๊ฑด๊ฐ ์ง๋จ
์คํฌ๋ฆฝํธ๋ฅผ ํ
์คํธํ๋ ค๋ฉด ModEvasive๋ฅผ ๋นํ์ฑํํ๊ณ ( sudo a2dismod evasive
๋์ค์ ํ์ฑํํด์ผ ํจ์ ์์ง ๋ง์ญ์์ค) Apache๋ฅผ ๋ค์ ์์ํ์ญ์์ค. ๊ทธ๋ฐ ๋ค์ tail
exec ๋ก๊ทธ :
tail -F /var/www-security-assistant/www-security-assistant.execlog
๊ทธ๋ฆฌ๊ณ ๋ค๋ฅธ ์ธ์คํด์ค์์ DoS ๊ณต๊ฒฉ์ ์ํํ์ญ์์ค (์ ab
: ๋ค์๊ณผ ๊ฐ์ ๋ฐฉ์์ผ๋ก ์ฌ์ฉ).
for i in {1..20}; do (ab -n 200 -c 10 https://example.com/ &); done
ModSecGuardianLog โบ ์ฌ์ฉ์ ์ ์ ๋ถ์ โบ WSAS โบ IP ํ ์ด๋ธ
์ฌ๊ธฐ์ httpd-custom-analyze.bash
ํน๋ณํ ์คํฌ๋ฆฝํธ ๋ ์๋์ง๋ง ์ข์ ์์ ๊ฐ ๋ ์ ์๋ ๊ฐ๋จํ ์คํฌ๋ฆฝํธ ๊ฐ ์์ต๋๋ค. ๊ทธ ๊ธฐ๋ฅ์ ์คํฌ๋ฆฝํธ ๋ณธ๋ฌธ์ ์ค๋ช
๋์ด ์์ต๋๋ค.
์ค์น ๋ฐ ์ค์
๋ค์ด๋ก๋ httpd-custom-analyze.bash
ํ์ฌ ์คํ ๊ฐ๋ฅํ๊ฒํ์ญ์์ค.
sudo wget https://raw.githubusercontent.com/pa4080/www-security-assistant/ask_ubuntu/httpd-custom-analyze.bash -O /var/www-security-assistant/httpd-custom-analyze.bash
sudo chmod +x /var/www-security-assistant/httpd-custom-analyze.bash
Apache ๊ตฌ์ฑ ( /etc/modsecurity/modsecurity.conf
) ๋ด์์ ๋ค์ ๋ณ๊ฒฝ ์ฌํญ์ ์ ์ฉ ํ๊ณ ๋ค์ ์์ํ์ญ์์ค.
#SecGuardianLog /var/log/apache2_mod_security/modsec_guardian.log
#SecGuardianLog "|/var/www-security-assistant/httpd-guardian.pl"
SecGuardianLog "|/var/www-security-assistant/httpd-custom-analyze.bash"
-
์๊ณ ๊ฐ์ ๋๋ฌํ๋ฉด ์คํฌ๋ฆฝํธ๊ฐ WSAS๋ฅผ ํธ์ถํฉ๋๋ค (์ฝ๊ธฐ ํ
86
๋ฐ)35
. -
๋
httpd-
์คํฌ๋ฆฝํธ๊ฐ ๋์์ ์๋ํ๊ฒ ํ๋ ค๋ฉด ๋ ์คํฌ๋ฆฝํธ๋ฅผ ๋ชจ๋ ํธ์งmodsecurity.conf
ํ๊ณ ํ์ดํํ์ญ์์คSecGuardianLog
. -
ํ ์คํธ๋ฅผ ์ํํ๋ ค๋ฉด ์ ์น์ ์ ํ์ ๋ฐ๋ฅด์ญ์์ค.
๋ต๋ณ
pa4080์ด์ด ๋ชจ๋ ๊ฒ์ ์ค์ค๋ก ๊ด๋ฆฌํ๋ ๋ฐ ๋์์ด๋๋ ์์ธํ๊ณ ์ ์ฉํ ๋ต๋ณ์ ์ ๊ณตํ๋ค๋ ๊ฒ์ ์๊ณ ์์ต๋๋ค. ํผ์์ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๊ฒ์ ๊ธฐ๋ถ์ด ์ข์ง๋ง ์๊ฐ์ด ์ค๋ ๊ฑธ๋ฆด ์๋ ์์ต๋๋ค .
- ๋ฌด๋ฃ DDoS ๋ณดํธ ๊ธฐ๋ฅ์ ์ ๊ณต ํ๋ฏ๋ก Cloudflare์ ์ต์ํด ์ง์ญ์์ค .
- ํ์ฌ Apache ๋ง ์ฌ์ฉํ๋ ๊ฒฝ์ฐ NGINX๊ฐ๋ก๋ ๊ท ํ์ ๋ง์ถ๋ ๋ฐฉ๋ฒ์ ๋ฐฐ์ฐ์ญ์์ค. NGINX๋ ์ฌ๊ธฐ ์ ์ฌ๊ธฐ์ ํ์๋ Apache๋ก๋ ๋ฐธ๋ฐ์ฑ์ ์ ์ฉ ํฉ๋๋ค .
- ๋ฌธ์ ๋ณด์์ ๋ํ Apache์ ํ์ ๊ฒํ ํ์ญ์์ค .