2 # Send virus/spam/normal messages to a named host with named sender/recipients
3 # and optionnal message size or smtp auth
5 # Require perl modules: Net::SMTP, AppConfig
7 # Copyright (C) 2006 Emmanuel Lacour <elacour@home-dn.net>
9 # This file is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by the
11 # Free Software Foundation; either version 2, or (at your option) any
14 # This file is distributed in the hope that it will be
15 # useful, but WITHOUT ANY WARRANTY; without even the implied warranty
16 # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this file; see the file COPYING. If not, write to the Free
21 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27 use AppConfig qw(:expand :argcount);
31 my $AUTHOR = 'Emmanuel Lacour, <elacour@home-dn.net>';
41 $sample{spam} = 'Subject: Test spam mail (GTUBE)
45 Content-Type: text/plain; charset=us-ascii
46 Content-Transfer-Encoding: 7bit
48 This is the GTUBE, the
55 If your spam filter supports it, the GTUBE provides a test by which you
56 can verify that the filter is installed correctly and is detecting incoming
57 spam. You can send yourself a test mail containing the following string of
58 characters (in upper case and with no white spaces and line breaks):
60 XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X
62 You should send this test mail from an account outside of your network.
65 # Nospam/novirus sample email
66 $sample{normal} = 'Subject: Test mail nospam/novirus
70 Content-Type: text/plain; charset=us-ascii
71 Content-Transfer-Encoding: 7bit
78 $sample{virus} = 'From: Sender <{FROM}>
82 Content-Type: multipart/mixed; boundary="C7zPtVaVf+AK4Oqc"
83 Content-Disposition: inline
84 Content-Transfer-Encoding: 8bit
89 Content-Type: text/plain; charset=iso-8859-1
90 Content-Disposition: inline
91 Content-Transfer-Encoding: 8bit
96 Content-Type: application/x-msdos-program
97 Content-Disposition: attachment; filename="EICAR.COM"
98 Content-Transfer-Encoding: quoted-printable
100 X5O!P%@AP[4{DEACTIVATED}\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*=0A
104 # Close properly smtp connection before exiting on error
107 print STDERR "E: ", $mesg;
114 # Prints out version information
116 print "$NAME $VERSION\n";
117 print "Written by $AUTHOR\n";
121 # Prints command-line help
123 print "Usage: $NAME ARGUMENTS [OPTIONNALS ARGUMENTS]
126 --host=HOST the host to connect to
127 --from=FROM the sender email
128 --to=TO the recipient email
129 --spam=SPAM_COUNT the number of spam emails to sent
130 --virus=VIRUS_COUNT the number of virus emails to sent
131 --normal=NORMAL_COUNT the number of nonspam/nonvirus emails to sent
133 OPTIONNALS ARGUMENTS:
134 --user=USER an optionnal user for smtp authentication
135 --pass=PASS an optionnal password for smtp authentication
136 --size=SIZE an optionnal message size (integer optionnaly
137 followed by M for megabytes or K for kilobytes
139 --help prints out command-line help
140 --version prints out version information\n";
147 # Read command line arguments
149 my $appconfig = AppConfig->new(
163 %opt = $appconfig->varlist('^.*$');
165 # Check command line arguments
166 usage if (defined $opt{help});
167 version if (defined $opt{version});
168 usage if ((!defined $opt{host}) || (! defined $opt{from}) || (! defined $opt{to}) || (! defined $opt{spam}) || (! defined $opt{virus}) || (! defined $opt{normal}));
169 usage if ((defined $opt{user}) && (! defined $opt{pass}));
170 usage if ((defined $opt{pass}) && (! defined $opt{user}));
172 my $host = $opt{host};
173 my $from = $opt{from};
175 $count{spam} = $opt{spam};
176 $count{virus} = $opt{virus};
177 $count{normal} = $opt{normal};
178 $user = $opt{user} if ($opt{user});
179 $pass = $opt{pass} if ($opt{pass});
180 $size = $opt{size} if ($opt{size});
182 if ($size =~ /^([0-9]+)M$/) {
183 $size = $1 * 1024 * 1024;
184 } elsif ($size =~ /^([0-9]+)K$/) {
186 } elsif ($size =~ /^([0-9]+)$/) {
189 die "Error, wrong size: $size\n";
193 # Open an smtp connection
194 $smtp = Net::SMTP->new($host, Debug => 0) or die "Couldn't connect to $host: $!\n";
196 # Authenticate if needed
197 if ($user && $pass) {
198 $smtp->auth($user, $pass) or error("Auth failed: $!\n");
202 foreach my $type (keys%count) {
204 while ($i < $count{$type}) {
205 print "Sending: $from -> $to, $type\n";
206 $smtp->mail($from) or error("From failed: $!\n");
207 $smtp->to($to) or error("To failed: $!\n");
208 $smtp->data() or error("Data failed: $!\n");
210 my $body = $sample{$type};
211 $body =~ s/{TO}/$to/g;
212 $body =~ s/{FROM}/$from/g;
213 # Disable special virus mangling (needed for letting people using an http AV download this toool ;))
214 $body =~ s/{DEACTIVATED}//g;
215 $smtp->datasend($body) or error("Datasend failed: $!\n");
216 $sent_size += length($body);
218 my $line = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
219 while ($sent_size <= $size) {
220 $smtp->datasend($line) or error("Datasend failed: $!\n");
224 $smtp->dataend() or error("Dataend failed: $!\n");
235 # script documentation (POD style)
239 smtpt - simple command line for testing smtp server features
243 This program let you send different kind of emails (spam, virus, normal) to a
244 specified smtp server. It can do smtp authentication and message size
247 =head1 COMMAND LINE PARAMETERS
249 Required command line parameters are:
251 =head2 B<--host>=I<HOST>
253 The host to connect to.
255 =head2 B<--from>=I<FROM>
263 =head2 B<--spam>=I<SPAM_COUNT>
265 The count of spam emails to sent.
267 =head2 B<--virus>=I<VIRUS_COUNT>
269 The count of virus emails to sent.
271 =head2 B<--normal>=I<NORMAL_COUNT>
273 The count of nonspam/nonvirus emails to sent.
278 =head2 B<--user>=I<AUTH_USER>
280 An optionnal user for smtp authentication.
282 =head2 B<--pass>=I<AUTH_PASSWORD>
284 An optionnal password for smtp authentication.
286 =head2 B<--size>=I<MESSAGE_SIZE>
288 An optionnal message size (integer optionnaly followed
289 by M for megabytes or K for kilobytes (default: bytes)).
293 Prints out command-line help.
297 Prints out version information.
301 Emmanuel Lacour, elacour@home-dn.net