hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Web Hosting : PHP FormMail Worm
Reply

Web Hosting Discussions on all aspects of web hosting including past experiences (both negative and positive), choosing a host, questions and answers, and other related subjects. If your service is unavailable, please click here.
Forum Jump

PHP FormMail Worm

Reply Post New Thread In Web Hosting Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 09-17-2005, 01:11 AM
NexDog NexDog is offline
Web Hosting God
 
Join Date: Dec 2001
Location: Above The Clouds
Posts: 6,633

PHP FormMail Worm


It has come to our attention that there is a nasty worm floating around that is compromising many PHP forms.

THE PROBLEM

The problem is that a worm is attacking forms that allow mail headers to entered on forms and then passed to the "mail" function without correct validation.

The most common cause of this is where the "From:" or other header lines are not checked.

An example:
PHP Code:
  $headers 'From: ' $_POST['username'] . '<'$_POST['usermail'] . '>';
  
mail($to$subject$message$headers); 
All the worm needs to do is manipulate the "username" to read:
Code:
  info@yourdomain.com <info@yourdomain.com>\n\rBcc: victim@anotherdomain.com
And the mail will be bcc'd to plenty of others. It can further manipulate the headers to include MIME attachments and, basically, anything it likes.

*******************
THE SYMPTOMS

The current worm uses the domain name as a spoofed "from" e-mail address. At also attacks several fields in one go, you commonly you see a "MIME" header inside the mail.

Snippet of actual mail received (where domain.com is the domain where the form resides):
Quote:
> The following details were filled in on the form -
> Name: wlqo@domain.com
> Address: wlqo@domain.com
> Content-Type: multipart/mixed;
boundary=&quot;===============1475260401==&quot;
> MIME-Version: 1.0
> Subject: 9b94e8d5
> To: wlqo@domain.com
> bcc: jrubin3546@aol.com
> From: wlqo@domain.com
>
> This is a multi-part message in MIME format.
>
> --===============1475260401==
> Content-Type: text/plain; charset=&quot;us-ascii&quot;
> MIME-Version: 1.0
> Content-Transfer-Encoding: 7bit
>
> qaetdqmst
> --===============1475260401==--
> wlqo@domain.com
> wlqo@domain.com
***********************************

THE PRIORITY FIX

Check anything that is passed as a header and remove \n and \r charcaters from user inputted data.

