Hi,
First of all, I am going to share with you some interesting links with helpful information to create custom decoders and rules:
You can add custom decoders and rules that fit your use case.
I will give you an example using the log you have shared.
First of all, I am going to see if there is any decoder or rule that matches. For this, I am going to use the /var/ossec/bin/wazuh-logtest tool.
After inserting the following log:
Oct 5 19:50:00 <dvc> fwlog: Log type: user authentication, user:<username>, IP:x.x.x.x, target:Log out, time logged in:2016-10-05 08:45:21, online duration:39878, time logged out:19:49:59
It shows the following result:
**Phase 1: Completed pre-decoding.
full event: 'Oct 5 19:50:00 <dvc> fwlog: Log type: user authentication, user:<username>, IP:x.x.x.x, target:Log out, time logged in:2016-10-05 08:45:21, online duration:39878, time logged out:19:49:59'
timestamp: 'Oct 5 19:50:00'
hostname: '<dvc>'
**Phase 2: Completed decoding.
No decoder matched.
As we can see, it has not been decoded and therefore cannot be used by any rule. Therefore we are going to create a custom decoder to decode this log.
I add the following decoders to the file /var/ossec/etc/decoders/local_decoder.xml.
<decoder name="sangfor-ngfw-generic">
<prematch>\p\S+\p fwlog: \.*</prematch>
</decoder>
<decoder name="sangfor-ngfw">
<parent>sangfor-ngfw-generic</parent>
<regex offset="after_parent">Log type:\s+(\.*), user:\s*(\.*), IP:\s*(\.*), target:\s*(\.*), time logged in:\s*(\.*), online duration:\s*(\.*), time logged out:\s*(\.*)</regex>
<order>log_type, user, ip, target, time_logged_in, online_duration, timme_logged_out</order>
</decoder>
Note: This is an example regex, edit it if necessary to generalize it if needed.
To use these decoders in a rule, I will use the example of wanting to generate an alert when the IP 192.168.1.15 disconnects from the session.
To do this, I add the following custom rule to the file /var/ossec/etc/rules/local_rules.xml.
<rule id="100050" level="3">
<decoded_as>sangfor-ngfw-generic</decoded_as>
<field name="log_type">user authentication</field>
<field name="ip">192.168.1.15</field>
<field name="target">Log out</field>
<description>Custom rule: $(ip) has logged out</description>
</rule>
I then test the following example log that should match those decoders and rule:
Oct 5 19:50:00 <dvc> fwlog: Log type: user authentication, user:test_user, IP:192.168.1.15, target:Log out, time logged in:2016-10-05 08:45:21, online duration:39878, time logged out:19:49:59
**Phase 1: Completed pre-decoding.
full event: 'Oct 5 19:50:00 <dvc> fwlog: Log type: user authentication, user:test_user, IP:192.168.1.15, target:Log out, time logged in:2016-10-05 08:45:21, online duration:39878, time logged out:19:49:59'
timestamp: 'Oct 5 19:50:00'
hostname: '<dvc>'
**Phase 2: Completed decoding.
name: 'sangfor-ngfw-generic'
dstuser: 'test_user'
ip: '192.168.1.15'
log_type: 'user authentication'
online_duration: '39878'
target: 'Log out'
time_logged_in: '2016-10-05 08:45:21'
timme_logged_out: '19:49:59'
**Phase 3: Completed filtering (rules).
id: '100050'
level: '3'
description: 'Custom rule: 192.168.1.15 has logged out'
groups: '['local', 'syslog', 'sshd']'
firedtimes: '1'
mail: 'False'
**Alert to be generated.
Now we observe how the log has been correctly coded, and the alert has been generated for the mentioned use case.
Once tested, restart the wazuh-manager to apply the changes to the rules and decoders.
systemctl restart wazuh-manager
I hope this information is helpful.
Best regards.