1. 개요

OWASP ZAP 도구 사용, 웹 취약점 공격 패킷 분석, Snort Rule 학습 목적으로 진행하였으며,

이번 글은 환경구축 및 OWASP-ZAP 사용을 학습하였습니다.

 

* OWASP-ZAP : OWASP에서 제공하는 공개된 모의침투 도구이며, 본 글에서는 웹 취약점 공격 구현에 사용함

https://www.owasp.org/index.php/OWASP_Zed_Attack_Proxy_Project

 

* DVWA(Damn Vulnerable Web Application) : 취약한 PHP/MySQL 웹 애플리케이션으로 웹보안 학습을 위해 개발된 환경임, 본 글에서는 취약한 웹사이트 환경에 사용함

 

* Snort : 널리 알려진 공개된 IDS/IPS로, 기존의 2.X버전에서 2021-01-19에 3.X 버전으로 공식 출시되었음. 본 글에서는 3.1 버전으로 실습을 진행함.

blog.snort.org/2021/01/snort-3-officially-released.html

 

Snort 3 officially released

We know users have been anticipating this day for years. So, we are excited to announce that the official release of Snort 3 is here ! The v...

blog.snort.org

 

 

2. 실습 환경 구축

* 공격자 PC

 - vm name : k
 - OS : Kali Linux 2020.4_64bit

 - IP : 192.168.116.135
 - Tool : OWASP-ZAP 2.9

칼리리눅스에 ZAP이 기본 설치되어 있음

 

* 피해자 PC
 - vm name : Ubuntu_20
 - OS : Ubuntu_20.04.1_64bit

 - IP : 192.168.116.132 
 - Tool : Docker, DVWA, Snort 3.1.1

 

2.1 도커 및 DVWA 설치

리눅스 종류 상관 없이 docker를 설치하는 스크립트

sudo wget -qO- http://get.docker.com/ | sh

 

정상 설치 여부 확인

docker verseion

 

 

DVWA 도커이미지 실행(hub.docker.com/r/jechoi/dvwa)

sudo docker run -d -p 8443:80 jechoi/dvwa

 

DVWA 도커 정상 접속 확인

http://localhost:8443/dvwa 

DVWA 초기계정정보 : admin/password

우분투에 DVWA 환경 구축됨을 확인



 

