<?xml version="1.0" encoding="utf-8"?>	<rss version="2.0"
		xmlns:content="http://purl.org/rss/1.0/modules/content/"
		xmlns:wfw="http://wellformedweb.org/CommentAPI/"
		xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
	<channel>
		<title>Comments on: Sending spam through contact forms</title>
		<link>http://www.gerd-riesselmann.net/archives/2005/09/sending-spam-through-contact-forms</link>
		<description>Gerd Riesselmann: Notes From the Bog-All Around Objects: C++, .NET, PHP, Design Patterns And More</description>
		<language>en</language>
		<pubDate>Sun, 11 Jun 2006 13:45:29 +0200</pubDate>
		<generator>Drupal TotalFeeds Module</generator>
				<image>
			<title>Comments on: Sending spam through contact forms</title>
			<link>http://www.gerd-riesselmann.net/archives/2005/09/sending-spam-through-contact-forms</link>
			<url>http://www.gerd-riesselmann.net/images/feedbog.png</url>
						<width>130</width>
			<height>80</height>
					</image>
			<item>
		<title>This solution doesn&#039;t apply</title>
		<link>http://www.gerd-riesselmann.net/node/82%2523comment-812</link>
		<description>This solution doesn&#039;t apply to the kind of spamming discussed here, since it is not about getting a set of links published on another one&#039;s web side as it is with comment spam.

Instead, this exploit is about turning a contact-form (or a comment form or actually any form that sends e-mails to whomever) into an open relay, that is: the form is used to send spam e-mails to thousands of other people. 

This spam doesn&#039;t necessary need links, but could also be some plain text. Over here in Germany, for example, the extreme political right does e-mail-spamming capaigns ever once in a while.</description>
		<content:encoded><![CDATA[<p>This solution doesn't apply to the kind of spamming discussed here, since it is not about getting a set of links published on another one's web side as it is with comment spam.</p>
<p>Instead, this exploit is about turning a contact-form (or a comment form or actually any form that sends e-mails to whomever) into an open relay, that is: the form is used to send spam e-mails to thousands of other people. </p>
<p>This spam doesn't necessary need links, but could also be some plain text. Over here in Germany, for example, the extreme political right does e-mail-spamming capaigns ever once in a while.</p>
]]></content:encoded>
		<pubDate>Sun, 11 Jun 2006 13:45:29 +0200</pubDate>
		<dc:creator>Gerd Riesselmann</dc:creator>
		<guid isPermaLink="true">http://www.gerd-riesselmann.net/node/82%2523comment-812</guid>
							</item>
		<item>
		<title>That&#039;s right, but currently</title>
		<link>http://www.gerd-riesselmann.net/node/82%2523comment-96</link>
		<description>That&#039;s right, but currently spammers inject two new lines to all input fields of the forms. With this patch their scritps will need to be smart enough to find the from field, inject bcc there and be careful not to put new lines to other fields as sending will fail. The chances are that they will do this if my patch will be incorporated into PHP, but for a few months this will work. Actually I prefer it not to go to PHP sources, as this way my servers are protected from current spammers tools, and I have no problem maintaining patchsets for PHP as my mail function is already patched to include headers with sender&#039;s domain (I own a hosting company and need to know if my users are sending spam, which with mod_php is not quite possible). For last 10 days before applying the patch to all the servers I have 1000+ mails from AOL and few from SpamCop with complaints that spam was sent from my networks and now it is over. I know it is not a perfect solution, but it works currently, just like graylistig, which is also a working but easy to fool solution. Just warning users that their forms are vulnerable is not an option, there are at least 500 forms on my servers that was used to send spam, many of them are part of softwares like osCommerce (maybe outdated version), that fail to check input data. Convincing a user that he will need to rewrite/upgrade something working (for him) is not that easy, so for now the only solution for me is to try to patch PHP and I can go as far analyzing if part of additional headers came from POST/GET (maybe stripslashed) and to block mail if this part contains new lines - again not a perfect solution but it will work most of the time.