This can most easily be achieved by (in the above example):
PHP Code:
   ereg_replace(array("\n","\r"),'',$from
Anything passed to the header is at risk - validate the e-mail address, username and, if sending HTML e-mail, practically everything!

NOTE: the double quotes are imporatant.

***********************************

A SUGGESTED ADDITION

It is also suggested that you add validation that the user name does not contain your own domain name or "\n" or "\r". The above fix (which is the important one) will still send an e-mail - just not maliciously as it goes to a non-existant address. Adding code validation will prevent the mail from actually being sent.

__________________
- Laurence Flynn - atOmicVPS LTD (Post Launch Craziness!)
- OnApp Powered Linux & Windows Cloud Hosting [Shared] [Reseller] [Cloud VPS]
- We are LIVE - find out what we are doing for our Post Launch phase!
- Featuring the atOmicSTACK - Speed ● Performance ● Stability ●


Reply With Quote


Sponsored Links
  #2  
Old 09-17-2005, 02:41 AM
Website Rob Website Rob is offline
learning is in the doing
 
Join Date: Sep 2000
Location: Alberta, Canada
Posts: 3,109
Excellent info NexDog, very good info for everyone.

Too many Forms out there that do not have "required field" settings. As most Bots cannot determine
what is 'required', the more required fields the better -- and your script is pretty safe. Another plus is
that people always get Forms filled out with correct information.

__________________
PotentProducts.com - for all your Hosting needs
Helping people Host, Create and Maintain their Web Site
ServerAdmin Services also available

Reply With Quote
  #3  
Old 09-17-2005, 03:28 AM
Philco Philco is offline
WHT Addict
 
Join Date: Jan 2002
Location: London UK
Posts: 139

Reply With Quote
Sponsored Links
  #4  
Old 09-17-2005, 05:21 AM
WireNine WireNine is offline
The Geek is coming
 
Join Date: Aug 2004
Location: Toronto
Posts: 7,102
Thank you for sharing Mr. Laurence

__________________
■█► WireNine.com 8+ years in business!
■█► Shared Hosting, Reseller Hosting and VPS Hosting 24/7 Support 99.9% Uptime 60 Day Money Back Guarantee
■█► cPanel, Litespeed, CloudFlare, Softaculous, Attracta SEO, Site Builder
■█► Find us on Facebook and follow us @wirenine

Reply With Quote
  #5  
Old 09-17-2005, 11:46 AM
georgeolm georgeolm is offline
New Member
 
Join Date: Sep 2005
Posts: 2
Re: PHP FormMail Worm

Quote:
Originally posted by NexDog
It has come to our attention that there is a nasty worm floating around that is compromising many PHP forms.

THE PROBLEM

The problem is that a worm is attacking forms that allow mail headers to entered on forms and then passed to the "mail" function without correct validation.

The most common cause of this is where the "From:" or other header lines are not checked.

An example:
PHP Code:
  $headers 'From: ' $_POST['username'] . '<'$_POST['usermail'] . '>';
  
mail($to$subject$message$headers); 
All the worm needs to do is manipulate the "username" to read:
Code:
  info@yourdomain.com <info@yourdomain.com>\n\rBcc: victim@anotherdomain.com
And the mail will be bcc'd to plenty of others. It can further manipulate the headers to include MIME attachments and, basically, anything it likes.

*******************
THE SYMPTOMS

The current worm uses the domain name as a spoofed "from" e-mail address. At also attacks several fields in one go, you commonly you see a "MIME" header inside the mail.

Snippet of actual mail received (where domain.com is the domain where the form resides):
***********************************

THE PRIORITY FIX

Check anything that is passed as a header and remove \n and \r charcaters from user inputted data.

This can most easily be achieved by (in the above example):
PHP Code:
   ereg_replace(array("\n","\r"),'',$from
Anything passed to the header is at risk - validate the e-mail address, username and, if sending HTML e-mail, practically everything!

NOTE: the double quotes are imporatant.

***********************************

A SUGGESTED ADDITION

It is also suggested that you add validation that the user name does not contain your own domain name or "\n" or "\r". The above fix (which is the important one) will still send an e-mail - just not maliciously as it goes to a non-existant address. Adding code validation will prevent the mail from actually being sent.
Hello all, long time reader, first time poster.

Nex - many should thank you for taking time to post about this, it'll save lots of people lots of headaches. However, there is one important detail you're missing. The exploit can be achieved by crafting a special MESSAGE BODY as well as "from" or other headers. Simply stripping newlines from the body of the message isn't going to work for everyone since newlines are typically valid as part of most messages. One should use regular expressions (eg proper data filtering) on all the fields, including the message (or equiv) field to search for any headers because having a message of something like
----------------------------
bcc: abusedmail@anywhere.com

This is a spammy message
----------------------------

will bypass your check and will result in the exploit being acheived. I hope this helps others. Philco posted a link to an article that explains this better than I can (I'm not allowed to post the link, I have less than 5 posts)

In summary, make sure to use regular expressions on the body of the message to check for anything that can be interpreted as a header, simply checking the "to", "subject" and "from" data is insufficient protection from this vulnerability.

Happy coding!

Reply With Quote
  #6  
Old 09-17-2005, 01:38 PM
Dan L Dan L is offline
Web Developer
 
Join Date: Feb 2003
Location: Connecticut
Posts: 5,441
Great first post, George, never realized that header data could be prepended to a message..

Reply With Quote
  #7  
Old 09-17-2005, 02:20 PM
VolkNet VolkNet is offline
Web Hosting Master
 
Join Date: Jun 2004
Location: Bay Area -USA
Posts: 1,738
Darn we just got blasted with this one our seo site...

Thanks for the heads up!

__________________
<<< Please see Forum Guidelines for signature setup. >>>

Reply With Quote
  #8  
Old 09-17-2005, 04:02 PM
sotet sotet is offline
Junior Guru Wannabe
 
Join Date: Jan 2005
Location: TX
Posts: 77
*

I have been made aware of attacks like this as well just in the past week or so various websites. Basically many people leave old or vulnerable forms online which have been found and exploited by spammmers.

Thanks for the details on the Perl code.

Here is an interesting blog entry about this recent wave of spamming attempts along with a long thread of interesting reader replies.

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


Last edited by sotet; 09-17-2005 at 04:06 PM.
Reply With Quote
  #9  
Old 09-17-2005, 07:22 PM
mwreid mwreid is offline
Newbie
 
Join Date: Aug 2005
Posts: 10
Great information in this thread.

I'm just wondering if it would be better if this thread were moved to either the Technical & Security Issues forum or the Programming Discussion forum.

Those are the places I would look for this type of info, and where I would most likely run a search if I were trying to find this thread in the future.

Reply With Quote
  #10  
Old 09-19-2005, 11:25 AM
sigfrid2000 sigfrid2000 is offline
Newbie
 
Join Date: Sep 2005
Posts: 19
Just what we was looking for! Thanks for sharing with us your usefull experience :-))

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
McAfee Predicts Evolution of Security Threats in 2013 Report Web Hosting News 2012-12-27 15:19:04
Security Provider Websense Discovers Fake Symantec Emails Distributing Malware Web Hosting News 2012-08-29 14:44:19
US Military Weighing New Cyber-Security Powers Web Hosting News 2012-08-13 12:35:54
Web Host Cirrus Tech Deploys ThreatSTOP to Protect Customers from Malware Web Hosting News 2012-04-12 16:14:31
Rogue Certificates, Mobile Banking Attacks Among Top Threats of 2012: McAfee Report Web Hosting News 2011-12-28 21:54:53


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?