当前位置: 首页 > article >正文

【主机入侵检测】Wazuh解码器之JSON解码器

在这里插入图片描述

前言

Wazuh 是一个开源的安全平台,它使用解码器(decoders)来从接收到的日志消息中提取信息。解码器将日志信息分割成字段,以便进行分析。Wazuh 解码器使用 XML 语法,允许用户指定日志数据应该如何被解析和规范化。解码器的工作分为两个阶段:预解码(pre-decoding)和解码(decoding)。在预解码阶段,如果存在类似 syslog 的头部,会提取时间戳、主机名和程序名等一般信息。在随后的解码阶段,解码器解析并解释剩余的日志数据,提取更多相关信息。
Wazuh 内置了一个专门用于 JSON 格式日志的 JSON 解码器。用户还可以创建自定义解码器,以适应特定的需求并提高检测能力。

JSON 解码器

JSON解码器能够提取数字、字符串、布尔值、空值、数组和对象等数据类型。提取的字段被存储为动态字段(即不属于Wazuh内置类型字段),可以被规则引用。下面示例展示Wazuh对Suricata(开源的网络入侵检测)生成的告警日志进行解码操作,Suricata告警日志为JSON格式。

Suricata日志

{
“timestamp”: “2023-05-02T17:46:48.515262+0000”,
“flow_id”: 1234,
“in_iface”: “eth0”,
“event_type”: “alert”,
“src_ip”: “16.10.10.10”,
“src_port”: 5555,
“dest_ip”: “16.10.10.11”,
“dest_port”: 80,
“proto”: “TCP”,
“alert”: {
“action”: “allowed”,
“gid”: 1,
“signature_id”: 2019236,
“rev”: 3,
“signature”: “ET WEB_SERVER Possible CVE-2014-6271 Attempt in HTTP Version Number”,
“category”: “Attempted Administrator Privilege Gain”,
“severity”: 1
},
“payload”: “21YW5kXBtgdW5zIGRlcHJY2F0QgYWI”,
“payload_printable”: “this_is_an_example”,
“stream”: 0,
“host”: “suricata.com”
}

JSON解码器无需依赖Suricata解码器即可从JSON日志中提取每个字段的内容。接下来,我们可以在Wazuh服务器上运行Wazuh自带的wazuh-logtest工具来解析这段日志,该工具会将预解码、解码阶段和规则匹配结果输出到终端,方便我们学习解码器运行过程。该工具默认在/var/ossec/bin/wazuh-logtest路径下。下面是该工具对日志解析结果:

Type one log per line

{"timestamp":"2023-05-02T17:46:48.515262+0000","flow_id":1234,"in_iface":"eth0","event_type":"alert","src_ip":"16.10.10.10","src_port":5555,"dest_ip":"16.10.10.11","dest_port":80,"proto":"TCP","alert":{"action":"allowed","gid":1,"signature_id":2019236,"rev":3,"signature":"ET WEB_SERVER Possible CVE-2014-6271 Attempt in HTTP Version Number","category":"Attempted Administrator Privilege Gain","severity":1},"payload":"21YW5kXBtgdW5zIGRlcHJY2F0QgYWI","payload_printable":"this_is_an_example","stream":0,"host":"suricata.com"}

**Phase 1: Completed pre-decoding.

**Phase 2: Completed decoding.
        name: 'json'
        alert.action: 'allowed'
        alert.category: 'Attempted Administrator Privilege Gain'
        alert.gid: '1'
        alert.rev: '3'
        alert.severity: '1'
        alert.signature: 'ET WEB_SERVER Possible CVE-2014-6271 Attempt in HTTP Version Number'
        alert.signature_id: '2019236'
        dest_ip: '16.10.10.11'
        dest_port: '80'
        event_type: 'alert'
        flow_id: '1234'
        host: 'suricata.com'
        in_iface: 'eth0'
        payload: '21YW5kXBtgdW5zIGRlcHJY2F0QgYWI'
        payload_printable: 'this_is_an_example'
        proto: 'TCP'
        src_ip: '16.10.10.10'
        src_port: '5555'
        stream: '0'
        timestamp: '2023-05-02T17:46:48.515262+0000'

**Phase 3: Completed filtering (rules).
        id: '86601'
        level: '3'
        description: 'Suricata: Alert - ET WEB_SERVER Possible CVE-2014-6271 Attempt in HTTP Version Number'
        groups: '['ids', 'suricata']'
        firedtimes: '1'
        mail: 'False'
**Alert to be generated.

