DAY12
DAY12

스노트 설정


[서버] - 설치시엔 항상 NAT설정
sudo apt update
apt -y install snort
snort -v

[IDS] sudo passwd root
snort --version (스노트 버전 확인)
lsb_release -a (설치버전 확인)

Bootstrap Example

스노트

교재
P.93~123 이론
P.124~ 실습

[IDS]
cd /etc/nort/rules (스노트 룰 확인)
NAT설정
cd /etc/snort/rules ls
sz *.rules
sudo apt -y install lrzsz
\\192.168.0.102 (공유폴더에서 다운로드) (윈도우10 dns를 .99로 변경하지 않아서(본인ip214로 설정되어 있음) 설치가 안됨 > 변경)

cd /etc/snort/rules
sudo nano local.rules (비어있는 파일 -> 규칙을 만들 수 있음!)

[kali]
ping 10.0.2.15
tcpdump -i enp0s3 -e icmp (오류 > esw에 포트 미러링 하기)

[esw1] - 포트 미러링
config t
monitor session 1 source interface fastethernet 1/0 - 14
monitor session 1 destination interface fastethernet 1/15
end
show monitor session 1

[IDS]
cd /etc/snort
nano snort.conf
    #site specific rules
    include $RULE_PATH/local.rules 만 살려두고 다른 include 다 #처리

    #include $RULE_PATH/app-detect.rules
    include > #include
    #include


~스노트 정책으로 탐지해보기~
[IDS] cd /etc/snort/rules
nano local.rules
    alert icmp any any -> any any (msg:"DetectToIcmp"; sid:1000001;)

tcpdump -i enp0s3 -e icmp (kali > ping10.0.2.15 해보면 감지됨!)
snort -A console -q -u snort -g snort -c /etc/snort/snort.conf (kali > ping10.0.2.15 해보면 감지됨!)

*랜드 공격 : 출발지 ip주소를 목적지 ip주소와 동일하게 설정하는 것


Bootstrap Example

1. PING 탐지

공격
ping 10.0.2.15

탐지
cd /etc/snort/rules
nano local.rules
    alert icmp any any -> any any (msg:""; sid:1000001;)


Bootstrap Example

2. ICMP 플러딩 공격 탐지

공격
hping 10.0.2.15 --icmp --flood

탐지
cd /etc/snort/rules
nano local.rules
    alert icmp any any -> any any (msg:"PingOfDeath";threshold:type both,track by_src,count 10,seconds 2;sid:1000002;)
=> 2초 동안 10회 이상의 ICMP 요청이 발생한다면 죽음의 핑 공격으로 판단하겠다!


Bootstrap Example

NMAP 공격 탐지

공격
nmap 10.0.2.15 -p 22 -sT

탐지
cd /etc/snort/rules
nano local.rules
    alert tcp any any -> 10.0.2.15 22 (msg:"nmapScan";flags:S;sid:1000003;)


Bootstrap Example

4. SSH 공격 탐지

공격
ssh master@10.0.2.15

탐지
nano local.rules
    alert tcp any any -> 10.0.2.15 22 (msg:"sshAttack";content:"SSH";nocase;sid:1000004;)

*nocase : 대소문자를 구별하지 않겠다.
*content:"";nocase랑 쌍으로 사용함


Bootstrap Example

5.HYDRA 공격 탐지

공격
hydra -L user.txt -P passwd.txt -f 10.0.2.15 ftp
hydra -L user.txt -P passwd.txt -f 10.0.2.15 ssh
hydra -L user.txt -P passwd.txt -f 10.0.2.15 http-get://10.0.2.15
(hydra -L user.txt -P passwd.txt intra.st.kr http-post-form "/login_chk.php:id=^USER^&pw=^PASS^:fail" -V)
slowhttptest -H -g -o slowloris -c 4000 -r 100 -i 10 -t GET -p 3 -x 3 -u http://10.0.2.15

탐지
nano local.rules
    alert tcp any any -> 10.0.2.15 21 (msg:"ftpAttack";content:"FTP";nocase;sid:1000005;)
    alert tcp any any -> 10.0.2.15 22 (msg:"sshBruteForceAttack";content:"SSH";nocase;offset:0;depth:4;sid:1000006;)
    alert tcp any any -> 10.0.2.15 80 (msg:"httpBruteForceAttack";content:"GET / HTTP/1.";nocase;offset:0;depth:4;sid:1000006;)
    alert tcp any any -> 10.0.2.15 80 (msg:"ToDetectSlowlowLorisAttack";flow:to_server,established;pcre:"/[^\x0d\x0a]\x0d\0a$/";threshold:type both,track by_src,count 10,seconds 2;sid:1000007;)

*pcre : (Perl Compatible Regular Expressions ) : 펄 호환 정규 표현식
*offset/depth는 지정한 위치에서 문자열 검색을 하기 위함
*nocase : 대소문자를 구별하지 않겠다.
*content:"";nocase랑 쌍으로 사용함


Bootstrap Example

APM 작동

IDS APM 작동되도록 설정해보자!
    기존 파일(레거지 파일)에 대한 버전 문제 발생(PHPS로 개발)
    윈도우용 레거지 apm을 이용하면 가능하지만 리눅스에서 해결하고자 함
