Hi IBM Qradar,
When you are testing decoders and rules in ossec-logtest
tool, you have to enter the raw log without any event header. For example, I see that you are entering the following:
"2020 Dec 07 15:40:16 (xxxxxxxxxx1) any->\aem\logpath\logs\access.log 07.12.2020 15:40:32.058 *INFO* [qtp305148339-1116906] access.log 11.11.111.11 - anonymous 07/Dec/2020:15:40:32 +0100 GET /url/random HTTP/1.1 200 2"
and that log corresponds to the entire event (you probably got it from the archives.log
file). As you can see, this log contains some extra headers added by wazuh, so it does not correspond to the original log sent by the agent.
The log that you have to enter in ossec-logtest
tool would be as follows:
\aem\logpath\logs\access.log 07.12.2020 15:40:32.058 *INFO* [qtp305148339-1116906] access.log 11.11.111.11 - anonymous 07/Dec/2020:15:40:32 +0100 GET /url/random HTTP/1.1 200 2"
I also see that the log that you are entering does not correspond to the format specified in the decoder since you have added the event headers in your decoders regex. Please, adapt the decoders to the log that I mentioned above.
If you need help with a particular case, tell me exactly which log you want to decode, what fields you want to decode, and any particular case to generate an alert.
Best regards.
Hi IBM Qradar,
You have to write the decoder and rule regex from the original log stored and sent by the agent to the manager. Where did you get the log that you have shared with me? Surely from archives.log
, but this file contains all received events, including the headers like I commented to you in the last message.
I suppose that the original log is the following:
\aem\publish\crx-quickstart\logs\access.log 07.12.2020 15:40:32.058 *INFO* [qtp305148339-1116906] access.log 213.8.114.1 - anonymous 07/Dec/2020:15:40:32 +0100 "GET /random/urlquery/token.json HTTP/1.1" 200 2 "https://referrer/random.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
From this log, I am going to create some custom decoders to decode your desired fields. I have added them in /var/ossec/etc/decoders/local_decoder.xml
file.
<decoder name="adobe_cloud">
<prematch>\S+ \d+.\d+.\d+ \d+:\d+:\d+.\d+ \S+ [\.+]</prematch>
</decoder>
<decoder name="adobe_cloud_custom">
<parent>adobe_cloud</parent>
<regex offset="after_parent">\S+ (\d+.\d+.\d+.\d+) - (\w+) \S+ \S+ "\S+ (\S+) \S+" (\d+) \d+ "(\S+)" "(\.+)"</regex>
<order>source_ip, username, uri, status_code, url, user_agent</order>
</decoder>
If we run again the ossec-logtest
tool, we can see now that your desired fields are decoded:
\aem\publish\crx-quickstart\logs\access.log 07.12.2020 15:40:32.058 *INFO* [qtp305148339-1116906] access.log 213.8.114.1 - anonymous 07/Dec/2020:15:40:32 +0100 "GET /random/urlquery/token.json HTTP/1.1" 500 2 "https://referrer/random.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
**Phase 1: Completed pre-decoding.
full event: '\aem\publish\crx-quickstart\logs\access.log 07.12.2020 15:40:32.058 *INFO* [qtp305148339-1116906] access.log 213.8.114.1 - anonymous 07/Dec/2020:15:40:32 +0100 "GET /random/urlquery/token.json HTTP/1.1" 200 2 "https://referrer/random.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"'
timestamp: '(null)'
hostname: 'manager'
program_name: '(null)'
log: '\aem\publish\crx-quickstart\logs\access.log 07.12.2020 15:40:32.058 *INFO* [qtp305148339-1116906] access.log 213.8.114.1 - anonymous 07/Dec/2020:15:40:32 +0100 "GET /random/urlquery/token.json HTTP/1.1" 200 2 "https://referrer/random.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"'
**Phase 2: Completed decoding.
decoder: 'adobe_cloud'
source_ip: '213.8.114.1'
username: 'anonymous'
uri: '/random/urlquery/token.json'
status_code: '200'
url: 'https://referrer/random.html'
user_agent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'
Important: Note that this log only works when the log format matches with the decoder regex. In case a log can have multiple formats, you will have to write more decoders to cover all possible cases.
Regarding the rules, for example, if we want to generate an alert when the status code is 500, we could do something like this in /var/ossec/etc/rules/local_rules.xml
:
<rule id="100120" level="5">
<decoded_as>adobe_cloud</decoded_as>
<field name="status_code">500</field>
<description>Server error</description>
</rule>
Now, if we test a log with status code 500, we can check that the alert would be generated:
\aem\publish\crx-quickstart\logs\access.log 07.12.2020 15:40:32.058 *INFO* [qtp305148339-1116906] access.log 213.8.114.1 - anonymous 07/Dec/2020:15:40:32 +0100 "GET /random/urlquery/token.json HTTP/1.1" 500 2 "https://referrer/random.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
**Phase 1: Completed pre-decoding.
full event: '\aem\publish\crx-quickstart\logs\access.log 07.12.2020 15:40:32.058 *INFO* [qtp305148339-1116906] access.log 213.8.114.1 - anonymous 07/Dec/2020:15:40:32 +0100 "GET /random/urlquery/token.json HTTP/1.1" 500 2 "https://referrer/random.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"'
timestamp: '(null)'
hostname: 'manager'
program_name: '(null)'
log: '\aem\publish\crx-quickstart\logs\access.log 07.12.2020 15:40:32.058 *INFO* [qtp305148339-1116906] access.log 213.8.114.1 - anonymous 07/Dec/2020:15:40:32 +0100 "GET /random/urlquery/token.json HTTP/1.1" 500 2 "https://referrer/random.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"'
**Phase 2: Completed decoding.
decoder: 'adobe_cloud'
source_ip: '213.8.114.1'
username: 'anonymous'
uri: '/random/urlquery/token.json'
status_code: '500'
url: 'https://referrer/random.html'
user_agent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'
**Phase 3: Completed filtering (rules).
Rule id: '100120'
Level: '5'
Description: 'Server error'
**Alert to be generated.
You can find more useful information about how to create custom decoders and rules in the following links:
• Creating decoders and rules from scratch: https://wazuh.com/blog/creating-decoders-and-rules-from-scratch/
• Sibling decoders: flexible extraction of information: https://wazuh.com/blog/sibling-decoders-flexible-extraction-of-information/
• Custom rules and decoders: https://documentation.wazuh.com/4.0/user-manual/ruleset/custom.html
• Testing decoders and rules: https://documentation.wazuh.com/4.0/user-manual/ruleset/testing.html
I hope this helps you :)
Best regards.
Hi,
No, there is nothing reported about it for 4.0
. A few notes about your use case:
Have you restarted the wazuh-manager after setting the new decoders and rules? When you are going to test it in ossec-logtest
tool, it is not necessary, but when you want to apply the new changes, you have to restart the wazuh-manager to load the new configuration.
As you tell me, it works in ossec-logtest
tool, but it does not work when you are adding the log in test_file.log
. Maybe something strange is happening with the echo
.
echo '<test_log>' >> /var/log/test_file.log
vi
or nano
commands.Check it and tell me. If it does not work, then you have to share with me all the related information: decoders, rules, localfile block in ossec.conf … in order to help you better.
Best regards.
Hi,
As I see it, you are not using the same log to check both cases. If you notice, in the first case, the string fields of the log are between double quotes, while in the second case (which is the one that doesn’t work) they are not.
Note that the regex of the decoders does specify the use of these quotes, so the reason is that.
<decoder name="fortigate-custom">
<prematch>^date=\d\d\d\d-\d\d-\d\d time=\d\d:\d\d:\d\d devname="\S+"</prematch>
</decoder>
<decoder name="fortigate-custom1">
<parent>fortigate-custom</parent>
<regex>devid="(\S+)" logid="(\S+)" type="(\S+) subtype="(\S+)"</regex>
<order>devid, logid, type, subtype</order>
</decoder>
Replace test_file.log
with the following one and try again:
date=2019-10-10 time=17:01:31 devname="FG111E-INFT2" devid="FG201E4Q17901611" logid="0000000020" type="traffic" subtype="forward" level="notice" vd="root" eventtime=1573570891 srcip=192.168.56.105 srcname="wazuh.test.local" srcport=63874 srcintf="port1" srcintfrole="lan" dstip=54.97.146.111 dstport=443 dstintf="wan1" dstintfrole="wan" poluuid="3e421d8c-0210-51ea-2e5e-6dd151c37590" sessionid=261713795 proto=6 action="accept" user="WAZUH" authserver="FSSO_TEST_LOCAL" policyid=131 policytype="policy" service="HTTPS" dstcountry="United Kingdom" srccountry="Reserved" trandisp="snat" transip=195.46.111.2 transport=63874 appid=45553 app="Microsoft.Outlook.Office.365" appcat="Email" apprisk="medium" applist="INF-APP-MONITOR" appact="detected" duration=815 sentbyte=13941 rcvdbyte=13429 sentpkt=58 rcvdpkt=63 sentdelta=360 rcvddelta=2189 devtype="Windows PC" devcategory="Windows Device" osname="Windows" osversion="8.1" mastersrcmac="fc:45:96:44:79:c9" srcmac="fc:45:96:44:79:c9" srcserver=1 dstdevtype="Router/NAT Device" dstdevcategory="None" masterdstmac="28:8b:1c:db:7c:48" dstmac="28:8b:1c:db:7c:48" dstserver=0
You will see the following expected output:
**Phase 1: Completed pre-decoding.
full event: 'date=2019-10-10 time=17:01:31 devname="FG111E-INFT2" devid="FG201E4Q17901611" logid="0000000020" type="traffic" subtype="forward" level="notice" vd="root" eventtime=1573570891 srcip=192.168.56.105 srcname="wazuh.test.local" srcport=63874 srcintf="port1" srcintfrole="lan" dstip=54.97.146.111 dstport=443 dstintf="wan1" dstintfrole="wan" poluuid="3e421d8c-0210-51ea-2e5e-6dd151c37590" sessionid=261713795 proto=6 action="accept" user="WAZUH" authserver="FSSO_TEST_LOCAL" policyid=131 policytype="policy" service="HTTPS" dstcountry="United Kingdom" srccountry="Reserved" trandisp="snat" transip=195.46.111.2 transport=63874 appid=45553 app="Microsoft.Outlook.Office.365" appcat="Email" apprisk="medium" applist="INF-APP-MONITOR" appact="detected" duration=815 sentbyte=13941 rcvdbyte=13429 sentpkt=58 rcvdpkt=63 sentdelta=360 rcvddelta=2189 devtype="Windows PC" devcategory="Windows Device" osname="Windows" osversion="8.1" mastersrcmac="fc:45:96:44:79:c9" srcmac="fc:45:96:44:79:c9" srcserver=1 dstdevtype="Router/NAT Device" dstdevcategory="None" masterdstmac="28:8b:1c:db:7c:48" dstmac="28:8b:1c:db:7c:48" dstserver=0'
timestamp: '(null)'
hostname: 'manager2'
program_name: '(null)'
log: 'date=2019-10-10 time=17:01:31 devname="FG111E-INFT2" devid="FG201E4Q17901611" logid="0000000020" type="traffic" subtype="forward" level="notice" vd="root" eventtime=1573570891 srcip=192.168.56.105 srcname="wazuh.test.local" srcport=63874 srcintf="port1" srcintfrole="lan" dstip=54.97.146.111 dstport=443 dstintf="wan1" dstintfrole="wan" poluuid="3e421d8c-0210-51ea-2e5e-6dd151c37590" sessionid=261713795 proto=6 action="accept" user="WAZUH" authserver="FSSO_TEST_LOCAL" policyid=131 policytype="policy" service="HTTPS" dstcountry="United Kingdom" srccountry="Reserved" trandisp="snat" transip=195.46.111.2 transport=63874 appid=45553 app="Microsoft.Outlook.Office.365" appcat="Email" apprisk="medium" applist="INF-APP-MONITOR" appact="detected" duration=815 sentbyte=13941 rcvdbyte=13429 sentpkt=58 rcvdpkt=63 sentdelta=360 rcvddelta=2189 devtype="Windows PC" devcategory="Windows Device" osname="Windows" osversion="8.1" mastersrcmac="fc:45:96:44:79:c9" srcmac="fc:45:96:44:79:c9" srcserver=1 dstdevtype="Router/NAT Device" dstdevcategory="None" masterdstmac="28:8b:1c:db:7c:48" dstmac="28:8b:1c:db:7c:48" dstserver=0'
**Phase 2: Completed decoding.
decoder: 'fortigate-custom'
devid: 'FG201E4Q17901611'
logid: '0000000020'
type: 'traffic"'
subtype: 'forward'
**Phase 3: Completed filtering (rules).
Rule id: '222000'
Level: '12'
Description: 'Fortigate messages grouped.'
**Alert to be generated.
lf->decoder_info->name: 'fortigate-custom'
ut_decoder_name : 'fortigate-custom'
Best regards.