Hello cyprien,
Regarding the firewall-drop active response, take in mind that the command’s expect option is deprecated since 4.2. https://documentation.wazuh.com/current/user-manual/reference/ossec-conf/commands.html?highlight=command#expect.
I have tested this active response command in my local environment and it seems it works correctly if we use the following configuration:
<command>
<name>firewall-drop</name>
<executable>firewall-drop</executable>
<timeout_allowed>yes</timeout_allowed>
</command>
....
<active-response>
<command>firewall-drop</command>
<location>all</location>
<rules_id>5710,5712,5716,100100</rules_id>
<timeout>1800</timeout>
</active-response>
Check this configuration, and in case this does not work, please share your logs with execd and remoted debug activated.
Regarding your log coming from /var/log/auth.log, please activate temporally the logall option in your configuration, restart your manager, and ensure you are getting the related log.
If that is not the case, activate logcollector.debug=2 in your local_internal_options.confand share with us your ossec.log
If you have any doubt do not hesitate to ask
First, regarding the path shown in your rule:
** Alert 1642580325.8320: mail - local,syslog,sshd,invalid_login,authentication_failed,pci_dss_10.2.4,pci_dss_10.2.5,pci_dss_10.6.1,gpg13_7.1,gdpr_IV_35.7.d,gdpr_IV_32.2,hipaa_164.312.b,nist_800_53_AU.14,nist_800_53_AC.7,nist_800_53_AU.6,tsc_CC6.1,tsc_CC6.8,tsc_CC7.2,tsc_CC7.3,
2022 Jan 19 08:18:45 (cible) 192.168.1.20->/var/log/auth.log
Checking your logs, the event shown in your /var/log/syslog file seems not to be related to your ssh alerts:
We are expecting Jan 19 08:18:45 cible sshd[1001]: Invalid user user from 192.168.x.x port 42444 and logcollector is readingJan 19 08:24:02 wazuh-manager filebeat[110]: 2022-01-19T08:24:02.
Taking that into account, follow these steps:
- Activate the logall option
<ossec_config>
<global>
...
<logall>yes</logall>
...
- Set the following content in your /var/ossec/etc/local_internal_options.conf
logcollector.debug=2
logcollector.sample_log_length=500
- Restart your manager
- Perform an ssh connection with an invalid user
- Check the content of your /var/ossec/logs/archives/archives.log
You should have gotten something similar to
2022 Jan 19 12:34:53 ubuntu-bionic->/var/log/auth.log Jan 19 12:34:52 ubuntu-bionic sshd[13919]: Invalid user invalid-user from 172.17.1.1 port 44298
- Check if the file specified in archives.log has that event
- Check the content of your ossec.log. You should get something similar to
2022/01/19 12:34:53 wazuh-logcollector[12963] read_syslog.c:104 at read_syslog(): DEBUG: Reading syslog message: 'Jan 19 12:34:52 ubuntu-bionic sshd[13919]: Invalid user invalid-user from 172.17.1.1 port 44298'
...
2022/01/19 12:34:53 wazuh-logcollector[12963] read_syslog.c:148 at read_syslog(): DEBUG: Read 2 lines from /var/log/auth.log
- Do the same by inserting your event in a custom file.
Send back your results. In case of showing in archives/alerts/ossec.log a file in which the event has not occurred, please send back any related logs and your OS and we will research this issue.
About, your AR configuration, my fault. The location value all only affects agents. So, yes, you should use something similar to the solution presented in https://groups.google.com/g/wazuh/c/pgfBgn4WaNQ/m/uWGDPfSFAAAJ.
However, as you said, is not recommended to use level as an AR condition for a firewall-drop command due to this required srcip field. Maybe the best approach is to use your original configuration, but using local as location
<active-response>
<command>firewall-drop</command>
<location>local</location>
<rules_id>5710,5712,5716,100100</rules_id>
<timeout>1800</timeout>
</active-response>
Restart your manager, and in case it does not work, please send back:
- active-response.log
- ossec.log
- alert.log
Also, to format text block as code, I use the extension Markdown Here.
Activate the logall option
Set the following content in your /var/ossec/etc/local_internal_options.conf /var/ossec/etc/local_internal_options.conf /var/ossec/etc/local_internal_options.conf
/var/ossec/logs/archives/archives.log2022 Jan 19 16:56:36 (cible) 192.168.1.20->/var/log/auth.log Jan 19 16:56:34 cible sshd[1936]: Invalid user user from 192.168.1.17 port 53072
Now, with the alert created in the custom file (echo “Nov 8 11:16:26 centos-manager1 sshd[20046]: test from 172.17.1.1 port 39588” >> /tmp/testing.log)
/var/ossec/logs/archives/archives.log :
2022 Jan 19 17:08:32 centos-manager1->/tmp/testing.log Nov 8 11:16:26 centos-manager1 sshd[20046]: test from 172.17.1.1 port 39588
2022/01/19 17:08:32 wazuh-logcollector[17041] read_syslog.c:104 at read_syslog(): DEBUG: Reading syslog message: 'Nov 8 11:16:26 centos-manager1 sshd[20046]: test from 17
2.17.1.1 port 39588'
2022/01/19 17:08:32 wazuh-logcollector[17041] read_syslog.c:148 at read_syslog(): DEBUG: Read 1 lines from /tmp/testing.log
<active-response>
<command>firewall-drop</command>
<location>local</location>
<rules_id>5710,5712,5716,100100</rules_id>
<timeout>1800</timeout>
</active-response>
root@wazuh-manager:~# tail -f /var/ossec/logs/archives/archives.log
reboot system boot 5.4.128-1-pve Thu Jan 13 15:40 - 17:10 (01:30)
root tty1 Wed Jan 12 08:25 - down (08:37)
reboot system boot 5.4.128-1-pve Wed Jan 12 08:25 - 17:03 (08:38)
root tty1 Tue Jan 11 09:15 - down (07:51)
reboot system boot 5.4.128-1-pve Tue Jan 11 09:15 - 17:06 (07:51)
wtmp begins Tue Jan 11 09:15:10 2022
2022 Jan 20 08:06:29 wazuh-manager->/var/log/syslog Jan 20 08:06:28 wazuh-manager filebeat[110]: 2022-01-20T08:06:28.553Z#011INFO#011[monitoring]#011log/log.go:184#011Non-zero metrics in the last 30s#011{"monitoring": {"metrics": {"beat":{"cgroup":{"memory":{"mem":{"usage":{"bytes":-36864}}}},"cpu":{"system":{"ticks":760,"time":{"ms":3}},"total":{"ticks":2360,"time":{"ms":36},"value":2360},"user":{"ticks":1600,"time":{"ms":33}}},"handles":{"limit":{"hard":524288,"soft":1024},"open":13},"info":{"ephemeral_id":"8f585e8d-2f19-4096-b9aa-6d6ede58b979","uptime":{"ms":1413468},"version":"8.0.0-alpha2"},"memstats":{"gc_next":12459984,"memory_alloc":6517600,"memory_total":269517000,"rss":87449600},"runtime":{"goroutines":168}},"filebeat":{"events":{"added":1,"done":1},"harvester":{"open_files":3,"running":3}},"libbeat":{"config":{"module":{"running":4},"scans":2},"output":{"events":{"acked":1,"active":0,"batches":1,"total":1},"read":{"bytes":6},"write":{"bytes":996}},"pipeline":{"clients":29,"events":{"active":0,"published":1,"total":1},"queue":{"acked":1}}},"registrar":{"states":{"current":14,"update":1},"writes":{"success":1,"total":1}},"system":{"load":{"1":1.25,"15":1.43,"5":1.32,"norm":{"1":0.3125,"15":0.3575,"5":0.33}}}}}}
2022 Jan 20 08:06:55 (cible) 192.168.1.20->/var/log/auth.log Jan 20 08:06:54 cible sshd[992]: Connection closed by invalid user user 192.168.x.x port 58816 [preauth]
2022 Jan 20 08:06:56 (cible) 192.168.1.20->/var/log/auth.log Jan 20 08:06:54 cible sshd[994]: Invalid user user from 192.168.x.x port 59172
2022 Jan 20 08:06:59 wazuh-manager->/var/log/syslog Jan 20 08:06:58 wazuh-manager filebeat[110]: 2022-01-20T08:06:58.553Z#011INFO#011[monitoring]#011log/log.go:184#011Non-zero metrics in the last 30s#011{"monitoring": {"metrics": {"beat":{"cgroup":{"memory":{"mem":{"usage":{"bytes":8192}}}},"cpu":{"system":{"ticks":770,"time":{"ms":9}},"total":{"ticks":2370,"time":{"ms":13},"value":2370},"user":{"ticks":1600,"time":{"ms":4}}},"handles":{"limit":{"hard":524288,"soft":1024},"open":13},"info":{"ephemeral_id":"8f585e8d-2f19-4096-b9aa-6d6ede58b979","uptime":{"ms":1443469},"version":"8.0.0-alpha2"},"memstats":{"gc_next":12459984,"memory_alloc":9044160,"memory_total":272043560,"rss":87449600},"runtime":{"goroutines":168}},"filebeat":{"events":{"added":1,"done":1},"harvester":{"open_files":3,"running":3}},"libbeat":{"config":{"module":{"running":4},"scans":2},"output":{"events":{"acked":1,"active":0,"batches":1,"total":1},"read":{"bytes":6},"write":{"bytes":981}},"pipeline":{"clients":29,"events":{"active":0,"published":1,"total":1},"queue":{"acked":1}}},"registrar":{"states":{"current":14,"update":1},"writes":{"success":1,"total":1}},"system":{"load":{"1":1.11,"15":1.42,"5":1.29,"norm":{"1":0.2775,"15":0.355,"5":0.3225}}}}}}
root@wazuh-manager:~# tail -f /var/ossec/logs/ossec.log
2022/01/20 08:05:42 wazuh-remoted[1809] manager.c:242 at save_controlmsg(): DEBUG: save_controlmsg(): inserting 'Linux |cible |5.4.128-1-pve |#1 SMP PVE 5.4.128-2 (Wed, 18 Aug 2021 16:20:02 +0200) |x86_64 [Debian GNU/Linux|debian: 10 (buster)] - Wazuh v4.2.5 / ab73af41699f13fdd81903b5f23d8d00
1715fb875296f5082db84216d4a850f8 merged.mg
#"_agent_ip":192.168.1.20
'
2022/01/20 08:05:42 wazuh-remoted[1809] manager.c:1058 at lookfor_agent_group(): DEBUG: Agent '010' group is 'default'
2022/01/20 08:05:42 wazuh-remoted[1809] manager.c:1144 at read_controlmsg(): DEBUG: read_controlmsg(): reading 'Linux |cible |5.4.128-1-pve |#1 SMP PVE 5.4.128-2 (Wed, 18 Aug 2021 16:20:02 +0200) |x86_64 [Debian GNU/Linux|debian: 10 (buster)] - Wazuh v4.2.5 / ab73af41699f13fdd81903b5f23d8d00
1715fb875296f5082db84216d4a850f8 merged.mg
#"_agent_ip":192.168.1.20
'
2022/01/20 08:05:43 wazuh-remoted[1809] state.c:59 at rem_write_state(): DEBUG: Updating state file.
2022/01/20 08:05:48 wazuh-remoted[1809] secure.c:314 at rem_keyupdate_main(): DEBUG: Checking for keys file changes.
2022/01/20 08:05:48 wazuh-remoted[1809] state.c:59 at rem_write_state(): DEBUG: Updating state file.
2022/01/20 08:05:48 wazuh-remoted[1809] manager.c:677 at c_files(): DEBUG: Updating shared files sums.
2022/01/20 08:05:48 wazuh-remoted[1809] manager.c:912 at c_files(): DEBUG: End updating shared files sums.
2022/01/20 08:05:52 wazuh-remoted[1809] secure.c:521 at HandleSecureMessage(): DEBUG: TCP socket 11 already in keystore. Updating...
2022/01/20 08:05:52 wazuh-remoted[1809] manager.c:242 at save_controlmsg(): DEBUG: save_controlmsg(): inserting 'Linux |cible |5.4.128-1-pve |#1 SMP PVE 5.4.128-2 (Wed, 18 Aug 2021 16:20:02 +0200) |x86_64 [Debian GNU/Linux|debian: 10 (buster)] - Wazuh v4.2.5 / ab73af41699f13fdd81903b5f23d8d00
1715fb875296f5082db84216d4a850f8 merged.mg
#"_agent_ip":192.168.1.20
root@wazuh-manager:~# tail -f /var/ossec/logs/alerts/alerts.log
Src IP: 192.168.1.17
Jan 20 08:05:42 cible sshd[992]: Failed password for invalid user user from 192.168.x.x port 58816 ssh2
** Alert 1642666016.2126: mail - local,syslog,sshd,invalid_login,authentication_failed,pci_dss_10.2.4,pci_dss_10.2.5,pci_dss_10.6.1,gpg13_7.1,gdpr_IV_35.7.d,gdpr_IV_32.2,hipaa_164.312.b,nist_800_53_AU.14,nist_800_53_AC.7,nist_800_53_AU.6,tsc_CC6.1,tsc_CC6.8,tsc_CC7.2,tsc_CC7.3,
2022 Jan 20 08:06:56 (cible) 192.168.1.20->/var/log/auth.log
Rule: 5710 (level 13) -> 'sshd: Attempt to login using a non-existent user'
Src IP: 192.168.1.17
Src Port: 59172
Jan 20 08:06:54 cible sshd[994]: Invalid user user from 192.168.x.xport 59172
Reviewing your archives.log
2022 Jan 20 08:06:55 (cible) 192.168.1.20->/var/log/auth.log Jan 20 08:06:54 cible sshd[992]: Connection closed by invalid user user 192.168.x.x port 58816 [preauth]
And your alert.log
...
2022 Jan 20 08:06:56 (cible) 192.168.1.20->/var/log/auth.log
Rule: 5710 (level 13) -> 'sshd: Attempt to login using a non-existent user'
Src IP: 192.168.1.17
Src Port: 59172
Jan 20 08:06:54 cible sshd[994]: Invalid user user from 192.168.x.xport 59172
It seems that the event is coming from your agent cible. The file shown in your alerts is relative to the agent in which your alerts occur. Please, if you are generating the failed ssh login attempt in an agent, ensure the event is placed in the agent file /var/log/auth.log. If that is not the case, follow the steps specified in my last message https://groups.google.com/g/wazuh/c/Q-H4oiQRD-c/m/_EZgWbfZAQAJ in your agent and send back your ossec.log
Ok, indeed sorry I send the ssh alert to another agent, not the one located on the wazuh-manager machine. So now I have my ssh alert in /var/log/auth.log !
So I did some tests.
Here is the content of : /var/ossec/etc/rules/local_rules.xml
<group name="local,syslog,sshd,">
<rule id="5710" level="13" overwrite="yes">
<if_sid>5700</if_sid>
<match>illegal user|invalid user</match>
<description>sshd: Attempt to login using a non-existent user</description>
<group>invalid_login,authentication_failed,pci_dss_10.2.4,pci_dss_10.2.5,pci_dss_10.6.1,gpg13_7.1,gdpr_IV_35.7.d,gdpr_IV_32.2,hipaa_164.312.b,nist_800_53_AU.14,nist$
<mitre>
<id>T1110</id>
</mitre>
</rule>
<rule id="100010" level="13">
<match>test</match>
<description>Testing active_response</description>
</rule>
</group>
If I do : echo "Nov 8 11:16:26 centos-manager1 sshd[20046]: test from 172.17.1.1 port 39588" >> /var/log/auth.log
Active response work, and the same for : echo "Nov 8 11:16:26 centos-manager1 sshd[20046]: invalid user from 172.17.1.1 port 39588" >> /var/log/auth.log
but with ssh alert it doesn’t work, the alert received is like this :
** Alert 1642779185.36837: mail - local,syslog,sshd,invalid_login,authentication_failed,pci_dss_10.2.4,pci_dss_10.2.5,pci_dss_10.6.1,gpg13_7.1,gdpr_IV_35.7.d,gdpr_IV_32.2,hipaa_164.312.b,nist_800_53_AU.14,nist_800_53_AC.7,nist_800_53_AU.6,tsc_CC6.1,tsc_CC6.8,tsc_CC7.2,tsc_CC7.3,
2022 Jan 21 15:33:05 wazuh-manager->/var/log/auth.log
Rule: 5710 (level 13) -> 'sshd: Attempt to login using a non-existent user'
Src IP: 192.168.1.17
Src Port: 36752
Jan 21 15:33:05 wazuh-manager sshd[7976]: Invalid user test from 192.168.1.17 port 36752
And if I do: echo "Nov 8 11:16:26 centos-manager1 sshd[20046]: test anUser from 172.17.1.1 port 39588" >> /var/log/auth.log
It doesn’t work ! So this is because of the syntxate of the sent alert, how to fix this?
It looks that now your AR module is working correctly, but there are some troubles with your ruleset. Let’s take a look.
In these situations, I strongly recommend using the wazuh-logtest tool. This will help us to know how the events are decoded:
Using your custom rules we run the wazuh-logtest for all your events:
Nov 8 11:16:26 centos-manager1 sshd[20046]: test from 172.17.1.1 port 39588**Phase 1: Completed pre-decoding.
full event: 'Nov 8 11:16:26 centos-manager1 sshd[20046]: test from 172.17.1.1 port 39588'
timestamp: 'Nov 8 11:16:26'
hostname: 'centos-manager1'
program_name: 'sshd'
**Phase 2: Completed decoding.
name: 'sshd'
**Phase 3: Completed filtering (rules).
id: '100010'
level: '13'
description: 'Testing active_response'
groups: '['local', 'syslog', 'sshd']'
firedtimes: '1'
mail: 'True'
**Alert to be generated.
We can see that your custom rule 100010 has been triggered, however, this will never trigger your firewall-drop AR correctly, due to it is required the decoded srcip value. Also, this maybe is not the best syntax due to this will trigger any event containing the word test, for example:
Jan 24 08:24:56 AR test
**Phase 1: Completed pre-decoding.
full event: 'Jan 24 08:24:56 AR test '
timestamp: 'Jan 24 08:24:56'
hostname: 'AR'
**Phase 2: Completed decoding.
No decoder matched.
**Phase 3: Completed filtering (rules).
id: '100010'
level: '13'
description: 'Testing active_response'
groups: '['local', 'syslog', 'sshd']'
firedtimes: '2'
mail: 'True'
**Alert to be generated.
If this rule is triggered after configuring AR for it, this will be the expected behavior.
2022/01/24 08:58:59 active-response/bin/firewall-drop: {"version":1,"origin":{"name":"node01","module":"wazuh-execd"},"command":"add","parameters":{"extra_args":[],"alert":{"timestamp":"2022-01-24T08:58:59.416+0000","rule":{"level":13,"description":"Testing active_response","id":"100010","firedtimes":1,"mail":true,"groups":["local","syslog","sshd"]},"agent":{"id":"000","name":"centos-manager2"},"manager":{"name":"centos-manager2"},"id":"1643014739.623530","full_log":"test example","decoder":{},"location":"/var/log/secure"},"program":"active-response/bin/firewall-drop"}}
2022/01/24 08:58:59 active-response/bin/firewall-drop: Cannot read 'srcip' from data
Nov 8 11:16:26 centos-manager1 sshd[20046]: invalid user from 172.17.1.1 port 39588**Phase 1: Completed pre-decoding.
full event: 'Nov 8 11:16:26 centos-manager1 sshd[20046]: invalid user from 172.17.1.1 port 39588'
timestamp: 'Nov 8 11:16:26'
hostname: 'centos-manager1'
program_name: 'sshd'
**Phase 2: Completed decoding.
name: 'sshd'
parent: 'sshd'
srcport: '39588'
**Phase 3: Completed filtering (rules).
id: '5710'
level: '13'
description: 'sshd: Attempt to login using a non-existent user'
groups: '['local', 'syslog', 'sshd', 'invalid_login', 'authentication_failed', 'nist$']'
firedtimes: '1'
If we use this event, 5710 will trigger. However, the event was not the expected due to srcip it is not being decoded (again, this will produce your AR does not work). If we check the event and we compare it with the generated for ssh:
Jan 24 08:24:56 centos-manager2 sshd[8823]: Invalid user invalid-user from 172.17.1.1 port 47916
Nov 8 11:16:26 centos-manager1 sshd[20046]: invalid user from 172.17.1.1 port 39588
The event has not included the invalid-user. If we use the correct syntax:
**Phase 1: Completed pre-decoding.
full event: 'Nov 8 11:16:26 centos-manager1 sshd[20046]: invalid user invalid-user from 172.17.1.1 port 39588'
timestamp: 'Nov 8 11:16:26'
hostname: 'centos-manager1'
program_name: 'sshd'
**Phase 2: Completed decoding.
name: 'sshd'
parent: 'sshd'
srcip: '172.17.1.1'
srcport: '39588'
srcuser: 'invalid-user'
**Phase 3: Completed filtering (rules).
id: '5710'
level: '13'
description: 'sshd: Attempt to login using a non-existent user'
The srcip is correctly decoded, and AR is working.
Also, take in mind that an overwrite rule can not contain if_sid, if_group or if_level https://github.com/wazuh/wazuh/pull/8210. In wazuh 4.3 this will not be allowed.
If you have any doubt about how to overwrite a custom rule with if_sidtaking in mind this limitation, I recommend you this approach https://github.com/wazuh/wazuh/issues/11596#issuecomment-1002630602
Also, I recommend you change the 100010 rule. If you specified what do you expect to alert we can help you with your custom rules.
Let me know if this solves your questions. Send back your logs and outputs if some of the logs are not the expected.
2022-01-24 09:39:00,687 wazuh-logtest[ERROR] ** Wazuh-logtest error when connecting with wazuh-analysisd