Since I've been running OSSEC/Wazuh (from the early days of OSSEC 2.8.x, to Wazuh 2.x and now on Wazuh 3.3.1) I've always been afflicted by apparently bogus, and certainly not very helpful email notifications about "netstat listening ports". I also know that other people have been similarly afflicted because I've seen plenty of chatter about this on both the OSSEC and Wazuh forums. What I haven't seen anywhere yet is a solution?!
Here's an example notification I received today.
----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------
The aspect that makes this notification most unhelpful is that the output of both the before and after netstats is clearly truncated, apparently arbitrarily. If I look at the entry in the alerts.json log that I think relates to this notification and I expand the JSON to make it easier to read, I get the following.
----------------------------------------------------------------------------------------------------------
timestamp => 2018-07-17T13:01:38.61+1000
rule => {"level"=>7, "description"=>"Listened ports status (netstat) changed (new port opened or closed).", "id"=>"533", "firedtimes"=>1, "mail"=>true, "groups"=>["ossec"], "pci_dss"=>["10.2.7", "10.6.1"], "gpg13"=>["10.1"], "gdpr"=>["IV_35.7.d"]}
agent => {"id"=>"000", "name"=>"myossecserver"}
manager => {"name"=>"myossecserver"}
id => 1531796498.174017
previous_output => ossec: output: 'netstat listening ports':
Active Internet connections (only servers)
Proto Local Address Foreign Address State PID/Program name
tcp :::22 :::* LISTEN 1196/sshd
tcp :::55000 :::* LISTEN 1199/nodejs
tcp :::5666 :::* LISTEN 1408/nrpe
tcp :::57657 :::* LISTEN 1705/cvfwd
udp :::123 :::* 1421/ntpd
full_log => ossec: output: 'netstat listening ports':
Active Internet connections (only servers)
Proto Local Address Foreign Address State PID/Program name
tcp :::22 :::* LISTEN 1196/sshd
tcp :::55000 :::* LISTEN 1199/nodejs
tcp :::5666 :::* LISTEN 1408/nrpe
tcp :::57657 :::* LISTEN 1705/cvfwd
udp :::123 :::* 1421/ntpd
decoder => {"name"=>"ossec"}
previous_log => ossec: output: 'netstat listening ports':
Active Internet connections (only servers)
Proto Local Address Foreign Address State PID/Program name
tcp :::22 :::* LISTEN 1196/sshd
tcp :::55000 :::* LISTEN 1199/nodejs
tcp :::5666 :::* LISTEN 1408/nrpe
tcp :::57657 :::* LISTEN 1705/cvfwd
udp :::123 :::* 1421/ntpd
predecoder => {"hostname"=>"myossecserver"}
location => netstat listening ports
----------------------------------------------------------------------------------------------------------
Comparing the values of 'previous_output' and 'previous_log' I see that they are identical. Comparing the values of 'full_log' and 'previous_output' I can see that they differ slightly.
----------------------------------------------------------------------------------------------------------
diff previous_log full_log
16c16
---
----------------------------------------------------------------------------------------------------------
OK, so the alert was triggered for a reason, I'm happy to accept that the alert is not 'bogus'. I'm not going to get into why netstat sometimes shows PID 1883 and sometimes PID 710 in the output (I expect that an instance of smtpd is spawned by Postfix's master process during receipt of an email): that's something that I could presumably filter out in my '<localfile>' definition in ossec.conf (or I could just choose to ignore such alerts). What's really bothering me is the truncation of the output. It seems to have afflicted OSSEC/Wazuh for a long time without any resolution. And the truncation of the output makes the notification totally useless. I'm a busy sysadmin and don't have time to trawl through the alerts.json log every time there is such a notification. I can confirm that the data in Elasticsearch is completely intact i.e. not truncated. I just wondered if someone out there had a solution to this issue? I've seen solutions before which suggest tinkering around with the commands used in the '<localfile>' definition in ossec.conf. But they are not real solutions. The real problem is that the outputs (more specifically the email outputs) are truncated. If I could see the full outputs I could easily see that TCP 25 was being bound to a different process, I'd see what was going on and immediately disregard the event as "of no concern". If I was getting too many of these I could filter out TCP 25 in the command definition, that's not a problem for a sysadmin to deal with, but the truncation of the output means the alert is just irritating and unhelpful.
Simon