<?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>onHacks &#187; Security</title>
	<atom:link href="http://onhacks.org/lang/en/tag/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://onhacks.org</link>
	<description>On Hacking Across Boundaries</description>
	<lastBuildDate>Wed, 02 Jun 2010 05:48:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>A Simple Thought Experiment with MIME</title>
		<link>http://onhacks.org/lang/en/2009/04/23/a-simple-thought-experiment-with-mime</link>
		<comments>http://onhacks.org/lang/en/2009/04/23/a-simple-thought-experiment-with-mime#comments</comments>
		<pubDate>Wed, 22 Apr 2009 16:48:02 +0000</pubDate>
		<dc:creator>log0</dc:creator>
				<category><![CDATA[WebAppSec]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://onhacks.org/?p=330</guid>
		<description><![CDATA[A break from the malware posts. Today I will talk about Content-Type headers, and also why you should make good use of SOP ( Same-Origin-Policy ). This is merely a thought experiment. I have done it only by looking in the HTTP traffic and browsing the webpage. No actual tampering happened. The Oddity Within I [...]]]></description>
			<content:encoded><![CDATA[<p>A break from the <a href="http://onhacks.org/lang/en/2009/04/16/a-glimpse-of-cybercrime-behind-the-great-firewall" target="_self">malware</a> <a href="http://onhacks.org/lang/en/2009/02/08/nature-and-virtual-space" target="_self">posts</a>.</p>
<p>Today I will talk about Content-Type headers, and also why you should make good use of <a href="en.wikipedia.org/wiki/Same_origin_policy">SOP ( Same-Origin-Policy )</a>.</p>
<p>This is merely a thought experiment. I have done it only by looking in the HTTP traffic and browsing the webpage. No actual tampering happened.</p>
<p><strong>The Oddity Within</strong></p>
<p>I am a great fan of web2.0 stuffs. I was walking along a Hong Kong startup called <a href="http://www.foncept.com" target="_blank">FONCEPT</a>, a startup where designers may upload their T-shirts and to sell them, and participate in various competitions. While appreciating the designs, I can&#8217;t help but noticed this odd page :</p>
<blockquote><p><span class="webdeveloper-display-image-paths" title="Src=http://uploads.foncept.com/e742340c-ec9c-11dd-84f3-12313900a097.jpeg">http://www.foncept.com/hk/designs/79</span></p></blockquote>
<p><span class="webdeveloper-display-image-paths" title="Src=http://uploads.foncept.com/e742340c-ec9c-11dd-84f3-12313900a097.jpeg">Notice what is wrong?</span></p>
<p><span class="webdeveloper-display-image-paths" title="Src=http://uploads.foncept.com/e742340c-ec9c-11dd-84f3-12313900a097.jpeg">Look again at the image path.</span></p>
<blockquote><p><span class="webdeveloper-display-image-paths" title="Src=http://uploads.foncept.com/e742340c-ec9c-11dd-84f3-12313900a097.jpeg">http://uploads.foncept.com/Z8GvFzU2WQLd4X2isyFY-203</span></p></blockquote>
<p><span class="webdeveloper-display-image-paths" title="Src=http://uploads.foncept.com/e742340c-ec9c-11dd-84f3-12313900a097.jpeg">The file name has no file extension. Now, look at the Content-Type header.</span></p>
<pre>x-amz-id-2: gfljmNR5XkOBLyPvLxYE+QBmuX6VRrbeU5seR+LI3WqmkIRXBcI1Rvxg8igSwyvn
x-amz-request-id: E458304A7189FC67
Date: Wed, 22 Apr 2009 15:24:43 GMT
x-amz-meta-s3fox-filesize: 54382
x-amz-meta-s3fox-modifiedtime: 1234846282000
Last-Modified: Mon, 02 Mar 2009 11:35:48 GMT
Etag: "b83173007445b85cf8bcef85036bfa72"
<strong>Content-Type: application/x-unknown-content-type</strong>
Content-Length: 54382
Server: AmazonS3

200 OK</pre>
<p><span class="webdeveloper-display-image-paths" title="Src=http://uploads.foncept.com/e742340c-ec9c-11dd-84f3-12313900a097.jpeg">The Content-Type header is used for hinting the browser </span><span class="webdeveloper-display-image-paths" title="Src=http://uploads.foncept.com/e742340c-ec9c-11dd-84f3-12313900a097.jpeg">whether or not to display the contents as HTML, or as Images, or as downloadable attachments, or even launch custom applications. </span><span class="webdeveloper-display-image-paths" title="Src=http://uploads.foncept.com/e742340c-ec9c-11dd-84f3-12313900a097.jpeg">However, the file extension might not be sufficient, as is this case. Images usually have these :</span></p>
<blockquote><p><span class="webdeveloper-display-image-paths" title="Src=http://uploads.foncept.com/e742340c-ec9c-11dd-84f3-12313900a097.jpeg">Content-Type: image/*</span></p>
<p><span class="webdeveloper-display-image-paths" title="Src=http://uploads.foncept.com/e742340c-ec9c-11dd-84f3-12313900a097.jpeg">Content-Type: </span><span class="webdeveloper-display-image-paths" title="Src=http://uploads.foncept.com/e742340c-ec9c-11dd-84f3-12313900a097.jpeg">image/jpg</span></p>
<p><span class="webdeveloper-display-image-paths" title="Src=http://uploads.foncept.com/e742340c-ec9c-11dd-84f3-12313900a097.jpeg">Content-Type: </span><span class="webdeveloper-display-image-paths" title="Src=http://uploads.foncept.com/e742340c-ec9c-11dd-84f3-12313900a097.jpeg">image/gif</span></p>
<p><span class="webdeveloper-display-image-paths" title="Src=http://uploads.foncept.com/e742340c-ec9c-11dd-84f3-12313900a097.jpeg">Content-Type: </span><span class="webdeveloper-display-image-paths" title="Src=http://uploads.foncept.com/e742340c-ec9c-11dd-84f3-12313900a097.jpeg">image/png</span></p></blockquote>
<p><span class="webdeveloper-display-image-paths" title="Src=http://uploads.foncept.com/e742340c-ec9c-11dd-84f3-12313900a097.jpeg">An image having an application type is odd. Adding to the fact that this image is uploaded by user, this seems to be able to fool some browsers into display an image as active content, providing an opportunity for exploitation. </span></p>
<p><span class="webdeveloper-display-image-paths" title="Src=http://uploads.foncept.com/e742340c-ec9c-11dd-84f3-12313900a097.jpeg">In testing with local environment, Internet Explorer 7, using <a href="http://msdn.microsoft.com/en-us/library/ms775107(VS.85).aspx" target="_blank">FindMimeFromData</a>, is susceptible to this attack and happily gets exploited.<br />
</span></p>
<p><strong><span class="webdeveloper-display-image-paths" title="Src=http://uploads.foncept.com/e742340c-ec9c-11dd-84f3-12313900a097.jpeg">The Attack Vector</span></strong></p>
<p><span class="webdeveloper-display-image-paths" title="Src=http://uploads.foncept.com/e742340c-ec9c-11dd-84f3-12313900a097.jpeg">FONCEPT operates by a user uploading an image, and then this image will be approved manually by backend operators. This image will then be resized appropriately and be put up on the website for display. The catch is, what kind of resizing mechanism it is using.</span></p>
<p><span class="webdeveloper-display-image-paths" title="Src=http://uploads.foncept.com/e742340c-ec9c-11dd-84f3-12313900a097.jpeg">Assuming they are using some sort of well-formed library, the headers and attributes of the file should be maintained. We will craft a JPG that has comments header injected with javascript, and this will get executed.</span></p>
<p><span class="webdeveloper-display-image-paths" title="Src=http://uploads.foncept.com/e742340c-ec9c-11dd-84f3-12313900a097.jpeg">Here is an evil image, and you can open it with a text editor and see the script :</span></p>
<blockquote><p><span class="webdeveloper-display-image-paths" title="Src=http://uploads.foncept.com/e742340c-ec9c-11dd-84f3-12313900a097.jpeg">&#60;script&#62;alert(1)&#60;/script&#62;<br />
</span></p></blockquote>
<p><span class="webdeveloper-display-image-paths" title="Src=http://uploads.foncept.com/e742340c-ec9c-11dd-84f3-12313900a097.jpeg">Looks so evil!</span></p>
<p><span class="webdeveloper-display-image-paths" title="Src=http://uploads.foncept.com/e742340c-ec9c-11dd-84f3-12313900a097.jpeg"><img class="aligncenter size-full wp-image-334" title="evil" src="http://onhacks.org/wp-content/uploads/2009/04/evil.jpg" alt="evil" width="200" height="200" /><br />
</span></p>
<p><span class="webdeveloper-display-image-paths" title="Src=http://uploads.foncept.com/e742340c-ec9c-11dd-84f3-12313900a097.jpeg">The steps :</span></p>
<ol>
<li>JPG with comment header injected with javascript code</li>
<li>JPG is uploaded to website for approval</li>
<li>JPG is approved and uploaded to the server</li>
<li>Access JPG through its stored URL through vulnerable browser ( Internet Explorer 7 ).</li>
<li>JPG is rendered as active content ( HTML ), and the script tag and javascript executes!</li>
</ol>
<p>This is an example of an inappropriate MIME issue.</p>
<p><strong>The Good News and the Fix<br />
</strong></p>
<p>Thanks to the SOP, and thanks to the developers are separating the FONCEPT domains into various uploads.foncept.com and www.foncept.com and static.foncept.com , the attack is of much lesser value.</p>
<blockquote><p>Vulnerable : uploads.foncept.com</p>
<p>Valuable contents and cookies : www.foncept.com</p></blockquote>
<p>If uploads.foncept.com domain is not supposed to be render as active content (HTML), it should set the correct Content-Type header for the image files so as to avoid rendering the images as HTML.</p>
<p><strong>The Conclusion</strong></p>
<p>I randomly picked a few later uploaded images and they are appended with the right jpg extensions. If the new uploaded images still take filenames without extensions, and processed as is, then this is still susceptible to the exploit. I did not go into the effort to verify that.</p>
<p>I held a few assumptions in this thought experiment. However, this should be enough to demonstrate if the assumptions held true, will result in a genuine vulnerability by exploiting inappropriate MIME types.</p>
<p>&#8212;</p>
<p>References</p>
<p><a href="http://en.wikipedia.org/wiki/MIME" target="_blank">MIME RFC list</a></p>
<p><a href="http://www.leviathansecurity.com/pdf/Flirting%20with%20MIME%20Types.pdf" target="_blank">Flirting with MIME types</a></p>
]]></content:encoded>
			<wfw:commentRss>http://onhacks.org/lang/en/2009/04/23/a-simple-thought-experiment-with-mime/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>RE : Encryption VS Compression</title>
		<link>http://onhacks.org/lang/en/2009/04/12/re-encryption-vs-compression</link>
		<comments>http://onhacks.org/lang/en/2009/04/12/re-encryption-vs-compression#comments</comments>
		<pubDate>Sun, 12 Apr 2009 14:52:11 +0000</pubDate>
		<dc:creator>log0</dc:creator>
				<category><![CDATA[Email]]></category>
		<category><![CDATA[Protocol]]></category>
		<category><![CDATA[Compression]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://onhacks.org/?p=276</guid>
		<description><![CDATA[LP gave a very good reply to the topic of &#8220;encrypt-and-compress&#8221; or &#8220;compress-and-encrypt&#8221; , and it is worth highlighting here. The reason why compression works is that the plaintext contains redundancy. E.g. there are certain patterns in the text, character frequencies are not uniform, etc. On the other hand, a good encryption algorithm should exhibit [...]]]></description>
			<content:encoded><![CDATA[<p>LP gave <a href="http://onhacks.org/lang/en/2009/01/01/encryption-vs-compression/comment-page-1/#comment-318" target="_blank">a very good reply</a> to the topic of <a href="http://onhacks.org/lang/en/2009/01/01/encryption-vs-compression/" target="_blank">&#8220;encrypt-and-compress&#8221; or &#8220;compress-and-encrypt&#8221;</a> , and it is worth highlighting here.</p>
<blockquote><p>The reason why compression works is that the plaintext contains redundancy. E.g. there are certain patterns in the text, character frequencies are not uniform, etc.</p>
<p>On the other hand, a good encryption algorithm should exhibit good diffusion and confusion. In short, it means that encrypted data should be indistinguishable from random noise. It is obvious that this property should hold regardless of the plaintext, otherwise the encryption algorithm is broken.</p>
<p>Therefore, compress-and-encrypt produces smaller output with no security compromise per se, but encrypt-and-compress is like feeding random noise (whose redundancy is greatly reduced) into the compression algorithm with no obvious security benefit.</p></blockquote>
<p>In short, encrypt-and-compress poses no obvious security benefit. Moreover, given that a good compression algorithm should be like real noise, and should not contain pattern, it follows that there will be no obvious storage benefit, either.</p>
]]></content:encoded>
			<wfw:commentRss>http://onhacks.org/lang/en/2009/04/12/re-encryption-vs-compression/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
