marcs has asked for the wisdom of the Perl Monks concerning the following question:
The addresses have been taken out and replaced with fictional ones:
My question is this: is this script secure? Is there a better way to do this while still validating the addresses? Security is my main concern here, so I wanted to run this past those with more knowledge than me. :)#!/usr/bin/perl # # Written by: Marc Silver <marcs@draenor.org> # # $Id: filter-mail-authenticate.pl,v 1.25 2001/08/08 08:58:24 marcs Ex +p $; # # # my( $sendmail ) = "/usr/sbin/sendmail"; #location of sendmail my( $logfile ) = "/tmp/filter.log"; #location of logfile my( $myaddress ) = "list\@draenor.org"; #list address my( $listadmin ) = "marcs\@draenor.org"; #admin address my( $modify_subject ) = 0; #modify the subject? my( $approved ) = 0; #this must be 0 my( $log ) = 1; #set to 1 to log umask 0133; @real_recipients = ( "user\@draenor.org", "erp\@iafrica.com", "user\@iafrica.com" ); $message = ""; open( LOG, ">> $logfile" ) if( $log ); while( <> ) { if( /^From ([-a-zA-Z0-9_.@]+) .+$/ && ! $sender ) { $sender = $1; print LOG "Sender found: $sender\n" if( $log ); next; } if( /^Subject: (.+)$/ ) { $original_subject = $1; if( $modify_subject ) { print LOG "Subject modified\n" if( $log ); s/$1/[friends]: $original_subject/; } } s/fuck/f***/ig; s/shit/s***/ig; s/shat/s***/ig; s/cock/c***/ig; s/cunt/c***/ig; s/pussy/p****/ig; s/whore/wh***/ig; s/bitch/b****/ig; s/asshole/a**hole/ig; s/bastard/b*st*rd/ig; s/crap/cr*p/ig; s/^\.$/. /; $message .= $_; } if( $sender ) { foreach $recipient( @real_recipients ) { if( $recipient eq $sender ) { $approved++; print LOG "Sender matched: $recipient\n" if( $log ); } } } else { print LOG "ERROR: No sender found\n" if( $log ); open( MAIL, "|$sendmail $listadmin" ); print MAIL "No sender found.\n\n"; print MAIL $message; close( MAIL ); exit 0; } if( $approved ) { open( MAIL, "|$sendmail @real_recipients" ); print MAIL $message; close( MAIL ); print LOG "Message [$original_subject] sent\n" if( $log ); } else { print LOG "Sender not matched\n" if( $log ); open( MAILADMIN, "|$sendmail -f $myaddress $listadmin" ); print MAILADMIN "$sender was rejected sending to the friends list.\n +\n"; print MAILADMIN "Message contents:\n\n $message\n"; close( MAILADMIN ); open( MAIL, "|$sendmail -f $myaddress $sender" ); print MAIL "You are not subscribed to this list and may not post to +it.\n"; close( MAIL ); print LOG "ERROR: Message denied. Admin / Sender notified\n" if( $lo +g ); } close( LOG ) if( $log );
Thanks,
Marc
Edit: chipmunk 2001-08-12
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: securing code
by abstracts (Hermit) on Aug 11, 2001 at 22:18 UTC | |
Re: securing code
by damian1301 (Curate) on Aug 11, 2001 at 22:46 UTC |