Wazuh解码器的预解码阶段和解码阶段的解码结果分别对应着上面(Phase 1和Phase 2),规则匹配阶段为(Phase 3)。通过查看每个阶段的输出我们可以看到,Wazuh在预解码和解码阶段已经成功的将Suricata日志中关键信息提取,并且在规则匹配阶段命中了ID为86601的规则。

偏移(offset)

Wazuh解码器的offset属性允许解码器跳过日志的一部分来进行解码操作。此机制适用于所解码的日志中既包含JSON格式数据,还包含其它类型的数据。例如,我们收到一段日志如下所示,既包含JSON数据,也包含日志的元信息。

2018 Apr 04 13:11:52 nba_program: this_is_an_example: " player_information: "{ “name”: “Stephen”, “surname”: “Curry”, “team”: “Golden State Warriors”, “number”: 30, “position”: “point guard”}

分析上面的日志信息,真正的JSON格式数据是字符串"player_information"之后的信息,我们需要告诉JSON解码器从该字符串开始进行解码操作。下面是我们通过配置offset属性来完成跳过功能。

<decoder name="raw_json">
    <program_name>nba_program</program_name>
    <prematch>player_information: "</prematch>
    <plugin_decoder offset="after_prematch">JSON_Decoder</plugin_decoder>
</decoder>

重点关注<prematch>标签和<plugin_decoder offset=“after_prematch”>标签,其它的标签含义会在后面的文章中介绍。前者表示该解码器要想执行解码操作,日志中必须包含"player_information: "字符串。后者表示使用JSON_Decoder作为解码插件,解码所匹配的日志,offset属性表示跳过<prematch>所匹配的字符串,即"player_information: "

配置好解码器后使用wazuh-logtest工具解析解析这段日志结果如下:

Type one log per line

2018 Apr 04 13:11:52 nba_program: this_is_an_example: " player_information: "{ "name": "Stephen", "surname": "Curry", "team": "Golden State Warriors", "number": 30, "position": "point guard"}

**Phase 1: Completed pre-decoding.
        full event: '2018 Apr 04 13:11:52 nba_program: this_is_an_example: " player_information: "{ "name": "Stephen", "surname": "Curry", "team": "Golden State Warriors", "number": 30, "position": "point guard"}'
        timestamp: '2018 Apr 04 13:11:52'
        program_name: 'nba_program'

**Phase 2: Completed decoding.
        name: 'raw_json'
        name: 'Stephen'
        number: '30'
        position: 'point guard'
        surname: 'Curry'
        team: 'Golden State Warriors'

正是我们期望的结果,JSON解码器会忽略掉日志中非JSON格式的日志内容。


http://www.kler.cn/news/289823.html

相关文章:

  • 24并发设计模式——线程池模式
  • 台球助教系统小程序源码开发与技术解析
  • LLM大模型学习:LoRA 大模型微调的利器
  • 第三届人工智能与智能信息处理国际学术会议(AIIIP 2024)
  • 在SpringMVC中用fmt标签实现国际化/多语言
  • 装饰器模式(Decorator Pattern)
  • MACOS安装配置前端开发环境
  • 北芯生命持续亏损:产能利用率不理想仍扩产能,销售费用越来越高
  • Python世界:文件自动化备份实践
  • 由一个 SwiftData “诡异”运行时崩溃而引发的钩深索隐(一)
  • 工业交换机如何确保品质
  • glsl着色器学习(四)
  • 日常避坑指南:如何合理利用Swap优化MongoDB内存管理
  • Linux驱动开发基础(IRDA 红外遥控模块)
  • E6000物联网主机:打造智慧楼宇的未来
  • Linux:vim编辑器的基本使用
  • 不小心删除丢失了所有短信?如何在 iPhone 上查找和恢复误删除的短信
  • 6 自研rgbd相机基于rk3566之深度计算库移植及测试
  • Spring Boot集成Spring Cloud Scheduler进行任务调度
  • 如何使用Spoon连接data-integration-server并在服务器上执行转换
  • nginx配置白名单服务
  • Gnu: binutils: ld: .gnu.warning.链接时的主动警告 glibc
  • IP地址与物理地址:‌区别解析及在网络通信中的作用
  • 开始使用 ROS 工具箱
  • 3144. 分割字符频率相等的最少子字符串
  • C#Is和As的区别:
  • 工业图像输出卡设计原理图:FMC214-基于FMC兼容1.8V IO的Full Camera Link 输出子卡
  • 排查 Kafka 生产者服务问题的实战经验总结(dubbo的Serializable 问题)
  • ISO 26262中的失效率计算:SN 29500-11 Expected values for contactors
  • Spark MLlib模型训练—回归算法 Isotonic Regression