Snort 정의 및 예제

동스토리 ㅣ 2021. 9. 2. 21:27

반응형

침입 탐지 시스템(snort)

IDS(Intrusion Detection System)의 대표적인 오픈소스 솔루션으로 네트워크 상 흐르는 트래픽 분석에 사용되는 솔루션

 

# 룰 헤더 설정

action  protocol  Source ip address  port   Direction ip address  port

 

# Action 유형

1) alert : 선택한 alert 방식을 이용해서 alert를 발생시키고 패킷을 로그에 남긴다.

2) log : 패킷을 로그에 남긴다.

3) pass : 패킷을 무시한다.

4) activate : alert를 발생시키고, 대응시키는 dynamic rule을 활성화킨다.

5) dynamic : activate rule에 의해 활성화 되고, log rule과 동일하게 동작한다.

6) drop : 패킷을 차단하고 로그에 남긴다.

7) reject : drop rule과 동일하게 패킷을 차단하고 로그에 남긴 후 TCP일 경우 TCP Reset을 전송하고 UDP일 경우 ICMP port unreachable 메시지를 전송한다.

8) sdrop : 패킷을 차단하지만 로그에 남기지 않는다.(silent)

alert tcp any any -> 192.168.133.0/24 80

log tcp $EXTERNAL_NET any <> $HOME_NET 80

* $EXTERNAL_NET : 외부네트워크 / $HOME_NET : 내부네트워크

 

# 룰 바디(body) 설정 : 일반 옵션

1) sid : snort rule id 정보

( 99이하 : 시스템에 예약된 sid / 100~1,000,000 이하 : snort에서 배포하는 sid / 1,000,001 이상 : 사용자 정의 sid )

2) rev : rule 수정 횟수

3) msg : alert 발생 시 사용할 이벤트 명

4) priority : rule 우선순위(위험도)

 

# 룰 바디(body) 설정 : payload/범위 관련 옵션

1) content : 페이로드에서 검사할 문자열을 지정

가. text = content:"pattern" -> 해당 pattern 문자열 검사

(msg:"~"; content:"/etc/passwd"; nocase; sid:1000021;)

나. binary = content:“|FF FF|" -> 파이프 기호 사이에 헥사값으로 표현

(msg:"~"; content:"|2f 65 74 63 2f 70 61 73 73 77 64|"; nocase; sid:1000022;)

(msg:"~"; content:"|2f 65 74 63 2f|passwd"; nocase; sid:1000023;)

2) uricontent : content 문자열을 전체 패킷과 비교하는 대신 HTTP 클라이언트 요청 URI 정보를 검사할 문자열을 지정

3) offset : 페이로드(0부터 시작)에서 content 패턴을 검사할 시작위치

(msg:"~"; content:"234"; offset:2; nocase; sid:1000023;)

4) depth : offset부터 몇 바이트까지 검사할 것인지 지정

(msg:"~"; content:"234"; offset:2; depth:3; nocase; sid:1000024;)

5) distance : 이전 content 패턴에 매치된 경우, 매치된 이후 바이트부터 몇 바이트 떨어진 위치에서 다음 content를 검사할 것인지 지정

(msg:"~"; content:"234"; offset:2; depth:3; content:"BCD"; distance:6; nocase; sid:1000025;)

6) within : 이전 content 패턴에 매치된 경우, distance부터 몇 바이트 범위 내에서 다음 content를 검사할 것인지를 지정

(msg:"~"; content:"234"; offset:2; depth:3; content:"BCD"; distance:6; within:3; nocase; sid:1000025;)

7) nocase : 페이로드 검사 시 대/소문자를 구분하지 않음

 

# 룰 바디 설정 : 페이로드/정규표현식(pcre)

-> 문자열 탐지의 유연성을 갖도록 하기위해 슬래시(/) 기호 사이에 입력

(msg:"~"; content:"+or+"; content:"%27%3D%27"; nocase; distance:0; within:20; pcre:"/^(GET|POST)/"; sid:1000040;)

 

# 룰 바디 설정 : 페이로드/HTTP 관련 옵션

1) http_method : HTTP method 부분을 검사

(msg:"~"; content:"GET"; http_method; nocase; sid:1000060;)

2) http_uri : HTTP URI 부분을 검사

(msg:"~"; content:"<script>"; http_uri; nocase; sid;1000061;)

3) http_header : HTTP Header 부분을 검사, 요청/응답 헤더에 모두사용

4) http_cookie : HTTP Cookie 부분을 검사

5) http_client_body : HTTP 클라이언트 요청의 Body 부분을 검사

6) http_stat_code : HTTP 응답의 status_code 부분을 검사

7) http_stat_msg : HTTP 응답의 status_message 부분을 검사

 

# 룰 바디 설정 : Event Threshold(이벤트 제한) 관련 옵션

-> 특정 시간동안 발생되는 이벤트 수를 제한

threshold type<limit|threshold|both>, track<by_src|by_dst>, count<c>, seconds<s>

1) type

- limit : 매 s초 동안 c번째 이벤트까지 action을 수행한다.

threshold type limit, track by_src, count 2, seconds 10

- threshold : 매 s초 동안 c번째 이벤트마다 action을 수행한다.