ATK_PC 브라우저에서 공격대상 웹사이트(http://192.168.116.132:8443/dvwa) 정상 접속 확인

ATK_PC에서 공격대상 웹사이트 정상 접속 확인(환경 테스트)

 

2.2 SNORT 설치

하단의 사이트를 참고하여 진행함

 

kifarunix.com/install-and-configure-snort-3-nids-on-ubuntu-20-04/

 

Install and Configure Snort 3 NIDS on Ubuntu 20.04 - kifarunix.com

In this tutorial, you will learn how to install and configure Snort 3 NIDS on Ubuntu 20.04. Snort is a lightweight network intrusion detection system. It

kifarunix.com


시스템 업데이트 실행

sudo apt update
sudo apt upgrade

 

의존성패키지 설치

apt install build-essential libpcap-dev libpcre3-dev libnet1-dev zlib1g-dev luajit hwloc libdnet-dev libdumbnet-dev bison flex liblzma-dev openssl libssl-dev pkg-config libhwloc-dev cmake cpputest libsqlite3-dev uuid-dev libcmocka-dev libnetfilter-queue-dev libmnl-dev autotools-dev libluajit-5.1-dev libunwind-dev

mkdir snort-source-files
cd snort-source-files

sudo git clone https://github.com/snort3/libdaq.git
cd libdaq
sudo ./bootstrap
sudo ./configure
sudo make
sudo make install

cd ../
sudo wget https://github.com/gperftools/gperftools/releases/download/gperftools-2.8/gperftools-2.8.tar.gz
sudo tar xzf gperftools-2.8.tar.gz
cd gperftools-2.8/
sudo ./configure
sudo make
sudo make install

 

snort 설치

cd ../
sudo git clone git://github.com/snortadmin/snort3.git

cd snort3/
sudo ./configure_cmake.sh --prefix=/usr/local --enable-tcmalloc

cd build
sudo make
sudo make install

ldconfig
snort -V

 

Snort 3.1 설치완료

 

 

2.3 Snort Rulesets 설정

여기서부터는 스노트 공식사이트의 글을 참고함

snort-org-site.s3.amazonaws.com/production/document_files/files/000/003/979/original/Snort3_3.1.0.0_on_Ubuntu_18___20.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIXACIED2SPMSC7GA%2F20210225%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210225T130521Z&X-Amz-Expires=172800&X-Amz-SignedHeaders=host&X-Amz-Signature=b1ff6259575f8ad04ed5c8f4c339a6a9e040ed96aa727494d5bb45c32f29dcfc

 

We need to create some folders and files that Snort reqiures for rules:

sudo mkdir /usr/local/etc/rules
sudo mkdir /usr/local/etc/so_rules/
sudo mkdir /usr/local/etc/lists/

sudo touch /usr/local/etc/rules/snort.rules
sudo touch /usr/local/etc/rules/local.rules
sudo touch /usr/local/etc/lists/default.blocklist sudo

sudo mkdir /var/log/snort

디렉터리 기본 경로(vim /usr/local/etc/snort/ snort.luasnort_defaults.lua)

 

 

We will create one rule in the local.rules file that you created above:

sudo vi /usr/local/etc/rules/local.rules

 

This rule will detect ICMP traic, and is really good for testing that Snort is working correctly and generating alerts. Paste the following line into the local.rules file (make sure that you’re copying this line exactly, you must have a space aer each semicolon in this file for PulledPork to parse the alert correctly):

alert icmp any any -> any any ( msg:"ICMP Traffic Detected"; sid:10000001; metadata:policy security-ips alert; )

 

Now run Snort and have it load the local.rules file (with the -R flag) to make sure it loads these rules correctly (verifying the rules are correctly formatted):

snort -c /usr/local/etc/snort/snort.lua -R /usr/local/etc/rules/local.rules

 

The output should end with “Snort successfully validated the configuration”. You should not have any warnings or errors. If you scroll up through the output, you should see this rule loaded successfully (under the rule counts section). Now let’s run Snort in detection mode on an interface (change eth0 below to match your interface name), and print all alerts to the console:

sudo snort -c /usr/local/etc/snort/snort.lua -R /usr/local/etc/rules/local.rules -i ens33 -A alert_fast -s 65535 -k none

공격자PC에서 PING을 날렸으며, 피해자PC Snort에서 ICMP 패킷을 탐지

ctrl+c로 스노트를 중지한다. 

 

 

Next let’s edit the snort.lua file. This file is the configuration file we pass to Snort at startup:

sudo vi /usr/local/etc/snort/snort.lua

 

Next, we want to enable decoder and inspector alerts (malicious traic that is detected by Snort, not the rules due to the more complex format), and we want to tell the ips module where our rules file will be (PulledPork will create this for us later) Scroll down to line 169, and look for the section titled ips. Here we un-comment (remove the leading two dashes) from enable_builtin_rules=true, and enable our pulledpork rules. Note that lua uses four spaces, not tabs to indent these lines (this is required). This section should look like this (comments removed):

166 ips =
167 {
168 enable_builtin_rules = true,
169 include = RULE_PATH .. "/local.rules",
170 variables = default_variables
171 }

 

수정 전
수정 후

 

test your config file (since we’ve made changes):

snort -c /usr/local/etc/snort/snort.lua

 

Now we can run snort as above, however we don’t explictly pass the local.rules file on the command line, as we’ve included it in the ips section in the snort.lua file:

sudo snort -c /usr/local/etc/snort/snort.lua -i ens33 -A alert_fast -s 65535 -k none

 

Snort 테스트 결과 정상 탐지

 

2.4 Snort 로깅 설정

To write Snort 3 events to log files, you need to enable configure alert settings. There are different Snort logging options that are explained well in the Snort 3 manual, Logger Modules section. To output the event data to a file, in brief format (as defined in the command line above by option -A alert_type), open the snort.lua configuration and head over to the outputs section.

vim /usr/local/etc/snort/snort.lua

vim /usr/local/etc/snort/snort.lua에서 해당 부분 변경

 

The setting will cause snort to write logs to alert_fast.txt file. Save and exit the configuration and run syntax checking.

snort -c /usr/local/etc/snort/snort.lua

 

Run the command again, this time, without the option, -A alert_fast, but with an option to specify the log directory, -l /var/log/snort.

sudo snort -c /usr/local/etc/snort/snort.lua -i ens33 -A alert_fast -s 65535 -k none -l /var/log/snort

 

Run the ping test again. If you check on the logs directory, you should see an alert_fast.txt file created. You can tail this file;

sudo tail -f /var/log/snort/alert_fast.txt

Snort 로깅 테스트 결과 정상

 

HOME_NET, EXTERNAL_NET 변수를 설정한다. 해당 변수는 룰 작성 시 출발지, 목적지 주소 설정에 편리함을 준다.

vim /usr/local/etc/snort/snort.lua

변수 설정

 

 

3. ZAP 실습

공격자 PC에서 ZAP을 실행하여 빠른시작의 URL to attack 칸에 공격대상 웹사이트 URL을 입력하면 공격이 시작된다.

ZAP 빠른 시작 공격 결과

* 빠른 시작 : URL to attacker 항목에 공격 대상 URL을 입력하여 점검 시작 및 중지하며, 중앙 오른쪽의 작업창에 위치한다.

* Spider : 공격시에 웹 로봇 기능을 수행하여 웹페이지에서 발견되는 모든 URL을 수집하는 기능이다. 사이트의 크기에 따라 소요 시간이 수 분에서 수 시간이 소요된다.


* Active Scan : Spider의 URL 수집이 완료되면 Active Scan이 수행됨.
Path Traversal, Remote OS Command Injection, XSS, SQL Injection 등의 취약점을 점검한다.

* 경고 : Active Scan이 종료되면 위험도별로 취약점이 나열되는 탭이다. 순서대로 위험도는 상, 중, 하, 정보용이다.
 - 상 : 직접 공격 가능
 - 중 : 민감한 정보
 - 하 : 덜 민감한 정보
 - 정보용 : 매우낮음.

 

* 탐지된 경고(취약점 항목)을 클릭하면 우측에 탐지 세부내용 확인가능하며, Request와 Response 탭을 눌러 그 내용을 확인하면 취약점 점검 방법을 보다 자세히 알 수 있음

경고를 클릭하면 세부 항목(취약점에 대한 설명) 확인 가능
경고에 대한 Request 패킷
경고에 대한 Response 패킷

 


* 경고 - 확인할 취약점 항목 우클릭 - Open URL in Browser : 취약점 실행결과를 브라우저에서 확인가능함.

* HUD : Open URL in Browser에서 우측 하단에 동그라미 아이콘 클릭하면 툴에서 경고들을 브라우저에서 확인 가능함

HUD 사용

- 좌측 경고(깃발 아이콘)들은 page에 대한 경고

- 우측 경고(깃발 아이콘)들은 site에 대한 경고

 

웹브라우저에서 사이트에 대한 경고를 위험도별로 볼 수 있음

 

경고에 대한 요청패킷 및 응답패킷을 확인할 수 있음




* ZAP이 HTTPS에서 정상 작동하기 위해서는 SSL 인증서 등록이 필요함.
Options - Dynamic SSL Certification - Generate를 통해 인증서 생성하고, 브라우저에서 인증서 등록

현재 진행한 실습은 인증서 등록을 하지않아서 취약점이 덜 발견되었으며, 다음 글에 추가 예정.

프록시 기능 설정하여 진행예정.

zap 2.9(18 Jan 2020)로 진행하였는데, 최신버전 2.10(17 Dec 2020)으로 진행예정.

 

 

참고자료 :

1. Install and Configure Snort 3 NIDS on Ubuntu 20.04 / gen_too / 2020-08-23 / kifarunix.com/install-and-configure-snort-3-nids-on-ubuntu-20-04/

2. snort-org-site.s3.amazonaws.com/production/document_files/files/000/003/979/original/Snort3_3.1.0.0_on_Ubuntu_18___20.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIXACIED2SPMSC7GA%2F20210225%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210225T130521Z&X-Amz-Expires=172800&X-Amz-SignedHeaders=host&X-Amz-Signature=b1ff6259575f8ad04ed5c8f4c339a6a9e040ed96aa727494d5bb45c32f29dcfc

3. 공개도구를 이용한 홈페이지 취약점 점검 안내서 / 김진숙정기문 / 한국과학기술정보연구원/ 2015-01-01 / repository.kisti.re.kr/bitstream/10580/6120/1/2015-037%20%EA%B3%B5%EA%B0%9C%EB%8F%84%EA%B5%AC%EB%A5%BC%20%EC%9D%B4%EC%9A%A9%ED%95%9C%20%ED%99%88%ED%8E%98%EC%9D%B4%EC%A7%80%20%EC%B7%A8%EC%95%BD%EC%A0%90%20%EC%A0%90%EA%B2%80%20%EC%95%88%EB%82%B4%EC%84%9C.pdf

 

'기술보안 > 기타' 카테고리의 다른 글

[HTB-ACADEMY] 윈도우 기초 - 01  (0) 2021.09.12
snort byte_test  (0) 2021.07.29
정규표현식 정리  (0) 2021.07.13
GNU Bash 취약점  (0) 2021.05.31
OWASP ZAP Active Scan - Remote OS Command Injection 공격 분석  (0) 2021.03.30
복사했습니다!