{"id":13747,"date":"2022-08-29T09:26:19","date_gmt":"2022-08-29T06:26:19","guid":{"rendered":"https:\/\/kifarunix.com\/?p=13747"},"modified":"2024-03-09T20:55:09","modified_gmt":"2024-03-09T17:55:09","slug":"send-alert-when-clamav-finds-infected-files-on-linux-systems","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/send-alert-when-clamav-finds-infected-files-on-linux-systems\/","title":{"rendered":"Send Alert When ClamAV Finds Infected Files on Linux Systems"},"content":{"rendered":"\n

In this tutorial, you will learn how to send alert when ClamAV finds infected files on Linux systems. ClamAV<\/a> is an opensource antivirus engine for detecting trojans, viruses, malware & other malicious threats. It is a good idea to sent alerts whenever a malicious file is detected on the system. This enables you to take actions of analyzing the files and probably removing them from the system based on the results of the analysis.<\/p>\n\n\n\n

Send Alert When ClamAV Finds Infected Files on Linux Systems<\/h2>\n\n\n\n

In our previous guides on ClamAV<\/a>, we learnt how to perform only one time scanning of the systems using ClamAV clamscan command line tool.<\/p>\n\n\n\n

We have also seen how to configure ClamAV to send scan events to ELK Stack Kibana for visualization<\/a>.<\/p>\n\n\n\n

In this setup, therefore, we will configure ELK stack to sent alerts using ElastAlert to analysts or system admins via the email whenever it receives events from ClamAV with evidence of infected files found on the systems rather than sending emails directly from the system where ClamAV is installed.<\/p>\n\n\n\n

Send ClamAV Alerts using ElastAlert<\/h3>\n\n\n\n

To proceed with this kind of alerting, you need to have already setup ELK stack and already processing ClamAV events well. Check the guide below on how to configure ClamAV to send scan events to ELK Stack Kibana for visualization.<\/p>\n\n\n\n

Visualize ClamAV Scan Logs on ELK Stack Kibana<\/a><\/p>\n\n\n\n

Next, install ElastAlert on ELK Stack. You can check our previous guide on how to install ElastAlert.<\/p>\n\n\n\n

Install ElastAlert on Linux<\/a><\/p>\n\n\n\n

If you are have Python 3.9, install ElastAlert2;<\/p>\n\n\n\n

pip install elastalert2<\/code><\/pre>\n\n\n\n

Configure your system to be able to send emails. You can consult our tutorials on using Postfix with Gmail SMTP.<\/p>\n\n\n\n

Install and Configure Postfix Gmail SMTP relay<\/a><\/p>\n\n\n\n

Assuming you already installed ElastAlert, it is then time to configure it to send ClamAV alerts whenever an infected file is found on the scan report.<\/p>\n\n\n\n

Remember in our guide on how to visualize ClamAV alerts on ELK<\/a>, one could filter ClamAV events with infected files using the filter;<\/p>\n\n\n\n

infected_files_num is not 0<\/strong><\/code><\/pre>\n\n\n\n

Or<\/p>\n\n\n\n

infected_files: exists<\/strong><\/code><\/pre>\n\n\n\n

Details for the infected files found event;<\/p>\n\n\n\n

\"\"<\/figure><\/a><\/div>\n\n\n\n

Based on the fields available above, we will configure ElastAlert to send an email alert when a match is found.<\/p>\n\n\n\n

Make a copy of the ElastAlert configuration file and update it for ClamAV alerts. This is our sample configuration<\/p>\n\n\n\n

cp \/opt\/elastalert\/{config,-clamav}.yaml<\/code><\/pre>\n\n\n\n

If you installed via PIP, you can download example configuration file and rules from Github repository<\/a>.<\/p>\n\n\n\n

vim \/opt\/elastalert\/config-clamav.yaml<\/code><\/pre>\n\n\n\n
rules_folder: example_rules\nrun_every:\n  minutes: 5\nbuffer_time:\n  minutes: 15\nes_host: 192.168.58.22\nes_port: 9200\nwriteback_index: elastalert_status\nwriteback_alias: elastalert_alerts\nalert_time_limit:\n  days: 2\n<\/code><\/pre>\n\n\n\n