Hello dseira, hope you’re great.
the realtime applied to a file has a strange behaviour; it detects just the first file modification and only if the scheduled scan has been executed.
What behavior are you telling about? do you mean that just the first file defined within the syscheck section works? or just the first changes made to a file?
I did some research and try this workaround:
<directories check_all="yes" realtime="yes">/tmp/testing_first.txt</directories> <directories check_all="yes" realtime="yes">/tmp/testing_second.txt</directories> <directories check_all="yes" realtime="yes">/home/vagrant/sample/</directories>Where we check one directory and two files, and they work. Here you have the alerts generated for both files:
{"timestamp":"2023-08-10T13:54:50.603+0000","rule":{"level":7,"description":"Integrity checksum changed.","id":"550","mitre":{"id":["T1565.001"],"tactic":["Impact"],"technique":["Stored Data Manipulation"]},"firedtimes":1,"mail":false,"groups":["ossec","syscheck","syscheck_entry_modified","syscheck_file"],"pci_dss":["11.5"],"gpg13":["4.11"],"gdpr":["II_5.1.f"],"hipaa":["164.312.c.1","164.312.c.2"],"nist_800_53":["SI.7"],"tsc":["PI1.4","PI1.5","CC6.1","CC6.8","CC7.2","CC7.3"]},"agent":{"id":"000","name":"manager45"},"manager":{"name":"manager45"},"id":"1691675690.666341","full_log":"File '/tmp/testing_first.txt' modified\nMode: realtime\nChanged attributes: size,mtime,md5,sha1,sha256\nSize changed from '0' to '10'\nOld modification time was: '1691675612', now it is '1691675690'\nOld md5sum was: 'd41d8cd98f00b204e9800998ecf8427e'\nNew md5sum is : 'b6fecf2b63f9f85df5f5a906b874140f'\nOld sha1sum was: 'da39a3ee5e6b4b0d3255bfef95601890afd80709'\nNew sha1sum is : 'a339ae83ae734a11cc71fdeb2bb07e92b9d15f9c'\nOld sha256sum was: 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'\nNew sha256sum is : 'd4154204de612e93db39dae3007ce9a0e40dee9b06221ed173a9a09fd4e53a3b'\n","syscheck":{"path":"/tmp/testing_first.txt","mode":"realtime","size_before":"0","size_after":"10","perm_after":"rw-r--r--","uid_after":"0","gid_after":"0","md5_before":"d41d8cd98f00b204e9800998ecf8427e","md5_after":"b6fecf2b63f9f85df5f5a906b874140f","sha1_before":"da39a3ee5e6b4b0d3255bfef95601890afd80709","sha1_after":"a339ae83ae734a11cc71fdeb2bb07e92b9d15f9c","sha256_before":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","sha256_after":"d4154204de612e93db39dae3007ce9a0e40dee9b06221ed173a9a09fd4e53a3b","uname_after":"root","gname_after":"root","mtime_before":"2023-08-10T13:53:32","mtime_after":"2023-08-10T13:54:50","inode_after":393240,"changed_attributes":["size","mtime","md5","sha1","sha256"],"event":"modified"},"decoder":{"name":"syscheck_integrity_changed"},"location":"syscheck"} {"timestamp":"2023-08-10T13:54:57.791+0000","rule":{"level":7,"description":"Integrity checksum changed.","id":"550","mitre":{"id":["T1565.001"],"tactic":["Impact"],"technique":["Stored Data Manipulation"]},"firedtimes":2,"mail":false,"groups":["ossec","syscheck","syscheck_entry_modified","syscheck_file"],"pci_dss":["11.5"],"gpg13":["4.11"],"gdpr":["II_5.1.f"],"hipaa":["164.312.c.1","164.312.c.2"],"nist_800_53":["SI.7"],"tsc":["PI1.4","PI1.5","CC6.1","CC6.8","CC7.2","CC7.3"]},"agent":{"id":"000","name":"manager45"},"manager":{"name":"manager45"},"id":"1691675697.667566","full_log":"File '/tmp/testing_second.txt' modified\nMode: realtime\nChanged attributes: size,mtime,md5,sha1,sha256\nSize changed from '0' to '10'\nOld modification time was: '1691675618', now it is '1691675697'\nOld md5sum was: 'd41d8cd98f00b204e9800998ecf8427e'\nNew md5sum is : '4cd330580da5a88171f30e18fb08d77b'\nOld sha1sum was: 'da39a3ee5e6b4b0d3255bfef95601890afd80709'\nNew sha1sum is : '84a160c8a973024a2dd2ae61808c806810ef23a1'\nOld sha256sum was: 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'\nNew sha256sum is : '33a343f7964af3f9df0b08a671c410ff2c6e749a4c7dfb35f25cd95298ce4632'\n","syscheck":{"path":"/tmp/testing_second.txt","mode":"realtime","size_before":"0","size_after":"10","perm_after":"rw-r--r--","uid_after":"0","gid_after":"0","md5_before":"d41d8cd98f00b204e9800998ecf8427e","md5_after":"4cd330580da5a88171f30e18fb08d77b","sha1_before":"da39a3ee5e6b4b0d3255bfef95601890afd80709","sha1_after":"84a160c8a973024a2dd2ae61808c806810ef23a1","sha256_before":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","sha256_after":"33a343f7964af3f9df0b08a671c410ff2c6e749a4c7dfb35f25cd95298ce4632","uname_after":"root","gname_after":"root","mtime_before":"2023-08-10T13:53:38","mtime_after":"2023-08-10T13:54:57","inode_after":393241,"changed_attributes":["size","mtime","md5","sha1","sha256"],"event":"modified"},"decoder":{"name":"syscheck_integrity_changed"},"location":"syscheck"}Also, more alerts will be generated, not just the first one:
{"timestamp":"2023-08-10T14:10:28.728+0000","rule":{"level":7,"description":"Integrity checksum changed.","id":"550","mitre":{"id":["T1565.001"],"tactic":["Impact"],"technique":["Stored Data Manipulation"]},"firedtimes":2,"mail":false,"groups":["ossec","syscheck","syscheck_entry_modified","syscheck_file"],"pci_dss":["11.5"],"gpg13":["4.11"],"gdpr":["II_5.1.f"],"hipaa":["164.312.c.1","164.312.c.2"],"nist_800_53":["SI.7"],"tsc":["PI1.4","PI1.5","CC6.1","CC6.8","CC7.2","CC7.3"]},"agent":{"id":"000","name":"manager45"},"manager":{"name":"manager45"},"id":"1691676628.670019","full_log":"File '/tmp/testing_first.txt' modified\nMode: realtime\nChanged attributes: size,mtime,md5,sha1,sha256\nSize changed from '10' to '18'\nOld modification time was: '1691675690', now it is '1691676628'\nOld md5sum was: 'b6fecf2b63f9f85df5f5a906b874140f'\nNew md5sum is : 'a6f0a429da49c8e3325442c023e4ea37'\nOld sha1sum was: 'a339ae83ae734a11cc71fdeb2bb07e92b9d15f9c'\nNew sha1sum is : '73e1a89b9017d8bc8ff79164ec3fb1544c19ee5c'\nOld sha256sum was: 'd4154204de612e93db39dae3007ce9a0e40dee9b06221ed173a9a09fd4e53a3b'\nNew sha256sum is : '25cfecba10c3fc6a1b81763b2c36556454c6ef2b86ca674b1905e9dbb0d084d0'\n","syscheck":{"path":"/tmp/testing_first.txt","mode":"realtime","size_before":"10","size_after":"18","perm_after":"rw-r--r--","uid_after":"0","gid_after":"0","md5_before":"b6fecf2b63f9f85df5f5a906b874140f","md5_after":"a6f0a429da49c8e3325442c023e4ea37","sha1_before":"a339ae83ae734a11cc71fdeb2bb07e92b9d15f9c","sha1_after":"73e1a89b9017d8bc8ff79164ec3fb1544c19ee5c","sha256_before":"d4154204de612e93db39dae3007ce9a0e40dee9b06221ed173a9a09fd4e53a3b","sha256_after":"25cfecba10c3fc6a1b81763b2c36556454c6ef2b86ca674b1905e9dbb0d084d0","uname_after":"root","gname_after":"root","mtime_before":"2023-08-10T13:54:50","mtime_after":"2023-08-10T14:10:28","inode_after":393240,"changed_attributes":["size","mtime","md5","sha1","sha256"],"event":"modified"},"decoder":{"name":"syscheck_integrity_changed"},"location":"syscheck"} {"timestamp":"2023-08-10T14:11:10.502+0000","rule":{"level":7,"description":"Integrity checksum changed.","id":"550","mitre":{"id":["T1565.001"],"tactic":["Impact"],"technique":["Stored Data Manipulation"]},"firedtimes":3,"mail":false,"groups":["ossec","syscheck","syscheck_entry_modified","syscheck_file"],"pci_dss":["11.5"],"gpg13":["4.11"],"gdpr":["II_5.1.f"],"hipaa":["164.312.c.1","164.312.c.2"],"nist_800_53":["SI.7"],"tsc":["PI1.4","PI1.5","CC6.1","CC6.8","CC7.2","CC7.3"]},"agent":{"id":"000","name":"manager45"},"manager":{"name":"manager45"},"id":"1691676670.671245","full_log":"File '/tmp/testing_first.txt' modified\nMode: realtime\nChanged attributes: size,mtime,md5,sha1,sha256\nSize changed from '18' to '26'\nOld modification time was: '1691676628', now it is '1691676670'\nOld md5sum was: 'a6f0a429da49c8e3325442c023e4ea37'\nNew md5sum is : '76d2092a502f5db95a8e71668d0c92f9'\nOld sha1sum was: '73e1a89b9017d8bc8ff79164ec3fb1544c19ee5c'\nNew sha1sum is : 'c269909ce4fab248cefaf6e76d7b813ddddb901c'\nOld sha256sum was: '25cfecba10c3fc6a1b81763b2c36556454c6ef2b86ca674b1905e9dbb0d084d0'\nNew sha256sum is : '862a28a24f3874ce017f98a4f8ee3b511dd1b59118ea907b5af0e22e60e2f6f3'\n","syscheck":{"path":"/tmp/testing_first.txt","mode":"realtime","size_before":"18","size_after":"26","perm_after":"rw-r--r--","uid_after":"0","gid_after":"0","md5_before":"a6f0a429da49c8e3325442c023e4ea37","md5_after":"76d2092a502f5db95a8e71668d0c92f9","sha1_before":"73e1a89b9017d8bc8ff79164ec3fb1544c19ee5c","sha1_after":"c269909ce4fab248cefaf6e76d7b813ddddb901c","sha256_before":"25cfecba10c3fc6a1b81763b2c36556454c6ef2b86ca674b1905e9dbb0d084d0","sha256_after":"862a28a24f3874ce017f98a4f8ee3b511dd1b59118ea907b5af0e22e60e2f6f3","uname_after":"root","gname_after":"root","mtime_before":"2023-08-10T14:10:28","mtime_after":"2023-08-10T14:11:10","inode_after":393240,"changed_attributes":["size","mtime","md5","sha1","sha256"],"event":"modified"},"decoder":{"name":"syscheck_integrity_changed"},"location":"syscheck"}If you are not able to see the changes alert within your /var/ossec/logs/alerts/alerts.json, please share your ossec.conf‘s syscheck section (avoid sharing sensitive info) and the logs/alerts related to syscheck.
You can check in realtime the changes alerts by using tail -f /var/ossec/logs/alerts/alerts.json | grep syscheck
To gather the logs/alerts related to syscheck, you can do the same but using cat:
cat /var/ossec/logs/alerts/alerts.json | grep syscheck
cat /var/ossec/logs/ossec.log | grep syscheck
About the documentation, as you said, it should not work for files. I will make some research about this and reach to you with any update about that.
Hope this helps you,
Luis.
Hello again, dseira.
How did you add the string? If you use vi/vim it won’t work because the inotify watch is deleted.
If that not the case, how do you add the string? If it still not working, please enable the syscheck debug mode by setting the syscheck.debug to 2 in your /var/ossec/etc/internal_options.conf and then restart the manager. Then, add the string using echo "#test" >> /etc/login.defs and obtain the logs with cat /var/ossec/logs/ossec.log | grep syscheck >> syscheck.log so you can attach them in case we need to research them.
If you want to check with vi/vim anyways, you should do a workaround like this:
You should be able to use restrict to limit the checks within the directories in realtime, and then add another one for the schedules ones.
Here you have the section that describes this field: https://documentation.wazuh.com/current/user-manual/reference/ossec-conf/syscheck.html#directories