All of my Drupal sites are sending me webform "replies" from @domain.com I was at another forum website and this topic came up, but not related to Drupal. The general consensus was that it is a result of a vulnerability in the form parsing script used. Do you care to comment on this? The other discussion is here: http://www.webmasterworld.com/forum10/9776.htm

Comments

ullgren’s picture

I'm not really sure what's the problem and I'm not in the mode to sign-up to some webform to find out.
Please copy paste the valid parts of the discussion into this issue.

The webform module uses the sites email address (specified in the site settings, admin -> settings).
If this field is empty the address is specified as "webmail@{$_SERVER['SERVER_NAME']}" that is webmail@www.example.com if ServerName in your httpd.conf is www.example.com.

I've tested both with and without setting the site email setting and I get both user and domain part in the from field of the email messages send by webform submissions. I would suggest that you set your site email adress under the site settings to a valid adress.

If on the other hand your problem is spambots missusing your webforms to send you spam I would suggest setting the permissions of the forms so that only authenticated users may use them.

jo1ene’s picture

You don't have to sign up for anything. I though you may want to glance through the thread in it's entirety (< 30 messages) to see the back and forth on the theories. Besides, the discussion is a hair too technical for me so I'm not sure which messages would help you most. Maybe this? It seems to sum up the problem.

Though I'm a perl coder, I'll chime in here. Been fighting this exact same thing for almost two years.

From what I can glean,

1. This is not executed from your form. Get that well: this is NOT executed from your form. It's either 
sent directly from the command line or from some program. They may initially visit the form to get the
 field names being submitted, but after that they're working on their own, probably from a compromised 
server they've hacked.

2. They can use **ANY** field your mailers process. Many solutions talk about screening the email field,
 but it doesn't matter. The most common approach I see is they use the Subject field to insert newlines
 and a bcc field. They then use the bcc field they create to dump hundreds of aol addresses, usually 
followed by a multipart mime message, complete with their own boundaries.

3. Given the above info, you would think you could stop them by removing any newlines in the mail 
headers. If you have success at this, great, but for whatever reason my attempts at this method have 
failed.

4. Important point to be learned from #2 and #3: even if you disable the "customer copy" and hard-code 
a mailer just to send to ONE address, it doesn't matter. They can use your subject, message, or other 
submitted field to create the BCC and spam addresses.

The only solution I have found is to screen ALL incoming data. ALL. If the following patterns are found

/b*cc\s*:/i ## BCC or CC
/content\-type/i ## This has no place in an email

Log it and immediately exit the program. This avoids other parts of your program being abused.

I put this trap directly into any read/parse routine.

The downside, of course, is if someone enters into the body of the message, "please send a cc: to....." 
the mailing will fail. But it's a good tradeoff because there should be a email field for a legitimate email 
reply address.

I'm sure there are holes in my logic and welcome any comments, but according to my logs this has 
effectively stopped this attack, at least for now. 
If on the other hand your problem is spambots missusing your webforms to send you spam I would
 suggest setting the permissions of the forms so that only authenticated users may use them.

Yes, this is the issue. I could only allow authenticated users to send form responses, which was a prevension method mentioned in the aforementioned thread, but I believe this would cut down on my inquiries. I'm not running a communtity site. And I do, in fact, have my email setting set properly.

ullgren’s picture

Hmm ... yesterday the link you submitted sent me to a "Register for access"-page but today I get the forum.

Thanks for the detailed explination on the matter.

The module have a option to disallow cross-site postings. That is it checks the HTTP_REFERER to check if the post came from the right site. I know this could be forged and a challenge-response approach would be more secure.

As I see it there are two cases this vurnability can be used agains webform. This is when you choose one of the fields to be SUBJECT and FROM address. In this cases these field may be used to insert headers into the email message and should be screened.

All other fields that are recieved from the user is added to the email _body_ and will be ignored by all sensible MTAs (who should ignore all header like information in the body part of the message). So in this perspective I disagree with you that ANY filed may be used to insert header information.

Also in Drupal some header fields (in this case the SUBJECT, TO and FROM addresses) are mime_header_encode() before used for sending the email message. I don't know if this gives any protection but I will investigate further.

jo1ene’s picture

Thanks for taking a look into this. I got hit with two rounds of this in the last four days. I checked my setup and I have the SUBJECT and FROM field set to automatic. Does this contradict your first point?

Your second point seems true because none of these messages have any BODY content. Another site that I manage that is getting hit with this does not use webform and those messages do have BODY content.

BTW, the opinion I posted previously (highlighted) is not my own.

nshb’s picture

One method of fixing this site wide would be to add this to your /modules/user.module
Locate the "function user_mail(.."

function user_mail($mail, $subject, $message, $header) {

And add these lines:

// START - SPAM FILTER
// check if they are spamming using a bcc hack
if (preg_match('/b*cc\s*:/i', $mail)
|| preg_match('/b*cc\s*:/i', $subject)
|| preg_match('/b*cc\s*:/i', $message)
|| preg_match('/b*cc\s*:/i', $header)
) {
return FALSE;
}

// check if they are spamming using a bcc hack
if (preg_match('/content\-type/i', $mail)
|| preg_match('/content\-type/i', $subject)
|| preg_match('/content\-type/i', $message)
|| preg_match('/content\-type/i', $header)
) {
return FALSE;
}
// END - SPAM FILTER

This will break out any email prior to sending a unsolicited spam message.

jo1ene’s picture

Thank you for the tip. I uploaded this code and will report back here on how effective it is.

jo1ene’s picture

So far, so good. I was getting hit every few days, but I haven't been hit in two weeks after adding the code suggested.

ullgren’s picture

Assigned: Unassigned » ullgren
Status: Active » Fixed

Added these checks before calling user_mail.
Fixed in CVS HEAD

joel_guesclin’s picture

I seem to have hit this same problem, however it is not clear to me that this proposed solution will work. I have webform set up so that anonymous users can send e-mail to addresses that do not necessarily correspond to user id's in Drupal. I don't want to oblige users to create a user id just to send an e-mail (especially this is just for first contact - thereafter we correspond using ordinary e-mail, not through the site).

The standard way for avoiding spamming in such cases seems to be using a captcha. I've set this up for login registration on another site and it seems to work ok. What are the chances of incorporating a call to the captcha module (if present) into webform?

I don't mind trying this, though it may take me a bit of time. But in the event that I get it to work, should it be submitted as a patch or through CVS?

jo1ene’s picture

The patch that is being discussed has nothing to do with registering as a user. Before installing it, i was getting hit once every few days. Since I have installed it (almost 6 weeks) i have not gotten hit. So we're assuming it works.

Restricting form access to users was just one proposed solution in an earlier message.

ullgren’s picture

Backported the patch to 4.6

Anonymous’s picture

Status: Fixed » Closed (fixed)