Hi ccM
I hope you are well!
Here you can find an example test, I choose a different event because I can test it with the
wazuh-logtest tool, and so it is easier to see how the engine that processes the events works.
Example event
Oct 14 11:12:38 test sudo[355]: zimbra : TTY=unknown ; PWD=/opt/zimbra ; USER=testuser ; COMMAND=/opt/zimbra/libexec/zmmailboxdmgr status
Testing it with wazuh-logtest tool
```
# /var/ossec/bin/wazuh-logtestType one log per line
Oct 14 11:12:38 test sudo[355]: zimbra : TTY=unknown ; PWD=/opt/zimbra ; USER=testuser ; COMMAND=/opt/zimbra/libexec/zmmailboxdmgr status
** Wazuh-Logtest: WARNING: Detected a deprecated field option for rule, same_agent is not longer available.
**Phase 1: Completed pre-decoding.
full event: 'Oct 14 11:12:38 test sudo[355]: zimbra : TTY=unknown ; PWD=/opt/zimbra ; USER=testuser ; COMMAND=/opt/zimbra/libexec/zmmailboxdmgr status'
timestamp: 'Oct 14 11:12:38'
hostname: 'test'
program_name: 'sudo'
**Phase 2: Completed decoding.
name: 'sudo'
parent: 'sudo'
ftscomment: 'First time user executed the sudo command'
command: '/opt/zimbra/libexec/zmmailboxdmgr status'
dstuser: 'testuser'
pwd: '/opt/zimbra'
srcuser: 'zimbra'
tty: 'unknown'
**Phase 3: Completed filtering (rules).
id: '5403'
level: '4' description: 'First time user executed sudo.'
groups: '['syslog', 'sudo']'
firedtimes: '1'
mail: 'False'
mitre.id: '['T1548.003']'
mitre.tactic: '['Privilege Escalation', 'Defense Evasion']'
mitre.technique: '['Sudo and Sudo Caching']'
**Alert to be generated.
```
Next, I have created the custom rule with my example record, in this case I have used the rule id 5403, I have also removed the conditions that we already know that they work, and there is no need to test in this case.
I added the custom rule in `/var/ossec/etc/rules/local_rules.xml`
```
<rule id="100005" level="0">
<if_sid>5403</if_sid>
<list field="user" lookup="match_key">etc/lists/customer_Tenant</list>
<description>Exception RuleID 5403: remove alerts from srcuser in cdb list</description>
</rule>
```
The CDB list looks like following, (var/ossec/etc/lists/customer_Tenant)
```
# cat customer_Tenant command1:
test:
zimbra:
```
Next, change the permissions to have it the same as the other lists.
```
# chmod 660 customer_Tenant
# chown wazuh customer_Tenant
# chgrp wazuh customer_Tenant
```
include the list in the
ossec.conf file.
```
<ruleset>
<!-- User-defined ruleset -->
<list>etc/lists/customer_Tenant</list>
</ruleset>
```
And finally resrtart the mananger, and run the test again, with same event.
```
# /var/ossec/bin/wazuh-logtestType one log per line
Oct 14 11:12:38 test sudo[355]: zimbra : TTY=unknown ; PWD=/opt/zimbra ; USER=testuser ; COMMAND=/opt/zimbra/libexec/zmmailboxdmgr status
**Phase 1: Completed pre-decoding.
full event: 'Oct 14 11:12:38 test sudo[355]: zimbra : TTY=unknown ; PWD=/opt/zimbra ; USER=testuser ; COMMAND=/opt/zimbra/libexec/zmmailboxdmgr status'
timestamp: 'Oct 14 11:12:38'
hostname: 'test'
program_name: 'sudo'
**Phase 2: Completed decoding.
name: 'sudo'
parent: 'sudo'
ftscomment: 'First time user executed the sudo command'
command: '/opt/zimbra/libexec/zmmailboxdmgr status'
dstuser: 'testuser'
pwd: '/opt/zimbra'
srcuser: 'zimbra'
tty: 'unknown'
**Phase 3: Completed filtering (rules).
id: '100005'
level: '0' description: 'Exception RuleID 5403: remove alerts from srcuser in cdb list'
groups: '['local', 'syslog', 'sshd']'
firedtimes: '1'
mail: 'False'
```
As you can see the
cdb list works, using the value of the srcusr field it found the zimbra name inside the list and applied the rule.
here is a name exception, srcuser and user are the same, but what you have to take into account for this case, is that the engine that processes the rules has access to the
srcuser field, that's why the
cdb list works, in the example you did, the engine that processes the rule doesn't have access to the
agent.name field.
On the other hand, the example given by user wazuh is valid, but the problem is that the
location field only indicates the address where the messages come from, in this case all the events that are from eventchannel will not be discriminated, which is not useful for your case.
Another option that occurs to me is to use the hostname, either by defining variables or using cdb list, but I see that not all alerts have it.
I don't see that it is easy to solve it at the rules level, this means that alerts will be generated and can be filtered in the UI.
I hope it helps.