<?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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>HEAVYWORKS &#187; Quickies</title>
	<atom:link href="http://www.heavyworks.net/blog/category/quickies/feed" rel="self" type="application/rss+xml" />
	<link>http://www.heavyworks.net</link>
	<description>Extreme Software Engineering</description>
	<lastBuildDate>Fri, 27 Aug 2010 01:55:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Quick-tip: PHP mail() header misuse &#8220;vulnerability&#8221;</title>
		<link>http://www.heavyworks.net/blog/posts/quick-tip-php-mail-header-misuse-vulnerability</link>
		<comments>http://www.heavyworks.net/blog/posts/quick-tip-php-mail-header-misuse-vulnerability#comments</comments>
		<pubDate>Tue, 10 Mar 2009 17:59:36 +0000</pubDate>
		<dc:creator>Jan Seidl</dc:creator>
				<category><![CDATA[Quickies]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[email header]]></category>
		<category><![CDATA[exploiting]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[xss]]></category>

		<guid isPermaLink="false">http://www.heavyworks.net/?p=139</guid>
		<description><![CDATA[When thinking about contact forms in PHP, people use to create a simple form that submits data to a simple script that calls PHP&#8217;s mail function. This function has the following parameters: mail&#40;$recipient, $subject, $message, $headers&#41;; Note the $headers part. Headers are meta information about the message that contains the sender, subject, date sent, CC, [...]


Related posts:<ol><li><a href='http://www.heavyworks.net/blog/posts/alternative-syntax-for-php-control-structures' rel='bookmark' title='Permanent Link: Alternative syntax for PHP control structures'>Alternative syntax for PHP control structures</a></li>
<li><a href='http://www.heavyworks.net/blog/posts/smartly-resolving-your-wordpress-pages-and-posts-javascript-and-css-dependences' rel='bookmark' title='Permanent Link: Smartly resolving your WordPress pages and posts JavaScript and CSS dependences'>Smartly resolving your WordPress pages and posts JavaScript and CSS dependences</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>When thinking about contact forms in <acronym title="PHP: Hypertext Preprocessor">PHP</acronym>, people use to create a simple form that submits data to a simple script that calls <acronym title="PHP: Hypertext Preprocessor">PHP</acronym>&#8217;s <code>mail</code> function.</p>
<p>This function has the following parameters:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$recipient</span><span style="color: #339933;">,</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$message</span><span style="color: #339933;">,</span> <span style="color: #000088;">$headers</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Note the <code>$headers</code> part. Headers are meta information about the message that contains the sender, subject, date sent, <acronym title="Carbon-Copy">CC</acronym>, <acronym title="Blind Carbon-Copy">BCC</acronym>, the recipient name and other stuff that the mail deamons (and anti-spam software) puts and uses to track the email path from sender to recipient.</p>
<p>You may have noticed that I&#8217;ve put the word <em>vulnerability</em> between quotes. Yes, this is <strong>NOT</strong> a <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> function vulnerability but it becomes one when misused.</p>
<p>The fact is that as this function doesn&#8217;t have a <code>$from</code> parameter, people passes this information via the <code>$header</code> parameter as the following example.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$headers</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;From: <span style="color: #006699; font-weight: bold;">{$_POST['name']}</span> &lt;<span style="color: #006699; font-weight: bold;">{$_POST['email']}</span>&gt;&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// &quot;From: SomeUser &lt;jon@doe.com&gt;&quot;</span></pre></div></div>

<p>This is our fail-point: <a href="http://www.php.net/magic_quotes"><acronym title="PHP: Hypertext Preprocessor">PHP</acronym> Magic Quotes</a> &#8220;protected&#8221; people from most XSS input attacks since it escapes quotes and stuff but as headers are separated by newlines (<code>\n</code>), the header can be easily spoofed by inputting:</p>

<div class="wp_syntax"><div class="code"><pre class="email" style="font-family:monospace;">Buy Viagra &lt;xx@xx.com&gt;\nBcc: email1, email2, email3″</pre></div></div>

<p>Note that I&#8217;ve added a <acronym title="Blind Carbon-Copy">BCC</acronym> entry and now the email is going to be sent to the email address specified under <code>$recipient</code> parameter at the <code>mail</code> function AND to my <acronym title="Blind Carbon-Copy">BCC</acronym> entries. </p>
<p><em>&#8220;Congratulations, your e-mail form (and server) is being used now to send my spam&#8221;</em><br />
(Just a quote, Heavyworks&#8217; ethics code would never let me SPAM!)</p>
<p><strong>Solution</strong><br />
Do not forward inputs directly to the header parameter or use a email class like <a href="http://phpmailer.codeworxtech.com/">Codeworx&#8217;s PHPMailer</a>.</p>
<p><em>NOTE: Learn more about e-mail headers at <a href="http://en.wikipedia.org/wiki/Email#Header" title="E-mail Headers">Wikipedia</a></em></p>
<p><em>There is a <a title="Segurança no envio de emails em PHP @ Ataraxia" href="http://www.ataraxia.com.br/posts/seguranca-no-envio-de-emails">Brazillian portuguese version of this vulnerability at Bruno&#8217;s Blog</a></em></p>

<p>Related posts:<ol><li><a href='http://www.heavyworks.net/blog/posts/alternative-syntax-for-php-control-structures' rel='bookmark' title='Permanent Link: Alternative syntax for PHP control structures'>Alternative syntax for PHP control structures</a></li>
<li><a href='http://www.heavyworks.net/blog/posts/smartly-resolving-your-wordpress-pages-and-posts-javascript-and-css-dependences' rel='bookmark' title='Permanent Link: Smartly resolving your WordPress pages and posts JavaScript and CSS dependences'>Smartly resolving your WordPress pages and posts JavaScript and CSS dependences</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.heavyworks.net/blog/posts/quick-tip-php-mail-header-misuse-vulnerability/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
