#!/usr/local/bin/perl # Usage: # open-relay-test target-host-to-examine # See also: http://www.orbs.org/envelopes.html # use IPC::Open2; init(); init_envelop(); # init array for the test cases start(); # start SMTP session # test loop foreach $j ( 0.. $#envelop ) { session($j);} # test($j);} print WTR $quit ; foreach $j ( sort { $a <=> $b } keys %problem ) { print $j, " ";} print "\nNumbers listed above have a problem.\n"; if ( $pid ) { kill (9,$pid) || print " ** Problem killing pid($pid)\n";} exit; # ------- S U B R O U T I N E ---------- sub init_envelop { $victim = 'userid'; # your userid $target = 'hostname' ; # your domain (can be anything) @envelop = # classic open relay ( [ "", "<$victim\@$target>" ], # sendmail 8.8.8 double quote [ "", "<\"$victim\@$target\">"], # no < > [ "", "$victim\@$target" ], # no domain [ "" , "<$victim\@$target>" ], # relay [ "", "<$victim\%$target\@$hostname>" ], # relay ( % -> @ ) [ "", "<$victim\%$target\@$hostname>" ], # uucp addressing [ "", "<$hostname!$victim\%$target>" ], # pathing [ "", "<\@$hostname:$victim\%$target>" ], # uucp [ "" , "<$target!$victim>" ], ); } sub test { # not used now, just for debug my $iii = $_ [0]; print $envelop[$iii] -> [0]."\n"; print $envelop[$iii] -> [1]."\n"; } sub sigint_handler { if ($pid) { kill 9,$pid;} exit; } sub init { $SIG{'INT'} = 'sigint_handler'; $hostname = `hostname`; chomp($hostname); if ( $#ARGV > -1 ) { $target_name = $ARGV[0];} else { $target_name = 'localhost';} $cmd = "telnet $target_name smtp"; $pid = open2(\*RDR, \*WTR, $cmd); $quit = "quit\n"; $helo = "HELO $hostname\n"; @mail = ( " From: makoto\@fujiwara test test test part . " ); } sub start { my $exit = 0; while() { ## print ' -- ', $_ ; if ( /^Trying/ ) { next; } if ( /^Connected/ ) { next; } if ( /^Escape cha/ ) { next; } if ( /^220 .* .*SMTP/ ) { print ; print WTR $helo; } elsif ( /^250 .* pleased to meet you/ ) { last;} }} sub session { my $iii = $_ [0]; my $reset = 0 ; print "Item($iii)\n"; print WTR 'MAIL FROM: '. $envelop[$iii] -> [0] ."\n"; while() { if ( /^250 .* Sender ok/ ) { print ' -- ', $_ ; print WTR 'RCPT TO: ' . $envelop[$iii] -> [1] ."\n";} elsif ( /^250 .* Recipient ok/ ) { print ' -- ', $_ ; print WTR "DATA\n";} elsif ( /^354 Enter mail, end/ ) { print WTR @mail;} elsif ( /^5\d+ .*/ ) { print ' -- ', $_ ; print WTR "RSET\n"; } elsif ( /^250 .* Rset state/ | /^250 .* Reset state/ ) { print WTR "NOOP\n"; print ' -- ', $_ ; $reset++; } elsif ( /^503 .* Sender already specified/ ) { print ' +- ', $_ ; print WTR "RSET\n"; } elsif ( /^250 .* OK/ ) { # response to NOOP maybe, last ;} elsif ( /^250 .*Message accepted/ ) { $problem{$iii} ++; last ;} } # print " -*- session exiting---\n"; } __END__ $Log: open-relay-test,v $ Revision 1.1 2000/12/29 13:10:21 makoto Initial revision Revision 1.5 2000/04/05 02:47:54 makoto may be OK now TODO sig hander for killing leftout telnet process 553 reset sender alread specified problem