Forum Moderators: phranque
They use a header attack, they generate bcc or cc fields WITHOUT using the submit form, just but direct line entry.
I have a theory to stop the bcc spam across multiple programs.
I am NOT a programmer, so I need help. Can any of you tell me if this will work?
Here we go: (perl)
Step 1:
Identify the variable that triggers the script to inject email headers:
The below example is taken from the notorious "matts cript archive" formmail.pl
"email" is the form header.
$sender = $form{'email'};
if ($sender =~ /\@.*\@¦,/) {
print "There was a problem sending your message. We apologize for the inconvenience.";
exit;
}
$sender = $form{'email'};
if ($sender =~ /\@.*\@¦,¦bcc:¦\n/i) {
print "There was a problem sending your message. We apologize for the inconvenience.";
exit;
}
(Pipes are NOT supposed to be broken, replace.)
The first subroutine detects more then one address in the header.
The second looks for bcc (blind carbon copy)AND /n (newline) injections.
This solution "appears" to be simple enough to be used on any perl script that uses email. Simply replace $sender = $form{'email'}; with $sender = $any_email_header_variable;
Thus it can be inserted into any perl script using email respond features.
I am not sure this will work, seems almost too easy.
If ANYONE can improve this, or tell me whats the problem, please let me know. Also am open to better solutions.
Thanks!
$sender = $form{'email'};
I've thought this over, and I just can't give it away for free, but will try lead you to a solution. You're definately on the right track though. :-) Important to know is that **any** valid mail header can be perverted for this purpose. You can do this in the subject, to, and from fields of a mail header as well. So to effectively slow them down, you need to screen ALL incoming data.
The newline regexp is worthless. They often use an encoded or binary value for the newline and it never matches on \n. But what you CAN rely on is what would come after that newline, the BCC or CC or a content-type header.
Although I won't specify how, I will say this, LOG YOUR DATA. Log everything input to your scripts. This will reveal exactly what they are doing, or trying to do, and you can form regexps and methods to stop it.
To the acual sender's email field - not necessarily what comes in from the form, but what you put in the mail header - apply a variety of screens:
1. If a comma separated list is found, split up the list, strip off and use only the first address in that list. This one possibly allows them to think their list was sent successfully, but it only sends the one. :-)
2. Check for the valid email pattern, there are many good regexps to be found on the web. Something like this, but this is not what I use:
if ($sender!~ /.*\@.*[.].*/) { (message and exit here) }
3. At this point all metacharacters should be already stripped out of the data - but do it again on only the email to-field in case something is bypassing the meta screening.
In your LOGGING routine, do something like this, to ALL FIELDS, not just incoming email field. As you have discovered, ¦ is the pipe operator, you can also use the word 'or':
if (
($field =~ /b*cc\s*:/i) ¦¦
($field =~ /to\s*:/i) ¦¦
($field =~ /content\-type/i)
) { (message and exit here) }
There is actually much more than this but it will lead you in the right direction and slow them down a bit. Plugging up this security hole for someone is a STEAL at $200, although it's seldom appreciated. :-)
$from = "joe@example.com\nBcc: spamee@example.com"; Then programmer uses this value for the sendmail input like:
open(SENDMAIL, "¦ /usr/sbin/sendmail");
print SENDMAIL "From: $from\n";
...
close(SENDMAIL);
When you print the $form variable, what actually prints is:
From: joe@example.com
Bcc: spamee@example.com
And sendmail doesn't care, because it's 100% valid input. And than could happen to any field value that you use directly in mail headers (subject, to, from, etc...)
They also get through the perl fix that I originally posted :(
However, I have not get tried that trick on ALL headers, which I am going to do.
I heard that NMS FormMail Version 3.14c1 from sourceforge is not Bcc and cc attackable, and is reasonably secure. Before I search through the code, or convert over to it, can anyone confirm it is secure? If its not, do you know of a form that is?
Thanks!
PS I appreciate the hints you gave. It's a shame you cant outright post the fix, but you have to make money like everyone else, and I can respect this. It's a shame though, because if you released a solid fix free to the public it would go a VERY long way in putting a dent in internet spam.
I tried that php code on a phpformmail and the spammer still got through.They also get through the perl fix that I originally posted
Did you make sure to change the $EMAIL variable to the variable you use for the $email field and run the same test against your other variables that stick stuff in email headers?
For instance you might need to modify the code to something like this:
if (preg_match("/[\\000-\\037]/",$email) ¦¦ preg_match("/[\\000-\\037]/",$subject)) { die(); }
henry0:
I do not know of any using (on purpose) BCC or CC via form as such why not disallow CC and BCC?
If you're asking on a domain level, both I and motar have explained: they insert a newline character into the data input that corresponds to one of the mail headers, then create their own BCC header. If you're asking on a mail server level, this is possible ONLY of you have your own dedicated mail server, I think you can configure sendmail to not allow BCC/CC. But this would mean NO ONE using sendmail could use BCC/CC. It is indeed a partial solution, but most cases you're on shared servers and can't just disable BCC/CC for all domains on that server for the benefit of one domain.
moltar:
$from = "joe@example.com\nBcc: spamee@example.com";
The problem is, it's almost never a \n, and for whatever reason matching on any encoding of a newline doesn't seem to work either. You can find this out by logging if you are attacked. :-)
MThiessen:
It's a shame you can't outright post the fix,
but you have to make money like everyone else, and I can respect this. It's a shame though,
because if you released a solid fix free to the public it would go a VERY long way in putting a dent in internet spam.
This knowledge has come long and hard, and believe me, I barely make enough to cut it, (as my wife ofttimes tells me!) but in truth, there's actually a larger reason. Hackers are watching us, you know they are. If we outright post our methods, this gives them the tools to undo them.
Worse yet, for myself, if one of my tips here were to render my methods ineffective, I would have to go back to all customers affected and fix them. Now, most programmers rationalize this as billable; as a personal ethic, I do not. I've charged for time to fix something, if it no longer works, the original solution was just a patch. If I pay a plasterer to fix a hole in my ceiling and if falls out a week later, I'm sure as hell not paying him to fix it again!
I've been there before, it's not a place I want to be again.
It's a common trick to help avoid hacking by using odd names for our variables, files, database tables, and other unseen server-side methods. Anything you do that cannot be seen by View Source should be kept as hidden as possible.
But follow the clues I've laid out here, watch, wait, think it through - all the clues are there. :-D
open (LOG, ">>$mylog");
foreach $key (keys %data) { print LOG "key: $v value: $data{$v}\n"; }
print LOG '=================',"\n";
close (LOG);
:-P
if interested sticky me
I suppose this is one good solution, force the visitor to enter their return email address into the data input field, which gets placed into the body of the email - but if they don't, you lose a contact.
"email injection" perl [google.com] is one of the more common searches.
Best of luck everyone! :-)