########################################################## # Defense in Depth - Anti-SPAM for sendmail environments # # by David Bank --> http://dave.trianglenug.org # ########################################################## # Code Example #3 - Perl - MIMEDefang - filter_sender() # ########################################################## ############################### # Declare a hash of hosted Domains # - Key: Domain Names we host # - Value: A flag as to if the Domain should be # receiving E-Mail (0=No, 1=Yes) ############################### %OurDomains=( "domain1.tld", 1, "domain2.tld", 0 }; [...] sub filter_sender { # Read parameters passed to function my($sender, $ip, $hostname, $helo)=@_; # Local variables my(@chksender); my($chk, $chksenderdomain); # Search the list of our hosts using the $ip argument if ( exists($OurHosts{$ip}) ) { # The connecting host is our own host, don't bother checking further return('CONTINUE', 'ok'); } # The sender cannot claim to be a user in any Domain we host since we have a # already eliminated the sending host as being ours # Make sure the address we're checking is in all lower-case $chk = lc($sender); # Remove any angle-brackets from address $chk =~ s/^$//; # Split the Sender address into Address and Domain Name @chksender=split(/\@/, $chk); # Extract just the Domain $chksenderdomain=$chksender[1]; if ( exists($OurDomains{$chksenderdomain}) ) { # Reject connection - fraudulent Foreign sender claiming to be local return('REJECT', "FRAUDULENT ADDRESS: $helo is not $chksenderdomain"); } # End of IF } # End of filter_sender