In general maybe it&#039;s a good idea for PHP to start accepting additional headers not only as string but also as an array of strings (and no one of them will be allowed to contain new lines) and to recommend this way of using it. After few versions to put a setting in php.ini that disables the old behavior and after few more versions to make it disabled by default. Checking $to and $subject for new lines should stay.</description>
		<content:encoded><![CDATA[<p>That's right, but currently spammers inject two new lines to all input fields of the forms. With this patch their scritps will need to be smart enough to find the from field, inject bcc there and be careful not to put new lines to other fields as sending will fail. The chances are that they will do this if my patch will be incorporated into PHP, but for a few months this will work. Actually I prefer it not to go to PHP sources, as this way my servers are protected from current spammers tools, and I have no problem maintaining patchsets for PHP as my mail function is already patched to include headers with sender's domain (I own a hosting company and need to know if my users are sending spam, which with mod_php is not quite possible). For last 10 days before applying the patch to all the servers I have 1000+ mails from AOL and few from SpamCop with complaints that spam was sent from my networks and now it is over. I know it is not a perfect solution, but it works currently, just like graylistig, which is also a working but easy to fool solution. Just warning users that their forms are vulnerable is not an option, there are at least 500 forms on my servers that was used to send spam, many of them are part of softwares like osCommerce (maybe outdated version), that fail to check input data. Convincing a user that he will need to rewrite/upgrade something working (for him) is not that easy, so for now the only solution for me is to try to patch PHP and I can go as far analyzing if part of additional headers came from POST/GET (maybe stripslashed) and to block mail if this part contains new lines - again not a perfect solution but it will work most of the time.</p>
<p>In general maybe it's a good idea for PHP to start accepting additional headers not only as string but also as an array of strings (and no one of them will be allowed to contain new lines) and to recommend this way of using it. After few versions to put a setting in php.ini that disables the old behavior and after few more versions to make it disabled by default. Checking $to and $subject for new lines should stay.</p>
]]></content:encoded>
		<pubDate>Fri, 02 Dec 2005 02:10:33 +0100</pubDate>
		<dc:creator>Anton Titov</dc:creator>
		<guid isPermaLink="true">http://www.gerd-riesselmann.net/node/82%2523comment-96</guid>
							</item>
		<item>
		<title>Hey Anton, that&#039;s cool.</title>
		<link>http://www.gerd-riesselmann.net/node/82%2523comment-95</link>
		<description>Hey Anton, that&#039;s cool. Actually the mail() function is definitly the place to stop this kind of attacks. Thumbs up for this!

However, your patch doesn&#039;t cover the full story. The problem lies in the additional headers. Your patch 

&lt;blockquote&gt;
checks ... if additional headers parameter have two subsequent new line characters and in this case trows a warning and do not send the mail.
&lt;/blockquote&gt;

This is still vulnerable, I think. Here&#039;s why:

&lt;ul&gt;
&lt;li&gt;A from field is taken from user input and not verifyed agains injection code.&lt;/li&gt;
&lt;li&gt;User enters &quot;email@example.org%0Abcc: victim@example.org&quot;&lt;/li&gt;
&lt;li&gt;The application generates a header: &quot;from: email@example.org\nbcc: victim@example.org&quot;&lt;/li&gt;
&lt;/ul&gt;

The header is valid, nethertheless the attack was successfull. I myself stumbled upon this, when proposing a &lt;a href=&quot;http://drupal.org/node/34181&quot;&gt;patch for Drupal&lt;/a&gt;.

Unfortunately there is nothing to do against this, except of checking user input before passing it to mail(). I think this is a design flow in the mail() function itself. There really is no reason why the sender can not be passed as a parameter, at least optional. </description>
		<content:encoded><![CDATA[<p>Hey Anton, that's cool. Actually the mail() function is definitly the place to stop this kind of attacks. Thumbs up for this!</p>
<p>However, your patch doesn't cover the full story. The problem lies in the additional headers. Your patch </p>
<blockquote><p>
checks ... if additional headers parameter have two subsequent new line characters and in this case trows a warning and do not send the mail.
</p></blockquote>
<p>This is still vulnerable, I think. Here's why:</p>
<ul>
<li>A from field is taken from user input and not verifyed agains injection code.</li>
<li>User enters "email@example.org%0Abcc: victim@example.org"</li>
<li>The application generates a header: "from: email@example.org\nbcc: victim@example.org"</li>
</ul>
<p>The header is valid, nethertheless the attack was successfull. I myself stumbled upon this, when proposing a <a href="http://drupal.org/node/34181">patch for Drupal</a>.</p>
<p>Unfortunately there is nothing to do against this, except of checking user input before passing it to mail(). I think this is a design flow in the mail() function itself. There really is no reason why the sender can not be passed as a parameter, at least optional.</p>
]]></content:encoded>
		<pubDate>Fri, 02 Dec 2005 00:05:19 +0100</pubDate>
		<dc:creator>Unknown</dc:creator>
		<guid isPermaLink="true">http://www.gerd-riesselmann.net/node/82%2523comment-95</guid>
							</item>
		<item>
		<title>I&#039;ve developed a PHP patch</title>
		<link>http://www.gerd-riesselmann.net/node/82%2523comment-93</link>
		<description>I&#039;ve developed a PHP patch that fixes this at PHP level:

http://www.titov.net/2005/12/01/php-forms-spam/</description>
		<content:encoded><![CDATA[<p>I've developed a PHP patch that fixes this at PHP level:</p>
<p><a href="http://www.titov.net/2005/12/01/php-forms-spam/" title="http://www.titov.net/2005/12/01/php-forms-spam/">http://www.titov.net/2005/12/01/php-forms-spam/</a></p>
]]></content:encoded>
		<pubDate>Thu, 01 Dec 2005 22:08:29 +0100</pubDate>
		<dc:creator>Anton</dc:creator>
		<guid isPermaLink="true">http://www.gerd-riesselmann.net/node/82%2523comment-93</guid>
							</item>
		<item>
		<title>Thanks Alastair, you&#039;re</title>
		<link>http://www.gerd-riesselmann.net/node/82%2523comment-86</link>
		<description>Thanks Alastair, you&#039;re right. I corrected both of them.</description>
		<content:encoded><![CDATA[<p>Thanks Alastair, you're right. I corrected both of them.</p>
]]></content:encoded>
		<pubDate>Tue, 22 Nov 2005 19:25:47 +0100</pubDate>
		<dc:creator>Gerd Riesselmann</dc:creator>
		<guid isPermaLink="true">http://www.gerd-riesselmann.net/node/82%2523comment-86</guid>
							</item>
		<item>
		<title>Also, I notice this, which</title>
		<link>http://www.gerd-riesselmann.net/node/82%2523comment-85</link>
		<description>Also, I notice this, which is just daft (the first line is effectively ignored):

&lt;code&gt;
	$ret = str_replace(&quot;\r&quot;, &quot;&quot;, $value);
	$ret = str_replace(&quot;\n&quot;, &quot;&quot;, $value);
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Also, I notice this, which is just daft (the first line is effectively ignored):</p>
<p><code> 	$ret = str_replace(&quot;\r&quot;, &quot;&quot;, $value); 	$ret = str_replace(&quot;\n&quot;, &quot;&quot;, $value); </code></p>
]]></content:encoded>
		<pubDate>Tue, 22 Nov 2005 12:35:39 +0100</pubDate>
		<dc:creator>Alastair Battrick</dc:creator>
		<guid isPermaLink="true">http://www.gerd-riesselmann.net/node/82%2523comment-85</guid>
							</item>
		<item>
		<title>There is a parse error with</title>
		<link>http://www.gerd-riesselmann.net/node/82%2523comment-84</link>
		<description>There is a parse error with your function. An extraneous semicolon.

Thanks for writing it BTW!</description>
		<content:encoded><![CDATA[<p>There is a parse error with your function. An extraneous semicolon.</p>
<p>Thanks for writing it BTW!</p>
]]></content:encoded>
		<pubDate>Tue, 22 Nov 2005 12:32:42 +0100</pubDate>
		<dc:creator>Alastair Battrick</dc:creator>
		<guid isPermaLink="true">http://www.gerd-riesselmann.net/node/82%2523comment-84</guid>
							</item>
		<item>
		<title>Hello Dave! The thanks go right back for your initial work.</title>
		<link>http://www.gerd-riesselmann.net/node/82%2523comment-58</link>
		<description>Hello Dave! The thanks go right back for your initial work.

I wonder why you are still receiving injected mails through the contact form. Ryan&#039;s code seems OK to me....</description>
		<content:encoded><![CDATA[<p>Hello Dave! The thanks go right back for your initial work.</p>
<p>I wonder why you are still receiving injected mails through the contact form. Ryan's code seems OK to me....</p>
]]></content:encoded>
		<pubDate>Fri, 16 Sep 2005 22:20:14 +0200</pubDate>
		<dc:creator>Gerd Riesselmann</dc:creator>
		<guid isPermaLink="true">http://www.gerd-riesselmann.net/node/82%2523comment-58</guid>
							</item>
		<item>
		<title>Cool! Thanks for turning my scribblings into something more prac</title>
		<link>http://www.gerd-riesselmann.net/node/82%2523comment-57</link>
		<description>Cool! Thanks for turning my scribblings into something more practical. On a side note, there&#039;s an updated WP-Contact Form over on ryan duff&#039;s site. For some reason, I&#039;m still getting weird emails with injected headers...I am not clever enough to figure out how it&#039;s happening...maybe some kind of alternate text encoding is going on.</description>
		<content:encoded><![CDATA[<p>Cool! Thanks for turning my scribblings into something more practical. On a side note, there's an updated WP-Contact Form over on ryan duff's site. For some reason, I'm still getting weird emails with injected headers...I am not clever enough to figure out how it's happening...maybe some kind of alternate text encoding is going on.</p>
]]></content:encoded>
		<pubDate>Fri, 16 Sep 2005 08:29:30 +0200</pubDate>
		<dc:creator>Dave</dc:creator>
		<guid isPermaLink="true">http://www.gerd-riesselmann.net/node/82%2523comment-57</guid>
							</item>
		</channel>
	</rss>
	