Hi Christian,
I double checked the "ossec.log" file for any permissions related errors but couldn't find any. So we can safely assume that the permissions are set correctly.
I repeated the same test but with a different rule file, just as what you did, and I chose "0095-sshd_rules.xml". So I excluded it in ossec.conf as you can see below:
<!-- Default ruleset -->
<decoder_dir>ruleset/decoders</decoder_dir>
<rule_dir>ruleset/rules</rule_dir>
<rule_exclude>0215-policy_rules.xml</rule_exclude>
<rule_exclude>0630-nextcloud_rules.xml</rule_exclude>
<rule_exclude>0095-sshd_rules.xml</rule_exclude>
<list>etc/lists/audit-keys</list>
<list>etc/lists/amazon/aws-eventnames</list>
<list>etc/lists/security-eventchannel</list>
And I copied the rule file, without changing anything, to /var/ossec/etc/rules/ and set the permissions appropriately as you see below:
ll /var/ossec/etc/rules/
total 40
drwxrwx--- 2 root ossec 4096 Apr 13 19:55 ./
drwxrwx--- 7 ossec ossec 4096 Apr 13 20:19 ../
-rw-rw---- 1 ossec ossec 1359 Apr 13 19:55 local_rules.xml
-rw-rw---- 1 ossec ossec 6038 Apr 13 15:13 nextcloud_rules.xml
-rw-rw---- 1 ossec ossec 18203 Apr 13 19:49 sshd_rules.xml
and restarted the Wazuh manager. It seems that it's working as it should. When I try to ssh with a user that doesn't exist, I get security events in Kibana. So that SSH default rules work.
I also tried to overwrite one of the Nextcloud default rules in "local_rules.xml" following the same document you shared but it didn't work.
Here is one of the Nextcloud events I copied from
archive.json file:
{"timestamp":"2022-04-13T20:25:28.452+0200","agent":{"id":"001","name":"nextcloud","ip":"192.168.0.46"},"manager":{"name":"wazuh-worker-01"},"id":"1649874328.115121","cluster":{"name":"wazuh-cluster","node":"wazuh-worker-01"},"full_log":"{\"reqId\":\"rbQ93RGvSQTbv4YMXYLp\",\"level\":1,\"time\":\"2022-04-13T20:25:27+02:00\",\"remoteAddr\":\"10.100.100.25\",\"user\":\"john\",\"app\":\"admin_audit\",\"method\":\"GET\",\"url\":\"/nextcloud/remote.php/dav/files/john/myfiles/image.png\",\"message\":\"File accessed: \\\"/myfiles/image.png\\\"\",\"userAgent\":\"Mozilla/5.0 (Macintosh) mirall/2.6.4stable (build 20200303) (Nextcloud)\",\"version\":\"22.2.3.1\",\"@source\":\"NextCloud\"}","decoder":{"name":"json"},"data":{"url":"/nextcloud/remote.php/dav/files/john/myfiles/image.png","reqId":"rbQ93RGvSQTbv4YMXYLp","level":"1","time":"2022-04-13T20:25:27+02:00","remoteAddr":"10.100.100.25","user":"john","app":"admin_audit","method":"GET","message":"File accessed: \"/myfiles/image.png\"","userAgent":"Mozilla/5.0 (Macintosh) mirall/2.6.4stable (build 20200303) (Nextcloud)","version":"22.2.3.1","@source":"NextCloud"},"location":"/var/log/nextcloud/audit.log"}
Using wazuh-logtest tool, I got this:
New session was created with token "82c989fc"
**Phase 1: Completed pre-decoding.
full event: '{"timestamp":"2022-04-13T20:25:28.452+0200","agent":{"id":"001","name":"nextcloud","ip":"192.168.0.46"},"manager":{"name":"wazuh-worker-01"},"id":"1649874328.115121","cluster":{"name":"wazuh-cluster","node":"wazuh-worker-01"},"full_log":"{\"reqId\":\"rbQ93RGvSQTbv4YMXYLp\",\"level\":1,\"time\":\"2022-04-13T20:25:27+02:00\",\"remoteAddr\":\"10.100.100.25\",\"user\":\"john\",\"app\":\"admin_audit\",\"method\":\"GET\",\"url\":\"/nextcloud/remote.php/dav/files/john/myfiles/image.png\",\"message\":\"File accessed: \\\"/myfiles/image.png\\\"\",\"userAgent\":\"Mozilla/5.0 (Macintosh) mirall/2.6.4stable (build 20200303) (Nextcloud)\",\"version\":\"22.2.3.1\",\"@source\":\"NextCloud\"}","decoder":{"name":"json"},"data":{"url":"/nextcloud/remote.php/dav/files/john/myfiles/image.png","reqId":"rbQ93RGvSQTbv4YMXYLp","level":"1","time":"2022-04-13T20:25:27+02:00","remoteAddr":"10.100.100.25","user":"john","app":"admin_audit","method":"GET","message":"File accessed: \"/myfiles/image.png\"","userAgent":"Mozilla/5.0 (Macintosh) mirall/2.6.4stable (build 20200303) (Nextcloud)","version":"22.2.3.1","@source":"NextCloud"},"location":"/var/log/nextcloud/audit.log"}'
**Phase 2: Completed decoding.
name: 'json'
agent.id: '001'
agent.ip: '192.168.0.46'
agent.name: 'nextcloud'
cluster.name: 'wazuh-cluster'
cluster.node: 'wazuh-worker-01'
data.@source: 'NextCloud'
data.app: 'admin_audit'
data.level: '1'
data.message: 'File accessed: "/myfiles/image.png"'
data.method: 'GET'
data.remoteAddr: '10.100.100.25'
data.reqId: 'rbQ93RGvSQTbv4YMXYLp'
data.time: '2022-04-13T20:25:27+02:00'
data.url: '/nextcloud/remote.php/dav/files/john/myfiles/image.png'
data.user: 'john'
data.userAgent: 'Mozilla/5.0 (Macintosh) mirall/2.6.4stable (build 20200303) (Nextcloud)'
data.version: '22.2.3.1'
decoder.name: 'json'
full_log: '{"reqId":"rbQ93RGvSQTbv4YMXYLp","level":1,"time":"2022-04-13T20:25:27+02:00","remoteAddr":"10.100.100.25","user":"john","app":"admin_audit","method":"GET","url":"/nextcloud/remote.php/dav/files/john/myfiles/image.png","message":"File accessed: \"/myfiles/image.png\"","userAgent":"Mozilla/5.0 (Macintosh) mirall/2.6.4stable (build 20200303) (Nextcloud)","version":"22.2.3.1","@source":"NextCloud"}'
id: '1649874328.115121'
location: '/var/log/nextcloud/audit.log'
manager.name: 'wazuh-worker-01'
timestamp: '2022-04-13T20:25:28.452+0200'
I also suspected that it could be related to the reserved rules IDs. So I already changed them and tested but unfortunately, no joy. Here is the rule file:
vi etc/rules/nextcloud_rules.xml
<group name="json,nextcloud,">
<rule id="110000" level="0">
<decoded_as>json</decoded_as>
<field name="@source">NextCloud</field>
<description>NextCloud messages grouped.</description>
<options>no_full_log</options>
</rule>
<rule id="110001" level="0">
<decoded_as>nextcloud</decoded_as>
<description>NextCloud messages grouped.</description>
<options>no_full_log</options>
</rule>
<rule id="110002" level="6">
<if_sid>110000,110001</if_sid>
<match>Login successful: </match>
<description>NextCloud authentication successful.</description>
<group>authentication_success,pci_dss_10.2.4,pci_dss_10.2.5,gdpr_IV_35.7.d,gdpr_IV_32.2,hipaa_164.312.b,nist_800_53_AU.14,nist_800_53_AC.7,tsc_CC6.1,tsc_CC6.8,tsc_CC7.2,tsc_CC7.3,</group>
<options>no_full_log</options>
</rule>
<rule id="110003" level="6">
<if_sid>110000,110001</if_sid>
<match>Login failed: </match>
<description>NextCloud authentication failed.</description>
<group>authentication_failed,pci_dss_10.2.4,pci_dss_10.2.5,gdpr_IV_35.7.d,gdpr_IV_32.2,hipaa_164.312.b,nist_800_53_AU.14,nist_800_53_AC.7,tsc_CC6.1,tsc_CC6.8,tsc_CC7.2,tsc_CC7.3,</group>
<options>no_full_log</options>
</rule>
<rule id="110004" level="6">
<if_sid>110000,110001</if_sid>
<match>User created: </match>
<description>NextCloud account created.</description>
<options>no_full_log</options>
</rule>
<rule id="110005" level="6">
<if_sid>110000,110001</if_sid>
<match>File accessed: </match>
<description>NextCloud file accessed.</description>
<group>pci_dss_10.2.4,pci_dss_10.2.5,gdpr_IV_35.7.d,gdpr_IV_32.2,hipaa_164.312.b,nist_800_53_AU.14,nist_800_53_AC.7,tsc_CC6.1,tsc_CC6.8,tsc_CC7.2,tsc_CC7.3,</group>
<options>no_full_log</options>
</rule>
</group>
I'm not sure what's special about the Nextcloud default rules.
Regards and thanks again for all your help.