Rule 구조 - header
header | option | ||||||
action | protocol | s.ip | s.port | -> | d.ip | d.port | option |
※ Rule은 /etc/snort/rules/local.rules에 추가한다.
- action
alert : 경고 발생, 로그 기록
log : 로그 기록
pass : 무시
drop : 방화벽을 통해 패킷 차단, 로그 기록
reject : 방화벽을 통해 패킷 차단, 로그 기록(응답 후 차단)
sdrop : drop 과 동일 단 로그 없음
active : alert 발생, 대응하는 dynamic rule을 활성화
dynamic : active에 의해 활성화 시에만 작동, log와 동일
- protocol
tcp, udp, ip, icmp, any
- s.ip [d.sip]
host, network 주소 지정
ex) any, $HOME_NET, $EXTERNAL_NET,
192.168.10.11/24, 192.168.10.0/24 : host나 network 주소
[192.168.10./24,192.168.12.0/24] : 여러 개 지정, 공백없음
!$HOME_NET, !192.168.11.0/24 : 제외
- s.port [d.port]
포트 번호 지정
ex) 80, !80
2048:2056, !2048:2056
any
- AP 시스템에 대한 접속을 감지하는 rule를 설정하고 경고를 확인한다.
ICMP, FTP, SSH, WEB 접속 확인을 위한 rule을 설정한다.
ex) 아래와 같이 다양한 source 설정을 테스트한다.
alert icmp any any -> 192.168.11.45 any (msg:"AP ICMP Detect"; sid:10000002; rev:1)
alert icmp $EXTERNAL_NET any -> 192.168.11.45 any (msg:"AP ICMP Detect"; sid:10000002; rev:1)
//$EXTERNAL_NET -> HOME_NET이 아닌것 = !$HOME_NET
alert icmp !$HOME_NET any -> 192.168.11.45 any (msg:"AP ICMP Detect"; sid:10000002; rev:1)
alert tcp any any -> $HOME_NET 21 (msg:"FTP detect"; sid:10000002; rev:1) // FTP
alert tcp any any -> $HOME_NET 22 (msg:"ssh detect"; sid:10000003; rev:1) // SSH
alert tcp any any -> $HOME_NET 80 (msg:"FTP detect"; sid:10000004; rev:1) // web
- 옵션
general, Payload, non-payload, post detection 등
전체 내용은 다음을 참고한다.
http://manual-snort-org.s3-website-us-east1.amazonaws.com/node27.html
- General
일반 옵션을 의미한다.
msg, sid, rev 등등
- Payload
패킷의 message에 해당하는 부분을 의미한다.
content, nocase, offset, depth, distance 등등
- Nopayload
패킷의 헤더에 해당한다.
fragoffset, frages, seq, ack, itype등등
General
- msg : 경고 메시지 지정
msg:"SYNC ATT";
- sid : 룰 식별자
100미만은 예약됨
100~1000000 : snort.org에서 배포하는 규칙에 이용
- rev : 원본이 수정되었을 때 이용. serial #
사용할 필요 없으나 오류 방지를 위해 적어준다.
Payload
- content : 텍스트 탐색
16진수나 문자열을 기반으로 검출한다.
alert tcp any 22 -> any any (content:"|535348|";) // ssh서버에서 ssh클라이언트로 보냄
alert tcp any any -> any 80 (content:!"GET";)
- nocase : 대소 문자 구문 없이 탐색
alert tcp any any -> any 21 (msg:"FTP ROOT"; content:"USER root"; nocase;)
- offset : 지정한 byte 부터 탐색
- depth : 지정한 byte 까지 탐색
alert tcp any any -> any 80 (content:"cgi-bin/phf"; offset:4; depth:20;) //앞에 content가 필요
- distance : content 매핑 후 지정한 위치 이후 동일한 content 탐색
alert tcp any any -> any any (content:"ABC"; content:"DEF"; distance:1;) // ABC를 찾고 1byte 건너 뛰고 DEF 검색
- within : content 매핑 후 지정한 위치 이내 동일한 content 탐색
alert tcp any any -> any any (content:"ABC"; content:"EFG"; within:10;) // ABC 다음 10byte 내에서 EFG 검색
- http 탐색 옵션
content의 내용을 아래 지정된 옵션에서 탐색한다.
http_url : URL내에서 탐색한다.
http_method : 메소드 탐색
http_header : HTTP heade에서 탐색
http_stat_code : 응답 상태 코드 탐색 // ex) 404 error
http_stat_message : 응답 상태 메시지 탐색
http_cookie : 쿠키 헤더필드에서 탐색한다.
http_client_body : HTTP body 탐색
Non Payload
- itype : ICMP type
itype:[<|>] number
itype:>20; 또는 itype:0
- icode : ICMP code
icode:[<|>] number
icode:>10; 또는 icode:0
- seq : TCP sequence 번호
seq:0;
- ack : TCP ACK 번호
ack:0;
- threshold
이벤트의 반복에 따라 action 수행
threshold:type <threshold|limit|both>,track <by src|by dst>, count <c>, second <s>
// threshold : 매 s초 동안 c 번째 이벤트 마다 action 수행
// limit : 매 s초 동안 c 번째 이벤트까지 action 수행
// both : 매 s초 동안 c 번째 이벤트 시에 한번 action 수행
// by src | by dst : src 또는 dst IP 기준으로 탐색
// count | second : 횟수와 시간
ex) alert icmp any any -> 192.168.11.45 any (msg:"ICMP TEST";threshold:type threshold,track by dst,count 10,seconds 1;sid:10000001; rev:001;) //동일 IP로 icmp 패킷이 1초에 10번 이상 전달되면 10번 마다 경고
- sameip : src ip와 dst ip 가 동일
alert ip any any -> any any (sameip;)
- flags
tcp flag
flags:[!|*|+]<FSRPAU>; // + : match on, *: match any. !:not match
S(SYN), F(FIN), A(ACK), U(UGR), P(PSH), R(RST)
ex) alert tcp any any -> any any (flags:SFAUPR;)
Rule 예제
- 사설 IP 접근 탐색
alert icmp 10.0.0.0/8 any -> any any (msg:"Bogon ip (A)"; sid:1000001;)
alert icmp 172.16.0.0/12 any -> any any (msg:"Bogon ip (B)"; sid:1000002;)
alert icmp 192.168.0.0/16 any -> any any (msg:"Bogon ip (C)"; sid:1000003;)
- flag 값을 통한 TCP 스캔 탐색
alert tcp any any -> any any (msg:"X-mas SCAN"; flags:UPF; sid:1000005;)
alert tcp any any -> any any (msg:"NULL SCAN"; flags:!UAPRSF; sid:1000006;)
- ICMP 탐색
alert icmp any any -> any any (msg:"ICMP Ping"; sid:1000007;)
alert icmp any any -> any any (msg:"ICMP Ping"; itype:13; sid:1000008;) //timestamp
alert icmp any any -> any any (msg:"ICMP Ping"; itype:15; sid:1000009;) //information
alert icmp any any -> any any (msg:"ICMP Ping"; itype:17; sid:1000010;) //Add mask
- UDP 패킷 탐색
alert udp any any -> any any (msg:"UDP packet"; sid:1000011;)
- Land Attack 탐색
alert icmp any any -> 192.168.11.0/24 any (msg:"Land Attack Detect"; sameip; sid:20000001;)
- Flooding 탐색
alert tcp any any -> any 80 (msg:"Att : SYN Flooding";flags: S; threshold: type threshold, track by_dst, count 10, seconds 1; sid:2000002;)
alert udp any any -> any any (msg:"ATT : UDP Flooding"; threshold: type threshold, track by_dst, count 10, seconds 1; sid:2000003;)
alert icmp any any -> any any (msg:"ATT : icmp Flooding"; threshold: type threshold, track by_dst, count 10, seconds 1; sid:2000004;)
- 탐색
alert tcp 192.168.11.45 22 -> any any (msg:"SSH BruteForce"; threshold:type threshold, track by_src, count 3, seconds 3; content:"SSH-2.0"; sid:10000012;) //hydra ssh 공격