#!/usr/local/bin/perl # avtest v1.1 (c) 21.7.2004 by Andreas Ley (u) 23.5.2005 # Test SMTP Server for AV in SMTP dialog use Getopt::Std; use Socket; sub usage { my $image = $0; $image =~ s!.*/!!; print STDERR "Usage: $image [-v] [-c count [-s]] hostname[:domain[:user]] [...]\n"; print STDERR "-v verbose mode\n"; print STDERR "-c Perform count tests on each host\n"; print STDERR "-s Print summary line only\n"; print STDERR "domain defaults to hostname, user defaults to postmaster\n"; exit(1); } $opt_c = 1; getopts('Dhxvc:s') || &usage; &usage if (defined($opt_h) || $#ARGV < 0); sub cmd { if (defined($_[0])) { print STDERR "> $_[0]" if ($opt_D); print SMTP $_[0]; } do { $_ = ; return(0) unless (/\S/); print STDERR "< $_" if ($opt_D); } while (!/^\d+\s/); return(1); } for $host (@ARGV) { undef $domain; $user = "postmaster"; ($host,$domain) = ($`,$') if ($host =~ /:/); ($domain,$user) = ($`,$') if ($domain =~ /:/); socket(SMTP,PF_INET,SOCK_STREAM,getprotobyname('tcp')) || die "$image: Can't get socket: $!\n"; connect(SMTP,sockaddr_in(25,inet_aton($host))) || die "$image: Can't connect to $host:$port: $!\n"; select((select(SMTP),$|=1)[0]); &cmd; $domain = (split)[1] unless(defined($domain)); if (/^2/) { print "$host: sending EICAR to $user\@$domain\n" if ($opt_v); for $cnt (1..$opt_c) { &cmd("MAIL FROM:<>\n") && /^2/ && &cmd("RCPT TO:<$user\@$domain>\n") && /^2/ && &cmd("DATA\n") && /^3/ && &cmd("Subject: Antivirus-Test\nMIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=EICAR\n\n--EICAR\nContent-Type: text/plain\n\nYou received this message because you have a dysfunctional or no virus scanner\nat all on $host\n\n--EICAR\nContent-Type: application/octet-stream\nContent-Disposition: attachment\n\nX5O!P%\@AP[4\\PZX54(P^)7CC)7}\$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!\$H+H*\n--EICAR--\n.\n"); print "$host: $_" unless ($opt_s && $cnt < $opt_c); if (/^[^25]/) { if ($cnt < $opt_c) { print "$host: $_" if ($opt_s); print "$host: only ".($cnt-1)." messages sent\n"; } last; } } } &cmd("QUIT\n"); close(SMTP); }