PDA

View Full Version : SPAM sent from a php contact form...


Fred
09-22-2005, 05:49 PM
Hi,

I stopped just in time a possible vulnerability in one of my user scripts... that could make my server a SPAM sender :eek:
Here's the script:


<?

$msg = "subject:\t$subject\n";
$msg .= "name:\t$name\n";
$msg .= "name2:\t$name2\n\n";
$msg .= "company:\t$company\n";
$msg .= "telephone:\t$telephone\n";
$msg .= "fax:\t$fax\n\n";
$msg .= "email:\t$email\n";
$msg .= "url:\t$url\n";
$msg .= "message:\t$message\n\n";

$recipient = "customer_email@hotmail.com";
$subject = "Form";

$mailheaders = "From: formulaire user<contact@domain.com> \n";
$mailheaders .= "Reply-To: $email\n\n";

mail($recipient, $subject, $msg, $mailheaders);


?>

A bot(or someone) attacked the script today...
I saw a lot of email sent from nobody@(my webserver user) and going to the my customer email and having the subject "Contact form domain.com".
BUT one of these emails was sent to another email using bcc: mhkoch321@aol.com

i looked at the script... but didn't understand how the bot was able to send an email to a bcc... i tried a lot of things... and finally i found it:
$mailheaders .= "Reply-To: $email\n\n";

$email is not checked before it was used... The customer told me the worst he's expected was to receive some junk in HIS mailbox ;)

So, the spammer was able to insert new mail headers ... Here's the $email value he used:


email: bfqngspb@domain.com
Content-Type: multipart/mixed; boundary=\"===============0452749181==\"
MIME-Version: 1.0
Subject: 1f0d01d8
To: bfqngspb@domain.com
bcc: mhkoch321@aol.com
From: bfqngspb@domain.com

This is a multi-part message in MIME format.

--===============0452749181==
Content-Type: text/plain; charset=\"us-ascii\"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

qoevyurk
--===============0452749181==--


I just want to warn you... so you can check your customers script or at least be able to avoid the problem...

ozgreg
09-22-2005, 06:46 PM
formmail.cgi and other versions / programs have always been an open hole for spambots to exploit.

Thanks for your post..

vps-vince
09-22-2005, 07:42 PM
Yes, this has been happening to many sites since July at least.
Read most info about it here:

http://www.anders.com/cms/75/Crack.Attempt/Spam.Relay

http://www.anders.com/projects/sysadmin/formPostHijacking/

http://securephp.damonkohler.com/index.php/Email_Injection

- Vince

Fred
09-22-2005, 07:45 PM
thanks for the links vince... Pretty interesting...
Also, from the link you posted, we found this written by the same author:
http://www.anders.com/projects/sysadmin/formPostHijacking/

vps-vince
09-22-2005, 07:53 PM
Gish you're quick Fred!
I was still adding the other 2 links between my office remote access PC and home when you replied. :)

- Vince

Fred
09-22-2005, 08:08 PM
We posted the links at the same time :)

The third link you posted is by far the greatest one ... Pretty great stuff there...

guapo
10-04-2005, 08:03 PM
nice topic i never had this problem yet but who knows the life :D
thx for the information.

add info to you guys.

in perl you can do something like this regexp also in php too but im showing here 1 in perl

$email =~ /[a-z0-9_\.\-]+\@[a-z0-9\.\-]*\.(edu|org|com|net|biz|info|gov|web|[a-z]{2})/

make it a unless clause.

that will check everything before @ and after if dont match with it...
wont be accepted.

this last part (edu|org|com|net|biz|info|gov|web|[a-z]{2}) is about everything after DOT
will accept those domain extensions finished with edu, net, biz etc
example name.edu name.org name.com

[a-z]{2} make 2 names allowed like brazillian its domain.com.br for example.