threshold type threshold, track by_src, count 10, seconds 5

- both : 매 s초 동안 c번째 이벤트 시 한번 action을 수행한다.

threshold type both, track by_src, count 10, seconds 1

2) track

- by_src : 출발지 IP를 기준으로 추적

- by_dst : 목적지 IP를 기준으로 추적

 

# 침입 탐지 시스템(snort) 실습

 

1) root 로그인 시도/성공 탐지

가. FTP root 로그인 시도 탐지

alert tcp any any -> 10.10.10.0/24 21 (msg:"~"; content:"USER root"; nocase; sid:1000010;)

- ftpusers 파일 설정

나. Telnet root 로그인 성공 탐지

alert tcp 10.10.10.0/24 23 -> any any (msg:"~"; content:"login"; pcre:"/root@.*#/"; nocase; sid:1000010;)

- root 계정의 원격접속 제한

 

2) 온라인 패스워드 크래킹 공격 탐지

가. Telnet 로그인 Brute Force/Dictionary Attack 공격 탐지

alert tcp 10.10.10.0/24 23 -> any any (msg:"~"; content:"Login incorrect"; nocase; threshold:type limit, track by_dst, count 1, seconds 5; sid:1000010;)

- 계정 잠금 임계값 설정

나. FTP 로그인 Brute Force/Dictionary Attack 공격 탐지

alert tcp 10.10.10.0/24 21 -> any any (msg:"~"; content:"Login incorrect"; nocase; threshold:type threshold, track by_dst, count 5, seconds 30; sid:1000010;)

다. SSH 로그인 Brute Force/Dictionary Attack 공격 탐지

alert tcp any any -> 10.10.10.0/24 22 (msg:"~"; content:"|53 53 48 2d 32 2e 30|"; nocase; threshold:type both, track by_src, count 5, seconds 30; sid:1000010;)

 

3) Flooding 계열 공격 탐지

가. HTTP GET Flooding 공격 탐지

alert tcp any any -> 10.10.10.0/24 80 (msg:"~"; content :"GET / HTTP/1."; depth:13; nocase; threshold:type threshold, track by_src, count 100, seconds 1; sid:1000010;)

나. TCP SYN Flooding 공격 탐지

alert tcp any any -> 10.10.10.0/24 80 (msg:"~"; flags:S; threshold:type threshold, track by_src, count 5, seconds 1; sid:1000010;)

다. UDP/ICMP Flooding 공격 탐지

alert udp any any -> $HOME_NET any (msg:"~"; threshold:type threshold, track by_src, count 5, seconds 1; sid:1000010;)

alert icmp any any -> $HOME_NET any (msg:"~"; threshold:type threshold, track by_src, count 5, seconds 1; sid:1000010;)

 

4) 비정상 IP 패킷

- 비정상적인 패킷을 제대로 처리하지 못하는 침입탐지/침입방지시스템(IDS/IPS) 또는 침입차단시스템(Firewall)을 우회하기 위한 목적

- 시스템이 비정상적인 패킷을 제대로 처리하지 못하여 장애나 오류가 발생하도록 하기 위한 목적

가. 인터넷 구간의 사설IP

1) 10.0.0.0 ~ 10.255.255.255.255 (10.0.0.0/8)

2) 172.16.0.0 ~ 172.31.255.255 (172.16.0.0/12)

3) 192.168.0.0 ~ 192.168.255.255 (192.168.0.0/16)

alert udp 10.0.0.0/8 any -> $HOME_NET any (msg:"~"; sid:1000010;)

나. 출발지와 목적지가 동일한 IP (Land Attack)

alert ip any any -> $HOME_NET any (msg:"~"; sameip; sid:1000010;)

 

5) 비정상 TCP 패킷

가. SYN+FIN 플래그 조합 비정상 TCP 패킷

alert tcp any any -> 10.10.10.0/24 any (msg:"~"; flags:SF; sid:100010;)

alert tcp any any -> 10.10.10.0/24 any (msg:"~"; flags:SF+; sid:100010;)

- flags : SF -> 연산자가 없을 경우 SYN, FIN만 설정된 경우를 말한다.

- flags : SF+ -> + 연산자가 있으면 SYN,FIN은 반드시 포함하고 다른 플래그도 설정될수 있다.

- 클라이언트의 요청에 대한 응답 패킷인 것처럼 위조하기 위해 출발지 포트와 목적지 포트를 동일하게 사용(원래는 출발지 포트는 1024이상)

나. FIN 플래그만 설정된 비정상 TCP 패킷

alert tcp any any -> 10.10.10.0/24 any (msg:"~"; flags:F; sid:100010;)

다. 플래그가 설정되지 않은 비정상 TCP 패킷(NULL패킷)

alert tcp any any -> 10.10.10.0/24 any (msg:"~"; flags:!UAPRSF; sid:100010;)

 

감사합니다.

반응형

'Security > Network' 카테고리의 다른 글

[Infra] Security Onion 설치  (0) 2021.10.08
iptables 정의 및 예제  (0) 2021.09.02
Proxy (Forward proxy & Reverse proxy)  (0) 2020.11.27
라우팅 (Routing)  (0) 2020.11.24
미러링(Mirroring) / 인라인(In-line) 모드  (0) 2020.11.16