Bootstrap Example

mysql에 SNORT 로그 저장하기

apt update
apt -y install snort
reboot

[IDS]
NAT설정 (3306포트 추가)
cd /etc/snort/rules
cd /var/log/snort
cat snort.log (깨진 파일을 확인 > 반야드2 프로그램이 필요하다 인지)

Bootstrap Example

반야드2 프로그램 설치하기

apt -y install build -essential
apt -y install libpcap-dev libpcre3-dev libdumbnet-dev
apt -y install mysql-server libmysqlclient-dev mysql-client autoconf libtool
apt -y install bison flex

cd ~
mkdir snort_source
cd snort_source
wget http://snort.org/downloads/snort/daq-2.0.6.tar.gz (또는 파일에서 끌어오기 apt install lrzsz 필요)

tar -xvzf daq-2.0.7.tar.gz
cd daq-2.0.7
./configure && make && make install (오류발생!!)

cd ~
touch /etc/snort/sid-msg.map
cat /etc/snort/snort.conf -n | egrep "output unified2"
    550 # output unified2: filename merged.log, limit 128, nostamp, mpls_event_types, vlan_event_types
    551 output unified2: filename snort.log, limit 128, nostamp, mpls_event_types, vlan_event_types
    (550번과 551번 라인 확인)

cd snort_source
wget https://github.com/firnsy/barnyard2/archive/master.tar.gz
tar zxvf master.tar.gz
cd barnyard2-master
autoreconf -fvi -I ./m4

ln -s /usr/include/dumbnet.h /usr/include/dnet.h
getconf LONG_BIT
64비트임을 알려줌

./configure --with-mysql
--with-mysql-libraries=/usr/lib/x86_64-linux-gnu
make && make install
cd /usr/local/bin/barnyard2 -V (오류)



~최신 블로그 내용 참고하기!!~
https://velog.io/@hackk/%EB%84%A4%ED%8A%B8%EC%9B%8C%ED%81%AC-%EB%B3%B4%EC%95%88-Snort%EC%99%80-barnyard2-%EC%97%B0%EB%8F%99%ED%95%98%EA%B8%B0

/etc/snort/snort.conf
    output unified2: filename snort.log, limit 128
    output alert_unified2: filename snort.alert, limit 128, nostamp

mysql -u root -p
    create database snort;
    create user snort@localhost identified by '123456';
    grant all privileges on snort.* to snort@localhost;
    flush privileges;
    exit

cd barnyard2-master
./autogen.sh
./configure --with-mysql=/usr/include/mysql/ --with-mysql-libraries=/usr/lib/aarch64-linux-gnu/

make
maek install

cp /var/log/snort/snort_source/barnyard2-master/etc/barnyard2.conf /etc/snort

mkdir /var/log/banyard2
touch /var/log/snort/barnyard2.waldo
chown snort.snort /var/log/snort/barnyard2.waldo

#MySQL 데이터 베이스 생성
#barnyard2-master/schemas 경로에서
mysql -p < create_mysql snort

/etc/snort/barnyard2.conf

barnyard2 설정파일 내용
# Snort에서 탐지한 네트워크 규칙을 어느 데이터베이스에 로깅할지 정보를 입력합니다.
    output database: log, mysql, user=snort password=root dbname=snort host=localhost

    input_type : file
    input_file: /var/log/snort

    input unified2

    #config reference_file: /etc/snort/reference.config
    config reference_file: /var/log/snort/snort.log
    config classification_file: /etc/snort/classification.config
    config gen_file: /etc/snort/gen-msg.map
    #config sid_file: /etc/snort/sid-msg.map

sudo chmod o-r /etc/snort/barnyard2.conf

cd snort_source/barnyard2-master/src/output-plugins
nano spo_alert_fwsam.c
    중간에 typedef int socket 지움
nano spo_database.h
    my_bool -> bool

/usr/local/bin/barnyard2 -V (완료!)

cp /var/log/snort/snort_source/barnyard2-master/etc/barnyard2.conf /etc/snort (경로 꼭 확인하고 설정하기!!)


설치완료
Barnyard2 spooler: Event cache size set to [2048]
Log directory = /var/log/barnyard2

        --== Initialization Complete ==--

          -*> Barnyard2 < *-
/ ,,_ \ Version 2.1.14 (Build 337)
|o" )~| By Ian Firns (SecurixLive): http://www.securixlive.com/
+ '''' + (C) Copyright 2008-2013 Ian Firns < firnsy@securixlive.com>


[Testing]
sudo /usr/local/bin/snort -q -u snort -g snort -c /etc/snort/snort.conf -i enp0s3
(usr/local/bin/snort 없음)

sudo barnyard2 -c /etc/snort/barnyard2.conf -d /var/log/snort -f snort.u2 -w /var/log/snort/barnyard2.bookmark -g snort -u snort
    Unable to open waldo file '/var/log/snort/barnyard2.bookmark
    (반야드2.북마크 없음)

mysql -u snort -p snort (접속 됨!)
select count(*) from event; (이벤트없음)