Suricata 規則配置
IDS/IPS/WAF
IPS、IDS和WAF分別是入侵防御系統和入侵檢測系統以及WEB應用防火牆的簡稱,很多人說這些玩意不就是盒子嗎已經過時了,其實不是,SIEM其實是有效的正規的打法,對於內網安全監控室非常必要的東西。之前大家的方式都是摒棄盒子思維,覺得盒子不靠譜防御不了真正的攻擊行為。這樣的理解難說不是國內眾多盒子廠商(本人待過很多)走低價競爭路線的一個惡性的結果。其實在數據驅動安全的幾天,盒子的作用絕不是簡單的匹配規則阻斷攻擊這么簡單的了,而是成為內網信息收集的一個Agent節點,作為雲化的安全能力中心節點的觸角存在,這都是非常有意義而且有必要的。
當然,我們還需要其他的更多的日志,不僅是網絡層面的,需要主機層的日志信息、服務應用的日志信息等等。
規則和驗證腳本
那么作為雲的觸角和雲的核心節點(安全能力節點)有兩種能力是必須具備的。第一脆弱性的發現能力(POC、EXP);第二就是威脅的監控能力,就是匹配規則。二者都來源於對攻擊的理解。POC和EXP是模仿攻擊的操作。規則是攻擊行為的特征,是檢測威脅的有效手段。廢話不多說了,今天我們來學習Suricata規則。
Suricata規則范式
alert tcp any any -> any any (msg:"";content:"";sid:1;rev:1;)
其實格式就是:
動作 協議 源地址 源端口 方向 目的地址 目的端口 (規則內容)
備注1:規則內容前面稱為規則頭部分
備注2:規則內容用分號分割,每一項都是一個key-value的鍵值對 ,如上圖示例
Suricata 規則頭
-
動作:
- alert 告警
- log 記錄
- pass 通過
- drop 丟棄
-
協議:
- TCP
- UDP
- ICMP
- IP
- Any
-
源和目的IP:
- IP地址 舉例 10.1.1.1 或者 ! 10.1.1.1 或則[1.1.1.1 , 1.1.1.2] 或者! [1.1.1.1 , 1.1.1.2]
- IP地址段(CIDR)[10.0.0.0/24]
- Any
-
元和目的端口:
- 端口 80 或者 [80,443] 當然 ! 80 或者 ! [80,443] 再有 [1:80,![2,3]] [80:82]
- Any
-
方向:
- 單項 ->
- 雙向 <>
Suricata 規則內容
Meta-settings
- msg:"description"; 描述字段,報警的時候的一些描述信息,比如某某某攻擊等的
- sid: 1; 簽名ID編號 1-
- rev: 3; 修訂版本 1-
- gid: 2; 組ID
- classtype:trojan-activity; 查看classification.config文件中的配置,后面有優先級。
- reference: bugtraq, 123; http://www.securityfocus.com/bid 或者 reference: url, www.info.nl
- priority:1; 優先級1-255 1-4常用 優先級越小越優先
- target:[src_ip|dest_ip] 報警時候回上報這個格式的,含義是[攻擊源|攻擊目標]
Header-Keyword
- ttl:10 數據包中的ttl
- ipopts:
- rr 記錄路由
- eol list最后
- nop
- ts
- sec
- esec
- lsrr
- ssrr
- satid
- any
- sameip;當數據報文的源和目的IP相同時候
- ip_proto:<name|id>
- 1 ICMP
- 6 TCP
- 17 UDP
- id:1 每一個IP報文發送后id+1,一個IP報文的多個分片ID一致
- geoip
- geoip: src, RU;
- geoip: both, CN, RU;
- geoip: dst, CN, RU, IR;
- geoip: both, US, CA, UK;
- geoip: any, CN, IR; - TCP關鍵字:
- ack:0;
- seq:0;
- window:55808;
- 等等...
- ICMP關鍵字:
- itype:8;
- itype:>10;
- icode 和itype類似
- icmp_id 和 icmp_seq
- fragbits和fragoffset
prefilter 預過濾
prefilter之前的規則屬於預過濾規則
payload 關鍵字
- content: ”............” ->
- content:“a|0D|bc”;
- content:”|61 0D 62 63|";
- content:”a|0D|b|63|”;
- pcre:"
" - content:"index.";|http_uri;pcre:"
";就可以匹配出content符合 index. 的payload
- content:"index.";|http_uri;pcre:"
- nocase; 忽略大小寫
- depth:3 payload出現的具體位置
- offset:4 便宜量
- distance:2
- content:"abc";content:"dev";distance:"1" -> payload:"abcsdev" 匹配成功
- within:4 判斷 payload -> "abcxxxdefxxxddsew" content:"abc";content:"def";within:3 -> 第二個匹配段的結尾與第一個匹配段的結尾的距離在within的的數值之內。
- content:"abc";content:"def";distance:4;within:9 -> abcxxxxdef 匹配成功 xxxx 距離4 f到從的距離是xxxx+payload2的長度 = 3+4 = 7
- isdataat:8 看看content結尾字符后面第isdataat位置是否還有數據
- dsize:345; payload長度,也可以是>或者<
- rpc 和RPC相關
- rpc:100009,*,*;
- replace:"asd"; content:"abvd";replace:"abcd" 替換,只能用於IPS之中
- fast_pattern 略
HTTP 關鍵字
請求字段
Keyword | Sticky or Modifier | Direction |
---|---|---|
http_uri | Modifier | Request |
http_raw_uri | Modifier | Request |
http_method | Modifier | Request |
http_request_line | Sticky Buffer | Request |
http_client_body | Modifier | Request |
http_header | Modifier | Both |
http_raw_header | Modifier | Both |
http_cookie | Modifier | Both |
http_user_agent | Modifier | Request |
http_host | Modifier | Request |
http_raw_host | Modifier | Request |
http_accept | Sticky Buffer | Request |
http_accept_lang | Sticky Buffer | Request |
http_accept_enc | Sticky Buffer | Request |
http_referer | Sticky Buffer | Request |
http_connection | Sticky Buffer | Request |
http_content_type | Sticky Buffer | Both |
http_content_len | Sticky Buffer | Both |
http_start | Sticky Buffer | Both |
http_protocol | Sticky Buffer | Both |
http_header_names | Sticky Buffer | Both |
響應字段
Keyword | Sticky or Modifier | Direction |
---|---|---|
http_stat_msg | Modifier | Response |
http_stat_code | Modifier | Response |
http_response_line | Sticky Buffer | Response |
http_header | Modifier | Both |
http_raw_header | Modifier | Both |
http_cookie | Modifier | Both |
http_server_body | Modifier | Response |
file_data | Sticky Buffer | Response |
http_content_type | Sticky Buffer | Both |
http_content_len | Sticky Buffer | Both |
http_start | Sticky Buffer | Both |
http_protocol | Sticky Buffer | Both |
http_header_names | Sticky Buffer | Both |
以上用法
content:"xxxxxx";http_xxxx;
特例:
- uricontent:"xxxx";
- urilen:10 > <也可以
- http_header 不包含URI部分
流信息關鍵字
-
flow:to_client 關鍵字:
- to_client
- to_server
- from_client
- from_server
- established
- not_established
- stateless
- only_stream
- no_stream
- only_frag
- no_frag
-
stream_size
- >
- <
- =
- !=
- >=
- <=
文件關鍵字
- filename:"a.php";
- fileext:"jpg";
- filemagic:"";
- filestore:[request|response],[file|tx|ssn]
- filenmd5:[!]filename; filenmd5:md5-blacklist;
- filesize:5 > < 也可以
閾值
- threshold: type <threshold|limit|both>, track <by_src|by_dst>, count
, seconds - threshold: type threshold, track by_src, count 10, seconds 60;
- detection_filter: track <by_src|by_dst>, count
, seconds
DNS關鍵字
dns_query;content:"域名"