I am struggling to write a custom wazuh rule in order to send alert when specific commands are written (powershell and bash).
Can anyone help me?
Thanks in advance!
I am struggling to write a custom wazuh rule in order to send alert when specific commands are written (powershell and bash).
Can anyone help me?
Thanks in advance!
Linux systems have a powerful auditing facility called auditd which can give a very detailed accounting of actions and changes in a system, but by default, no auditd rules are active so we tend to miss out on this detailed history.
Let’s follow the next steps to create the custom rule:
/etc/audit/rules.d/audit.rules
echo "-a exit,always -F auid=1000 -F egid!=994 -F auid!=-1 -F arch=b32 -S execve -k audit-wazuh-c" >> /etc/audit/rules.d/audit.rules
echo "-a exit,always -F auid=1000 -F egid!=994 -F auid!=-1 -F arch=b64 -S execve -k audit-wazuh-c" >> /etc/audit/rules.d/audit.rules
Where auid=1000
represents the user ID. If unsure, you may verify this value by running: grep centos /etc/passwd
(replacing centos if you have a different user name).
auditctl -R /etc/audit/rules.d/audit.rules
auditctl -l
Now, we are going to create a list of command that Wazuh will watch for:
/var/ossec/etc/lists/suspicious-programs
with this content:ncat:
nc:
tcpdump:
ping:
<ruleset>
section of ossec configuration in /var/ossec/etc/ossec.conf
:<ruleset>
<list>etc/lists/suspicious-programs</list>
/var/ossec/etc/rules/local_rules.xml
on the Wazuh Manager.<group name="audit">
<rule id="100200" level="8">
<if_sid>80792</if_sid>
<list field="audit.command" lookup="match_key">etc/lists/suspicious-programs</list>
<description>Audit: Suspicious Command: $(audit.exe)</description>
<group>audit_command,</group>
</rule>
</group>
/var/ossec/bin/ossec-makelists
Now if you run, for example, tcpdump –-version
the rule 100200
will match and an alert will be triggered.
You can see more info here.