Decoder para un log simiar a IDS IPS

199 views
Skip to first unread message

suricata

unread,
May 4, 2023, 8:21:32 AM5/4/23
to Wazuh mailing list
Hola a todos,

Estoy intentando crear un decoder para un log que es el que pongo más abajo, pero algo me falla y no sé exactamente qué es.

Apr 27 23:45:17 control KerioControl  IPS: Alert, severity: High, Rule ID: 1:2525034 ET 3CORESec Poor Reputation IP TCP group 18, proto:TCP, ip/port:194.26.xx.xxx:48958 -> 192.168.xxx.xxx:8443 (control)

A ver si alguien me4 puede dar una pista.
Gracias,

<decoder name="kerio">
  <program_name>^kerio</program_name>
</decoder>

<decoder name="kerio">
  <type>ids</type>
  <prematch>^severity \S+","\S+","\S+","\S+","\S+</prematch>
</decoder>

<group name="kerio,">
   <rule id="110001" level="5">
     <decoded_as>kerio</decoded_as>
     <description>IPS kerio</description>
   </rule>
</group>


Saludos,

Nicolas Alejandro Bertoldo

unread,
May 4, 2023, 10:47:49 AM5/4/23
to Wazuh mailing list
Hola,

Gracias por utilizar Wazuh!
Puedes probar con el siguiente decoder:

<decoder name="kerio">
  <program_name>KerioControl</program_name>

</decoder>

<decoder name="kerio">
  <type>ids</type>
  <prematch type="pcre2">severity: .*?, .*?, .*?, .*</prematch>
</decoder>


A continuación puedes ver la salida del Wazuh logtest:

[root@wazuh-server wazuh-user]# /var/ossec/bin/wazuh-logtest
Starting wazuh-logtest v4.4.1
Type one log per line


Apr 27 23:45:17 control KerioControl  IPS: Alert, severity: High, Rule ID: 1:2525034 ET 3CORESec Poor Reputation IP TCP group 18, proto:TCP, ip/port:194.26.xx.xxx:48958 -> 192.168.xxx.xxx:8443 (control)

**Phase 1: Completed pre-decoding.
full event: 'Apr 27 23:45:17 control KerioControl  IPS: Alert, severity: High, Rule ID: 1:2525034 ET 3CORESec Poor Reputation IP TCP group 18, proto:TCP, ip/port:194.26.xx.xxx:48958 -> 192.168.xxx.xxx:8443 (control)'
timestamp: 'Apr 27 23:45:17'
hostname: 'control'

**Phase 2: Completed decoding.
name: 'kerio'

**Phase 3: Completed filtering (rules).
id: '20101'
level: '6'
description: 'IDS event.'
groups: '['ids']'
firedtimes: '1'
mail: 'False'
**Alert to be generated.


Para realizar pruebas con las regex, puede ser muy útil esta herramienta: https://regex101.com/

Espero que esto te sirva de ayuda. 
Saludos

suricata

unread,
May 4, 2023, 1:10:54 PM5/4/23
to Wazuh mailing list
Hola Nicolas,
Gracias por tu ayuda.

El Wazuh logtesh sale correcto.

He creado una rule:

   <rule id="110001" level="6">

     <decoded_as>kerio</decoded_as>
     <description>IPS kerio</description>
   </rule>
   <rule id="110002" level="6">
     <decoded_as>kerio</decoded_as>
     <description>'IDS event.</description>
   </rule>
</group>

Supongo que con esto debe salir ya algo en cuanto se genere un log.

Saludos,

suri cata

unread,
May 5, 2023, 2:38:14 AM5/5/23
to Wazuh mailing list
Buenos días, Nicolás,

Sale perfectamente la alerta.
ideese.PNG
Lo que me gustaría es que en la descripción apareciera más información. Lo he intentado con el full_log, pero no hay manera de que salga.
Con que me apareciera algo parecido al full_log sería para mí más que suficiente,

Saludos,

--
You received this message because you are subscribed to a topic in the Google Groups "Wazuh mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/wazuh/WgQY2tDn7mU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to wazuh+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/wazuh/eec6e2b3-f37e-46cb-8ddc-6ee18c06773cn%40googlegroups.com.

suricata

unread,
May 5, 2023, 5:38:57 AM5/5/23
to Wazuh mailing list
Hola,

He modificado el decoder para filtrar las alertas que necesito. Funciona. Pero como he comentado antes, en la descripción solo aparece "Evento IDS/IPS"
Me gustaría que apareciera algún campo más como la alerta en s´-i, laip y puertos, etc

