Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

shockme (2685)

  reversethis-{gro.dnuowtixe} {ta} {kcohs}
AOL IM: stephenhargrove (Add Buddy, Send Message)

If you really must have more information about me, see my home node [] at PerlMonks [] or my journal [] at

Journal of shockme (2685)

Tuesday December 09, 2003
06:01 PM

A Question Regarding a CGI script

[ #16250 ]

Consider the following script:

use strict;
use CGI qw(param);

$user_name = param(UserName);
$email_addy = param(EmailAddy);
$comments = param(Comments);

open(SENDMAIL, "| sendmail -oi -t") or die "Can't fork for sendmail: $!\n";
From: $email_addy
To: joe\
Subject: Message from $user_name

$user_name ($email_addy) has sent you the following:





Other than flooding Joe's inbox, can you think of any way that this script could be abused? More specifically, is it possible to abuse this script to send email to someone other than Joe?

Posted from, comment here.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Drive-by email (Score:3, Informative)

    by dws (341) on 2003.12.09 18:33 (#26406) Homepage Journal
    You'll want to screen $email_addy to prevent someone from passing in, say "foo@bar\nCc:".
    • When I passed it that from a simple form, it emailed me the following:
      Test Name (\ has sent you the following:
      It only sent one email, and that was to the address hardcoded in the To: field in the script. I never received an email at the Cc: address.

      The email header shows:

      From: "steveNOSPAM@exitwound.orgnCc:stephenNOSPAM" <>

      which is weird, but still unsuccessful.


      If things get any worse, I'll have to ask you to stop helping me.

      • Looks like you're losing the newline. Are you sure you're passing \n (%0A%0D)?
        • Here is a cut-and-paste of what I sent:



          Both resulted in one email being sent to the hardcoded To: address, with nothing being received as a copy. And both resulted in goofed headers as previously described.

          What am I missing here? I agree with you that not checking $email_addy should be abusable, but I don't seem to be able to replicate it.


          If things get any worse, I'll have to ask you to stop helping me.

          • My bad. Injecting %0A is sufficient.
            • Pasting


              results in the same thing ... Jeez. What am I missing here? This script may be insecure, but I'll be damned if I can prove it.


              If things get any worse, I'll have to ask you to stop helping me.

              • Here's a simple test case. $to simulates a query parameter that someone has injected a %0A into. With suitable substitutions for email addresses, I get an email to each address.

                use CGI;

                my $to = CGI::unescape("a\ b\");

                open(SENDMAIL, "| sendmail -oi -t") or die "sendmail: $!\n";
                print SENDMAIL <<EOF;
                From: test <you\>
                To: $to
                Subject: Automagic message


  • ...preferring to use the Mail::Mailer interface. You might look at that as an alternative.
    • I'm with you. That would have cleaned the script up quite a bit.

      Unfortunately, in this situation, the developer has no control over the installed modules. He has to live with what he has, and in this case has to follow the FAQ on sending mail.

      dws [] pretty much hit it on the head with the inadequate (i.e., no) untainting/validation of the input.

      But yeah, if the situation was different, I'd definitely go with modules.


      If things get any worse, I'll have to ask you to stop helping me.