From owner-freebsd-questions Thu Oct 22 10:00:14 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id KAA21266 for freebsd-questions-outgoing; Thu, 22 Oct 1998 10:00:14 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from zeus.tds.edu (zeus.tds.edu [38.149.131.15]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id KAA21259 for ; Thu, 22 Oct 1998 10:00:09 -0700 (PDT) (envelope-from willow@tds.edu) Received: from zeus.tds.edu (willow@zeus.tds.edu [38.149.131.15]) by zeus.tds.edu (8.9.1a/8.9.1a) with ESMTP id MAA06228; Thu, 22 Oct 1998 12:59:11 -0400 (EDT) Date: Thu, 22 Oct 1998 12:59:11 -0400 (EDT) From: Willow To: "Norman C. Rice" cc: Dan Busarow , "David L. Vondrasek" , freebsd-questions@FreeBSD.ORG Subject: Re: Third Party SMTP relay In-Reply-To: <19981022102924.B2415@emu.sourcee.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG I dont remember where I got it, but here it is. ----------- cut here ------------- #!/usr/local/bin/perl5 # SMTP email verifier # A.Daviel, Vancouver Webpages sub disc { print <) { chop ; s/^\s+// ; if (/^#/) { next ; } s/\s.*// ; &checknode ($_) ; } if (!$nname) { &help ; } sub checknode { local($node) = $_[0] ; undef(@status) ; $timed_out=0 ; $sec=0 ; ($nname,$aliases,$addrtype,$length,@addrs) =gethostbyname($node) ; if ($timed_out) { return ; } #@f = unpack('C4',$addrs[0]); unless ($nname) { push(@status,"906") ; &clean ; return ; } if (!$quiet) { print "Spam Test for $nname\n"; } if (!$debug) { $SIG{'ALRM'} = "timed_out" ; alarm($tout1) ; } $start = time ; $proto = getprotobyname('tcp') ; if ($timed_out) { return ; } unless ($proto) { print STDERR "ERROR: getprotobyname fail ($!)\n"; push(@status,"901") ; &clean ; return ; } $port = 25; $iaddr = inet_aton ($node) ; if ($timed_out) { return ; } unless ($iaddr) { print STDERR "ERROR: inet_aton ($!)\n"; push(@status,"902") ; &clean ; return ; } $sin = sockaddr_in ($port, $iaddr); $stat = socket(S, PF_INET, SOCK_STREAM, $proto) ; if ($timed_out) { return ; } unless ($stat) { print STDERR "ERROR: socket fail ($!): $proto\n" ; push(@status,"903") ; &clean ; return ; } $stat = connect(S, $sin) ; if ($timed_out) { return ; } unless ($stat) { #print STDERR "ERROR: connect fail ($!)\n"; push(@status,"904") ; &clean ; return ; } if (!$debug) { alarm($tout) ; } recv S,$_,999,0 ; if ($timed_out) { return ; } $version = $_ ; if (!$quiet) { print "$_\n"; } &pstat ; if (!$quiet) { print "Check HELO\n";} send S, "MAIL From:<".$good_address.">\r\n",0 ; recv S,$_,999,0 ; if ($timed_out) { return ; } if (!$quiet) { print "$_\n"; } &pstat ; &rset ; if (!$quiet) { print "HELO $bad_org .. " ;} send S, "HELO ".$bad_org."\r\n",0 ; recv S,$_,999,0 ; if ($timed_out) { return ; } if (!$quiet) { print "$_"; } &pstat ; &rset ; if (!$quiet) { print "HELO $here .. " ;} send S, "HELO ".$here."\r\n",0 ; recv S,$_,999,0 ; if ($timed_out) { return ; } if (!$quiet) { print "$_"; } &pstat ; if (!$quiet) { print "\nCheck VRFY and EXPN\n"; } if (!$quiet) { print "VRFY .. " ;} send S, "VRFY \r\n",0 ; recv S,$_,999,0 ; if ($timed_out) { return ; } if (!$quiet) { print "$_"; } &pstat ; if (!$quiet) { print "EXPN .. " ;} send S, "EXPN \r\n",0 ; recv S,$_,999,0 ; if ($timed_out) { return ; } if (!$quiet) { print "$_"; } &pstat ; # try bogus FROM if (!$quiet) { print "\nTest FROM spoofing\n";} if (!$quiet) { print "From:<$bad_address> .. ";} send S, "MAIL From:<".$bad_address.">\r\n",0 ; recv S,$_,999,0 ; if ($timed_out) { return ; } if (!$quiet) { print "$_";} &pstat ; &rset ; if (!$quiet) { print "From: .. " ; } send S, "MAIL From:\r\n",0 ; recv S,$_,999,0 ; if ($timed_out) { return ; } if (!$quiet) { print "$_";} &pstat ; &rset ; if (!$quiet) { print "From:<$good_address> .. " ;} send S, "MAIL From:<".$good_address.">\r\n",0 ; recv S,$_,999,0 ; if ($timed_out) { return ; } if (!$quiet) { print "$_\n";} &pstat ; if (!$quiet) { print "Test mail relay\n";} if ($hname eq $nname && !$quiet) { print "$hname is local\n"; } if (!$quiet) { print "To:<$bad_address> .. ";} send S, "RCPT To:<".$bad_address.">\r\n",0 ; recv S,$_,999,0 ; if ($timed_out) { return ; } if (!$quiet) { print "$_";} &pstat ; if (!$quiet) { print "To:<$good_address> .. ";} send S, "RCPT To:<".$good_address.">\r\n",0 ; recv S,$_,999,0 ; if ($timed_out) { return ; } if (!$quiet) { print "$_";} &pstat ; if (!$quiet) { print "To:<$good_address\@$node> .." ; } send S, "RCPT To:<".$good_address."\@$node>\r\n",0 ; recv S,$_,999,0 ; if ($timed_out) { return ; } if (!$quiet) { print "$_";} &pstat ; if (!$quiet) { print "To <$me%$here\@$node> .." ;} send S, "RCPT To:<".$me."%".$here."\@$node>\r\n",0 ; recv S,$_,999,0 ; if ($timed_out) { return ; } if (!$quiet) { print "$_";} &pstat ; if (!$quiet) { print "To <$here!$me\@$node> .." ;} send S, "RCPT To:<".$here."!".$me."\@$node>\r\n",0 ; recv S,$_,999,0 ; if ($timed_out) { return ; } if (!$quiet) { print "$_";} &pstat ; if ($hname eq $nname) { $status[9] = '907'; } if (!$quiet) { print "\nInvalid user\n";} if (!$quiet) { print "To .." ;} send S, "RCPT To:\r\n",0 ; recv S,$_,999,0 ; if ($timed_out) { return ; } if (!$quiet) { print "$_";} &pstat ; if (!$quiet) { print "\nValid user\n";} if (!$quiet) { print "To .." ;} send S, "RCPT To:\r\n",0 ; recv S,$_,999,0 ; if ($timed_out) { return ; } if (!$quiet) { print "$_";} &pstat ; if (!$quiet) { print "To .." ;} send S, "RCPT To:\r\n",0 ; recv S,$_,999,0 ; if ($timed_out) { return ; } if (!$quiet) { print "$_";} &pstat ; if (!$quiet) { print "To .." ;} send S, "RCPT To:\r\n",0 ; recv S,$_,999,0 ; if ($timed_out) { return ; } if (!$quiet) { print "$_";} &pstat ; if (!$quiet) { print "\nQuit.\n";} send S, "QUIT\r\n",0 ; recv S,$_,999,0 ; if ($timed_out) { return ; } if (!$quiet) { print "$_\n";} &clean ; } # end checknode sub timed_out { #print STDERR "Port 25 timed out to $node\n"; push(@status,"905") ; $timed_out=1 ; &clean ; } sub clean { $sec = time - $start ; if ($prstat) { print "$node "; foreach $_ (@status) { print "$_ "; } print "\n"; } if (!$prstat) { if ($status[0] eq '904') { print "$nname rejects SMTP mail\n"; } elsif ($status[0] eq '905') { print "$nname could not be reached\n"; } elsif ($status[0] eq '906') { print "$node not found\n"; } elsif ($status[0] =~ /^9/) { print "Internal error\n" ; } else { if ($version) { print "$nname $version" ; } print "$nname requires HELO: " ; &npyn(1) ; print "$nname allows VRFY username verification: "; &pyn(4) ; print "$nname allows EXPN forwarding expansion: "; &pyn(5) ; print "$nname allows bogus From: header: "; &pyn(6) ; if ($status[9] eq '907') { print "$nname is local\n"; } else { print "$nname allows mail relaying: "; if (($status[9] =~ /^2/) || ($status[10] =~ /^2/) || ($status[11] =~ /^2/) || ($status[12] =~ /^2/) || ($status[13] =~ /^2/)) { print "YES\n"; } else { print "NO\n"; } } print "$nname can mail to postmaster: "; &pyn(15) ; print "$nname can mail to webmaster: "; &pyn(16) ; print "$nname can mail to abuse: "; &pyn(17) ; foreach $_ (@status) { if ($_ eq '905') { print "$nname timed out\n"; } } } if ($sec>0) { print "$nname - $sec seconds\n"; } } alarm(0); } sub rset { if (!$quiet) { print "Reset.. ";} send S, "RSET\r\n",0 ; recv S,$_,999,0 ; if (!$quiet) { print "$_" ;} } sub pstat { tr/\n/ /; chop ; s/\D.*// ; push(@status,$_) ; } sub npyn { if ($status[$_[0]] =~ /^250/) { print "NO\n"; } else { print "YES\n"; } } sub pyn { if (!($status[$_[0]] =~ /^250/)) { print "NO\n"; } else { print "YES\n"; } } sub help { print < This program attempts to relay email messages through sendmail. No actual messages are sent; only recipients are tested. Please read the disclaimer ($0 -D) If -s is specified, the test runs quietly and only generates a status line. If -q is specified, the test runs quietly and only generates a summary. If -t is specified, timeouts are disabled. If is not present, will read a list of addresses from STDIN such as that produced by "host -l ". The summary is designed to be fed to "grep", "sort", etc. The status line is designed to be fed to e.g. another Perl script for statistics gathering. The status elements (with -s) are from the following commands, sequentially: connect, mail no helo, helo badorg, helo goodaddr, vrfy postmaster, expn postmaster, from badaddr, from nosuchperson, from goodaddr, to badaddr, to goodaddr, to good\@org\@node, to good%org\@node, to org!good\@node, to nosuchuser, to postmaster, to webmaster, to abuse status values are from sendmail, except 900 series which indicate a local error. 904 is connect fail (SMTP mail not supported) 905 is timed out (tcp connect failed) 906 is not found (DNS lookup failure) 907 means you are testing this machine, so relay tests are pointless EOM } ------------ cut here ------------- -- willow@tds.edu -- On Thu, 22 Oct 1998, Norman C. Rice wrote: > What program are you using to perform the spam test? > Is there a URL where it can be downloaded? > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message