ClamAV is free opensource antivirus engine designed for detecting Trojans, viruses, malware and other malicious threats. Here in this article we will look at setting up clamAV in Ubuntu 14.04 LTS server, integrate it with Apache ModSecurity Firewall and scan the uploaded file through a web application.
Install ClamAV
Install clamav and clamav-daemon from repo
$ sudo apt-get install clamav clamav-daemon -y
Update clamav malware patterns
$ sudo freshclam
Start clamav-daemon
$ sudo /etc/init.d/clamav-daemon start
Add Anti-virus scanning rules in the ModSecurity
Create a soft link to an Anti-virus rule file. i.e modsecurity_crs_46_av_scanning.conf
# cd /usr/share/modsecurity-crs/activated_rules
# ln -s ../optional_rules/modsecurity_crs_46_av_scanning.conf
Edit configuration in the rule file modsecurity_crs_46_av_scanning.conf
# nano modsecurity_crs_46_av_scanning.conf
Here, edit the location of script in the "@inspectfile" operator.
SecRule FILES_TMPNAMES "@inspectFile /usr/share/modsecurity-crs/util/av-scanning/runav.pl" \
"phase:2,t:none,block,msg:'Virus found in uploaded file',id:'950115',tag:'MALICIOUS_SOFTWARE/VIRUS',tag:'PCI/5.1',severity$
Restart Apache2
# service apache2 restart
Test the configuration by uploading a test virus file through the upload function of an web application hosted in the server. You can use EICAR test file if you dont want to take risk using real malicious files.
Check modsecurity log if ModSecurity is in DetectionOnly mode, else ModSecurity will do the default action set in the Active Mode. i.e 403 Forbidden error display
Note: File upload service might get little bit sluggish due to scanning task by ClamAV.
Install ClamAV
Install clamav and clamav-daemon from repo
$ sudo apt-get install clamav clamav-daemon -y
Update clamav malware patterns
$ sudo freshclam
Start clamav-daemon
$ sudo /etc/init.d/clamav-daemon start
Add Anti-virus scanning rules in the ModSecurity
Create a soft link to an Anti-virus rule file. i.e modsecurity_crs_46_av_scanning.conf
# cd /usr/share/modsecurity-crs/activated_rules
# ln -s ../optional_rules/modsecurity_crs_46_av_scanning.conf
Edit configuration in the rule file modsecurity_crs_46_av_scanning.conf
# nano modsecurity_crs_46_av_scanning.conf
Here, edit the location of script in the "@inspectfile" operator.
SecRule FILES_TMPNAMES "@inspectFile /usr/share/modsecurity-crs/util/av-scanning/runav.pl" \
"phase:2,t:none,block,msg:'Virus found in uploaded file',id:'950115',tag:'MALICIOUS_SOFTWARE/VIRUS',tag:'PCI/5.1',severity$
Restart Apache2
# service apache2 restart
Test the configuration by uploading a test virus file through the upload function of an web application hosted in the server. You can use EICAR test file if you dont want to take risk using real malicious files.
Check modsecurity log if ModSecurity is in DetectionOnly mode, else ModSecurity will do the default action set in the Active Mode. i.e 403 Forbidden error display
Note: File upload service might get little bit sluggish due to scanning task by ClamAV.