{"id":132,"date":"2009-05-11T09:24:08","date_gmt":"2009-05-11T07:24:08","guid":{"rendered":"http:\/\/www.shukko.com\/x3\/?p=132"},"modified":"2009-05-11T09:24:08","modified_gmt":"2009-05-11T07:24:08","slug":"howto-proftpd-antivirus-using-clamav","status":"publish","type":"post","link":"https:\/\/www.shukko.com\/x3\/2009\/05\/11\/howto-proftpd-antivirus-using-clamav\/","title":{"rendered":"HOWTO: ProFTPD Antivirus using CLAMAV"},"content":{"rendered":"<div id=\"post_message_156452\">This howto is about making ProFTPD work with CLAMAV to scan all files uploaded by users using a FTP client.<br \/>\nRecently our customers are having real difficulty with Iframe viruses, Php shells and other kind of windows viruses are also a headache always.<br \/>\nClamAV is already working with exim mail server in our servers for years. Why not make it also scan incoming FTP uploads.This will add more CPU Time to our servers, but preventing users to upload any kind of virus data makes sense.<\/p>\n<p>How will this work? :<br \/>\n-we will add ClamAV support to ProFTPD using <a href=\"http:\/\/www.thrallingpenguin.com\/resources\/mod_clamav.htm\" target=\"_blank\">mod_clamav<\/a> module.<br \/>\n-when a user uploads a file using FTP, ClamAV will scan incoming file after upload finishes.<br \/>\n-if any kind of virus like signature found by ClamAV, uploaded file will be deleted from server, notifying the FTP client.<\/p>\n<p>1- we will need a working ClamAV installation on server before this. I prefer not to tell how to install ClamAV to server this time, because there is already a very handy script called <a href=\"http:\/\/www.directadmin.com\/forum\/showthread.php?t=22587\" target=\"_blank\">update.script<\/a> which can install ClamAV and tons of other stuff. I take portions of this script to automate my process. Thanks to original update.script creator!<\/p>\n<p>If ClamAV is already installed and updating itself regularly please skip this step.<\/p>\n<p>-INSTALL CLAMAV-<\/p>\n<div style=\"margin: 5px 20px 20px;\">\n<div class=\"smallfont\" style=\"margin-bottom: 2px;\">Code:<\/div>\n<pre class=\"alt2\" style=\"border: 1px inset; margin: 0px; padding: 6px; overflow: auto; width: 640px; height: 82px; text-align: left;\" dir=\"ltr\">mkdir \/usr\/local\/updatescript\r\ncd \/usr\/local\/updatescript\r\nwget http:\/\/tools.web4host.net\/update.script\r\nchmod 755 update.script<\/pre>\n<\/div>\n<p>Run it once.<\/p>\n<div style=\"margin: 5px 20px 20px;\">\n<div class=\"smallfont\" style=\"margin-bottom: 2px;\">Code:<\/div>\n<pre class=\"alt2\" style=\"border: 1px inset; margin: 0px; padding: 6px; overflow: auto; width: 640px; height: 34px; text-align: left;\" dir=\"ltr\">.\/update.script<\/pre>\n<\/div>\n<p>Install Clamav<\/p>\n<div style=\"margin: 5px 20px 20px;\">\n<div class=\"smallfont\" style=\"margin-bottom: 2px;\">Code:<\/div>\n<pre class=\"alt2\" style=\"border: 1px inset; margin: 0px; padding: 6px; overflow: auto; width: 640px; height: 34px; text-align: left;\" dir=\"ltr\">.\/update.script CLAMAV<\/pre>\n<\/div>\n<p>Clamav Installation Done!<\/p>\n<p>2- Update ProFTPD with current version. And patch it using mod_clamav for ClamAV usage.<\/p>\n<div style=\"margin: 5px 20px 20px;\">\n<div class=\"smallfont\" style=\"margin-bottom: 2px;\">Code:<\/div>\n<pre class=\"alt2\" style=\"border: 1px inset; margin: 0px; padding: 6px; overflow: auto; width: 640px; height: 82px; text-align: left;\" dir=\"ltr\">cd ~\r\nwget http:\/\/www.serverdirekt.com\/DA\/FTPAV\/ftpantivirus\r\nchmod +x ftpantivirus\r\n.\/ftpantivirus<\/pre>\n<\/div>\n<p>-this script will download ProFTPD, download mod_clamav latest version, patch ProFTPD with mod_clamav, compile and install new ProFTPD package with ClamAV support.<\/p>\n<p>3- We need to edit our clamav.conf file to allow TCPSocket connections to port 3310<\/p>\n<div style=\"margin: 5px 20px 20px;\">\n<div class=\"smallfont\" style=\"margin-bottom: 2px;\">Code:<\/div>\n<pre class=\"alt2\" style=\"border: 1px inset; margin: 0px; padding: 6px; overflow: auto; width: 640px; height: 34px; text-align: left;\" dir=\"ltr\">nano \/etc\/clamd.conf<\/pre>\n<\/div>\n<p>find #TCPSocket 3310 line and comment it out.<br \/>\nfind #TCPAddr 127.0.0.1 line and comment it out.<br \/>\nFinal file will look like this:<\/p>\n<div style=\"margin: 5px 20px 20px;\">\n<div class=\"smallfont\" style=\"margin-bottom: 2px;\">Code:<\/div>\n<pre class=\"alt2\" style=\"border: 1px inset; margin: 0px; padding: 6px; overflow: auto; width: 640px; height: 338px; text-align: left;\" dir=\"ltr\">....................\r\n# Path to a local socket file the daemon will listen on.\r\n# Default: disabled (must be specified by a user)\r\nLocalSocket \/tmp\/clamd\r\n\r\n# Remove stale socket after unclean shutdown.\r\n# Default: no\r\nFixStaleSocket yes\r\n\r\n# TCP port address.\r\n# Default: no\r\nTCPSocket 3310\r\n\r\n# TCP address.\r\n# By default we bind to INADDR_ANY, probably not wise.\r\n# Enable the following to provide some degree of protection\r\n# from the outside world.\r\n# Default: no\r\nTCPAddr 127.0.0.1\r\n....................<\/pre>\n<\/div>\n<p>4- Finally we need to edit proftpd.conf to use our new mod_clamav module.<\/p>\n<div style=\"margin: 5px 20px 20px;\">\n<div class=\"smallfont\" style=\"margin-bottom: 2px;\">Code:<\/div>\n<pre class=\"alt2\" style=\"border: 1px inset; margin: 0px; padding: 6px; overflow: auto; width: 640px; height: 34px; text-align: left;\" dir=\"ltr\">nano \/etc\/proftpd.conf<\/pre>\n<\/div>\n<p>inside &lt;Global&gt;&lt;\/Global&gt; tags at the end add:<\/p>\n<div style=\"margin: 5px 20px 20px;\">\n<div class=\"smallfont\" style=\"margin-bottom: 2px;\">Code:<\/div>\n<pre class=\"alt2\" style=\"border: 1px inset; margin: 0px; padding: 6px; overflow: auto; width: 640px; height: 114px; text-align: left;\" dir=\"ltr\">&lt;IfModule mod_clamav.c&gt;\r\n   ClamAV on\r\n   ClamServer localhost\r\n   ClamPort 3310\r\n   ClamMaxSize 5 Mb\r\n&lt;\/IfModule&gt;<\/pre>\n<\/div>\n<p>we do not want to scan files bigger than 5 Mb to save some CPU time.<\/p>\n<p>5- Restart ClamAv and ProFTPD to test this out!<\/p>\n<div style=\"margin: 5px 20px 20px;\">\n<div class=\"smallfont\" style=\"margin-bottom: 2px;\">Code:<\/div>\n<pre class=\"alt2\" style=\"border: 1px inset; margin: 0px; padding: 6px; overflow: auto; width: 640px; height: 50px; text-align: left;\" dir=\"ltr\">service clamd restart\r\nservice proftpd restart<\/pre>\n<\/div>\n<p>6- Finally go to <a href=\"http:\/\/www.eicar.org\/anti_virus_test_file.htm\" target=\"_blank\">http:\/\/www.eicar.org\/anti_virus_test_file.htm<\/a> to download eicar test virus and upload it to your ftp server with your favorite FTP client.<\/p>\n<p>If you see something like that on your FTP client logs, well done!<\/p>\n<div style=\"margin: 5px 20px 20px;\">\n<div class=\"smallfont\" style=\"margin-bottom: 2px;\">Code:<\/div>\n<pre class=\"alt2\" style=\"border: 1px inset; margin: 0px; padding: 6px; overflow: auto; width: 640px; height: 82px; text-align: left;\" dir=\"ltr\">Command:\tSTOR eicar_com.zip\r\nResponse:\t150 Opening BINARY mode data connection for eicar_com.zip\r\nResponse:\t550 Virus Detected and Removed: Eicar-Test-Signature\r\nStatus:\tRetrieving directory listing...<\/pre>\n<\/div>\n<p>7- IF something goes wrong and your ClamAV enabled ftp server is not scanning files as it should.<\/p>\n<p>first check ProFTPD if mod_clamav is activated<\/p>\n<div style=\"margin: 5px 20px 20px;\">\n<div class=\"smallfont\" style=\"margin-bottom: 2px;\">Code:<\/div>\n<pre class=\"alt2\" style=\"border: 1px inset; margin: 0px; padding: 6px; overflow: auto; width: 640px; height: 34px; text-align: left;\" dir=\"ltr\">proftpd -vv<\/pre>\n<\/div>\n<p>If you see mod_clamav.c under Loaded modules:<br \/>\nyou have mod_clamav ready.<\/p>\n<p>For further investigation we can run our ProFTPD server in debug mode to see what&#8217;s going on:<\/p>\n<div style=\"margin: 5px 20px 20px;\">\n<div class=\"smallfont\" style=\"margin-bottom: 2px;\">Code:<\/div>\n<pre class=\"alt2\" style=\"border: 1px inset; margin: 0px; padding: 6px; overflow: auto; width: 640px; height: 50px; text-align: left;\" dir=\"ltr\">service proftpd stop\r\nproftpd -n -d 10<\/pre>\n<\/div>\n<p>Try to login and upload eicar test virus to your FTP now, you will see what&#8217;s going on under the hood in good detail&#8230;<\/p>\n<p>FINAL NOTE: I tested this only on Centos 5.x i386 and X86_64 servers. So there is no guarantee that it will work on any other O\/S.<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>This howto is about making ProFTPD work with CLAMAV to scan all files uploaded by users using a FTP client. Recently our customers are having real difficulty with Iframe viruses, Php shells and other kind of windows viruses are also a headache always. ClamAV is already working with exim mail server in our servers for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-132","post","type-post","status-publish","format-standard","hentry","category-kategerisiz"],"_links":{"self":[{"href":"https:\/\/www.shukko.com\/x3\/wp-json\/wp\/v2\/posts\/132","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shukko.com\/x3\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shukko.com\/x3\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shukko.com\/x3\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shukko.com\/x3\/wp-json\/wp\/v2\/comments?post=132"}],"version-history":[{"count":1,"href":"https:\/\/www.shukko.com\/x3\/wp-json\/wp\/v2\/posts\/132\/revisions"}],"predecessor-version":[{"id":133,"href":"https:\/\/www.shukko.com\/x3\/wp-json\/wp\/v2\/posts\/132\/revisions\/133"}],"wp:attachment":[{"href":"https:\/\/www.shukko.com\/x3\/wp-json\/wp\/v2\/media?parent=132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shukko.com\/x3\/wp-json\/wp\/v2\/categories?post=132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shukko.com\/x3\/wp-json\/wp\/v2\/tags?post=132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}