#!/bin/sh to=$1 from=$2 destination=$3 sendmail=/usr/sbin/sendmail # # Unpack attachments, test for virus: # tmpdir=/var/tmp/scanmails$$ mkdir $tmpdir chmod 700 $tmpdir cat >$tmpdir/receivedmail mkdir $tmpdir/unpacked METAMAIL_TMPDIR=$tmpdir/unpacked export METAMAIL_TMPDIR echo scanmails called $1 $2 $3 $4 > $tmpdir/logfile metamail -x -w $tmpdir/receivedmail >> $tmpdir/logfile 2>&1 # for each file in unpacked, unpack zip, tar, and binhex archives recursively: cd $tmpdir/unpacked doneit=0 maxlevel=0 while test $doneit -eq 0 -a $maxlevel -lt 20 do echo maxlevel: $maxlevel >>$tmpdir/logfile doneit=1 for E in `find . -print` do # test for zip file file $E|fgrep -q "Zip archive data" if test $? -eq 0 then echo Unziping $E >> $tmpdir/logfile unzip $E >>$tmpdir/logfile 2>&1 rm $E doneit=0 fi # test for tar archive file $E|fgrep -q "tar archive" if test $? -eq 0 then echo Untaring $E >> $tmpdir/logfile tar xvf $E >>$tmpdir/logfile 2>&1 rm $E doneit=0 fi # test for compressed file file $E|fgrep -q "compress'd" if test $? -eq 0 then echo Uncompressing $E >> $tmpdir/logfile uncompress $E doneit=0 fi # test for binhex file head -4 $E|fgrep -q "(This file must be converted with BinHex 4.0)" if test $? -eq 0 then echo Unpacking binhex file $E >> $tmpdir/logfile xbin $E rm $E $E.info $E.rsrc mv $E.data $E doneit=0 fi # test for uuencoded file grep -q "begin [0-7][0-7][0-7]" $E if test $? -eq 0 then echo Unpacking uuencoded file $E >> $tmpdir/logfile uudecode --output-file=uudecode.$maxlevel $E rm $E doneit=0 fi done maxlevel=`expr $maxlevel + 1` done echo Contents of $tmpdir/unpacked >> $tmpdir/logfile ls -lR $tmpdir/unpacked >> $tmpdir/logfile uvscan --recursive --summary --verbose $tmpdir/unpacked >> $tmpdir/logfile 2>&1 scanstatus=$? echo Scanstatus is: $scanstatus >> $tmpdir/logfile if test $scanstatus -eq 1 -o $scanstatus -eq 3 then # A virus was found: Mail it to virusalert echo Virus FOUND Sent to virusalert >> $tmpdir/logfile uuencode receivedmail <$tmpdir/receivedmail >$tmpdir/receivedmail.uu echo Subject: mail.crc.dk VIRUSALERT from: $from, to: $to, destination: $destination >$tmpdir/virusmail echo >> $tmpdir/virusmail echo The attached mail has been found to contain a virus >>$tmpdir/virusmail echo Originally from: $from >>$tmpdir/virusmail echo Originally to: $to >>$tmpdir/virusmail echo Original destination: $destination >>$tmpdir/virusmail echo >> $tmpdir/virusmail cat $tmpdir/virusmail $tmpdir/logfile $tmpdir/receivedmail.uu | $sendmail virusalert@mail.cfc.dk..virscanned else # No virus, send as usual echo No virus found - good >> $tmpdir/logfile $sendmail -f $from $to@$destination.virscanned <$tmpdir/receivedmail $sendmail virusalert <$tmpdir/logfile fi # clean up rm -rf $tmpdir