<decoder name="kerio">
  <program_name>KerioControl</program_name>
</decoder>

<decoder name="kerio">
  <type>ids</type>
  <prematch type="pcre2">(IPS: (Alert|Packet drop), severity: (\S+), Rule ID: (\d+):(\d+) (ET|ssp_ssl\:)+(.*), proto:(\S+), ip\/port:(\S+) (\S+)+(\S+) (\S+))</prematch>
</decoder>

De momento esto es lo que llevo,

Saludos,

Nicolas Alejandro Bertoldo

unread,
May 8, 2023, 1:24:47 PM5/8/23
to Wazuh mailing list
Hola,

Antes que nada, disculpas por la demora en la respuesta.
Estaría faltando extraer los campos (con la opción <order>) que deseas visualizar cuando se dispare la alerta. Puedes seguir esta guía de referencia: Creating decoders and rules from scratch
Aquí te dejo un ejemplo del decoder y la salida de wazuh-logtest:

<decoder name="kerio">
  <program_name>KerioControl</program_name>
</decoder>

<decoder name="kerio">
  <type>ids</type>
  <prematch type="pcre2">IPS: Alert|Packet drop, </prematch>
  <regex type="pcre2">severity: (\w+), Rule ID: (.*?), proto:(\w+), ip\/port:(\d+.\d+.\w+.\w+):(\d+) -> (\d+.\d+.\w+.\w+):(\d+) (\(\w+\))</regex>
  <order>severity, rule_id, proto, srcip, srcport, dstip, dstport, type</order>
</decoder>


--------------------------------------------------------------------

Starting wazuh-logtest v4.4.1
Type one log per line

Apr 27 23:45:17 control KerioControl  IPS: Alert, severity: High, Rule ID: 1:2525034 ET 3CORESec Poor Reputation IP TCP group 18, proto:TCP, ip/port:194.26.xx.xxx:48958 -> 192.168.xxx.xxx:8443 (control)

**Phase 1: Completed pre-decoding.
full event: 'Apr 27 23:45:17 control KerioControl  IPS: Alert, severity: High, Rule ID: 1:2525034 ET 3CORESec Poor Reputation IP TCP group 18, proto:TCP, ip/port:194.26.xx.xxx:48958 -> 192.168.xxx.xxx:8443 (control)'
timestamp: 'Apr 27 23:45:17'
hostname: 'control'

**Phase 2: Completed decoding.
name: 'kerio'
dstip: '192.168.xxx.xxx'
dstport: '8443'
proto: 'TCP'
rule_id: '1:2525034 ET 3CORESec Poor Reputation IP TCP group 18'
severity: 'High'
srcip: '194.26.xx.xxx'
srcport: '48958'
type: '(control)'


**Phase 3: Completed filtering (rules).
id: '20101'
level: '6'
description: 'IDS event.'
groups: '['ids']'
firedtimes: '1'
mail: 'False'
**Alert to be generated.


Saludos.


suricata

unread,
May 9, 2023, 8:27:39 AM5/9/23
to Wazuh mailing list
Gracias Nico, Todo funciona perfectamente,

He creado un decoder y rule nuevo para un tipo de log que no termina de salir:

Log: solo cambia un guión y la fecha solo tiene un dígito (9)

May  9 12:27:06 control KerioControl  IPS: Alert, severity: Low, Rule ID: 1:2013409 ET POLICY Outbound MSSQL Connection to Non-Standard Port - Likely Malware, proto:TCP, ip/port:192.168.4.21:60412 -> 20.216.165.5:63009



Rule:

<group name="ids,">

   <rule id="110002" level="6">
     <category>ids</category>
     <description>Evento IDS/IPS Alerta $(severity) $(rule_id) $(proto) $(srcip) $(dstip)</description>
   </rule>
</group>

Decoder:

<decoder name="kerio1">
  <program_name>KerioControl1</program_name>
</decoder>

<decoder name="kerio1">
  <type>ids</type>

  <prematch type="pcre2">IPS: Alert|Packet drop, </prematch>
  <regex type="pcre2">severity: (\w+), Rule ID: (.*?) - (.*), proto:(\w+), ip\/port:(\d+.\d+.\w+.\w+):(\d+) -> (\d+.\d+.\w+.\w+):((\d+))</regex>

  <order>severity, rule_id, proto, srcip, srcport, dstip, dstport, type</order>
</decoder>

Pero hace referencia al decorder y reglas anteriores:

**Phase 1: Completed pre-decoding.
full event: 'May  9 12:27:06 control KerioControl  IPS: Alert, severity: Low, Rule ID: 1:2013409 ET POLICY Outbound MSSQL Connection to Non-Standard Port - Likely Malware, proto:TCP, ip/port:192.168.4.21:60412 -> 20.216.165.5:63009'
timestamp: 'May  9 12:27:06'

hostname: 'control'

**Phase 2: Completed decoding.
name: 'kerio'

**Phase 3: Completed filtering (rules).
id: '110001'
level: '6'
description: 'Evento IDS/IPS Alerta     '
groups: '["ids"]'
firedtimes: '1'
mail: 'false'
**Alert to be generated

El viernes, 5 de mayo de 2023 a las 8:38:14 UTC+2, suri cata escribió:

Nicolas Alejandro Bertoldo

unread,
May 9, 2023, 5:30:09 PM5/9/23
to Wazuh mailing list
Hola,

Si observas la regex del decoder, verás que está capturando Rule ID en dos campos diferentes Rule ID: (.*?) - (.*) , mientras que en <order> solo defines un campo (rule_id) para esos dos valores capturados.
Por otro lado, en la captura de las direcciones IP, los dos ultimos valores del octeto admiten words -> (\d+.\d+.\w+.\w+), y en el log de ejemplo los valores son numéricos.

Como ejemplo para ese evento, es válido este decoder:

<decoder name="kerio">
  <type>ids</type>
  <prematch type="pcre2">IPS: Alert|Packet drop, </prematch>
  <regex type="pcre2">severity: (\w+), Rule ID: (.*?), proto:(\w+), ip\/port:(\d+.\d+.\S+.\S+):(\d+) -> (\d+.\d+.\S+.\S+):(\d+)</regex>
  <order>severity, rule_id, proto, srcip, srcport, dstip, dstport</order>
</decoder>


Aquí está la salida del logtest:

Starting wazuh-logtest v4.4.1
Type one log per line

May  9 12:27:06 control KerioControl  IPS: Alert, severity: Low, Rule ID: 1:2013409 ET POLICY Outbound MSSQL Connection to Non-Standard Port - Likely Malware, proto:TCP, ip/port:192.168.4.21:60412 -> 20.216.165.5:63009

**Phase 1: Completed pre-decoding.
full event: 'May  9 12:27:06 control KerioControl  IPS: Alert, severity: Low, Rule ID: 1:2013409 ET POLICY Outbound MSSQL Connection to Non-Standard Port - Likely Malware, proto:TCP, ip/port:192.168.4.21:60412 -> 20.216.165.5:63009'
timestamp: 'May  9 12:27:06'
hostname: 'control'

**Phase 2: Completed decoding.
name: 'kerio'
dstip: '20.216.165.5'
dstport: '63009'
proto: 'TCP'
rule_id: '1:2013409 ET POLICY Outbound MSSQL Connection to Non-Standard Port - Likely Malware'
severity: 'Low'
srcip: '192.168.4.21'
srcport: '60412'


**Phase 3: Completed filtering (rules).
id: '20101'
level: '6'
description: 'IDS event.'
groups: '['ids']'
firedtimes: '1'
mail: 'False'
**Alert to be generated.

Sin embargo, para estos casos donde los eventos tienen una estructura dinámica y, a veces se omiten algunos valores, puede ser útil trabajar con: Sibling decoders

Saludos. 

suricata

unread,
May 11, 2023, 1:42:04 AM5/11/23
to Wazuh mailing list
Buenos días, Nicolas.

Con tu respuesta ya salían bien algunos tipos de alertas. He realizado unos retoques añadiendo algunas cosas más en el decoder y ya salen todos. Muchas gracias por tu ayuda.
He añadido dos campos más.

<decoder name="kerio">
  <type>ids</type>
  <prematch type="pcre2">IPS: Alert|Packet drop, </prematch>
  <regex type="pcre2">severity: (\w+), Rule ID: (.*?), proto:(\S+), ip\/port:(\d+.\d+.\w+.\w+):(\d+)\s?(\S+)? -> (\d+.\d+.\w+.\w+):(\d+)\s?(\S+)?</regex>
  <order>severity, rule_id, proto, srcip, srcport, srcres, dstip, dstport, dstres</order>
</decoder>

He creado también un dashboard simple:

keriodash.png

Saludos y gracias,
Reply all
Reply to author
Forward
0 new messages