Posted by: Mangesh_Linux_Administrator | November 29, 2010

scan and stop uploading infected files to your server


How to scan and stop uploading infected files to your server?

To scan and stop uploading infected files to your server , you need to enable ClamAV with PureFTP (Do not use this with ProFTP or other FTP services on your server).

  1. Make sure Clamav is installed on your server and/or up-to-date.

Clamav binary files are installed in (for a cPanel and DirectAdmin powered servers)
/usr/local/bin and /usr/bin/

Using your favorite Linux text editor such as vi or pico, edit /etc/pure-ftpd.conf file and set the entry:

From:
#CallUploadScript yes

To:
CallUploadScript yes

Save and exit the file /etc/pure-ftpd.conf.

  1. Edit the file /etc/init.d/pure-ftpd
    Find the following entry:
    $DAEMONIZE $fullpath /etc/pure-ftpd.conf -O clf:/var/log/xferlog $OPTIONS –daemonize
    and insert the following line below it:
    $DAEMONIZE /usr/sbin/pure-uploadscript -B -r /var/run/pure-ftpd/clamscan.sh
  2. Find the following entry:
    kill $(cat /var/run/pure-ftpd.pid)
    and insert the following line below it:
    kill $(cat /var/run/pure-ftpd/pure-uploadscript.pid)
  3. Save and exit the file /etc/init.d/pure-ftpd
  4. Change the directory to:
    cd /var/run/pure-ftpd/
  5. Create the following script: clamscan.sh and insert the following text
#!/bin/sh

if [ "$1" = "" ]; then
        echo 'Variable is blank';
        exit;
fi
if [ ! -f "$1" ]; then
        echo "$1 file not found"
        exit;
fi


date=`date '+%d-%m-%y %H:%M'`;
scan=`/usr/bin/clamdscan --remove --no-summary "$1"`;
echo "$date ClamAV $scan" >> /var/log/messages
  1. Save and exit the file clamscan.sh, and then run the following command to change its permission:
    chmod 755 /var/run/pure-ftpd/clamscan.sh
  1. Restart PureFTP daemon (for generic server):
    /sbin/service pure-ftpd restart
    For a cPanel powered-server:
    /scripts/restartsrv pure-ftpd

Since we used the switch –remove with the clamscan command in the script above, infected files will be permanently deleted. If you do not want the script to delete infected files and just move them to a directory, change the following entry:

From:
scan=`/usr/bin/clamdscan –remove –no-summary “$1″`;

To:
scan=`/usr/bin/clamdscan –move=/root/junk –no-summary “$1″`;

If you do that, you need to create the subdirectory junk in the /root directory. To do so, execute this command:

  • mkdir /root/junk

DONE!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Categories

%d bloggers like this: