<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;DE8BRn07fyp7ImA9WhRaE0o.&quot;"><id>tag:blogger.com,1999:blog-5593108060941425908</id><updated>2012-02-16T20:20:57.307+13:00</updated><category term="file upload" /><category term="csrf" /><category term="xsrf" /><category term="html5" /><category term="cors" /><category term="security" /><category term="xhr" /><title>malerisch.net</title><subtitle type="html">Security research, divulgations and food for thought.</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://blog.malerisch.net/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://blog.malerisch.net/" /><author><name>Roberto Suggi Liverani</name><uri>http://www.blogger.com/profile/00603006078110455351</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/Malerisch" /><feedburner:info uri="malerisch" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;DUMCQHk9eyp7ImA9WhRXEks.&quot;"><id>tag:blogger.com,1999:blog-5593108060941425908.post-4832384612549905381</id><published>2011-12-15T22:43:00.001+13:00</published><updated>2011-12-19T17:04:21.763+13:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-19T17:04:21.763+13:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="xhr" /><category scheme="http://www.blogger.com/atom/ns#" term="csrf" /><category scheme="http://www.blogger.com/atom/ns#" term="file upload" /><category scheme="http://www.blogger.com/atom/ns#" term="html5" /><category scheme="http://www.blogger.com/atom/ns#" term="xsrf" /><category scheme="http://www.blogger.com/atom/ns#" term="security" /><category scheme="http://www.blogger.com/atom/ns#" term="cors" /><title>CSRF - File Upload PoC</title><content type="html">&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;A couple of weeks ago I have found myself working on a CSRF File Upload Proof-of-Concept (PoC) for a bug I have found in an Oracle product.&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;I remember that Krzysztof Kotowicz did some research on a similar PoC not long time ago. A quick Google search brought me to his article on &lt;a href="http://blog.kotowicz.net/2011/05/invisible-arbitrary-csrf-file-upload-in.html"&gt;invisible arbitrary file upload&lt;/a&gt; in Flickr. So instead of reinventing the wheel, I have tried to use his PoC code available &lt;a href="https://github.com/koto/blog-kotowicz-net-examples/blob/master/crossdomain-upload/evil/flickr.html"&gt;here&lt;/a&gt;. &lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;Unfortunately, the code was not working in my case and I was unsure whether that was depending on the browsers I was using (Firefox 8.0.1 and Chrome 15.0.874.121) and/or on the vulnerable application itself. Consequently, I have spent some time to come up with a PoC (or probably a good term would be a &lt;/span&gt;&lt;i style="font-family: Arial, Helvetica, sans-serif;"&gt;collage&lt;/i&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;) which would work in my case. The technique used is the same illustrated in Kotowicz's research and more&amp;nbsp;information&amp;nbsp;can be found &lt;/span&gt;&lt;a href="http://blog.kotowicz.net/2011/05/invisible-arbitrary-csrf-file-upload-in.html" style="font-family: Arial, Helvetica, sans-serif;"&gt;here&lt;/a&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;.&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;In few words, the exploitation process is divided in two steps:&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;1) Use XHR to get a binary file and store it as a JavaScript object;&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;2) Then perform a cross-domain XHR POST request (using CORS) to send/upload the binary file to the vulnerable application.&lt;br /&gt;
&lt;br /&gt;
Here is the &lt;a href="https://github.com/malerisch/blog-kotowicz-net-examples/blob/master/crossdomain-upload/evil/upload.html"&gt;PoC&lt;/a&gt;&amp;nbsp;I have composed by taking pieces of code from different parts. For the curios reader, here is the &lt;a href="https://github.com/malerisch/blog-kotowicz-net-examples/commit/c3ecf9e82e968827881c205ef408b328d8fffcb9"&gt;diff&lt;/a&gt; output between my PoC and Kotowicz's one.&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;Following is a short summary of the &lt;i&gt;collage&lt;/i&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Supporting multiple parameters&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
I just reused the same functions in Kotowicz's &lt;a href="https://github.com/koto/blog-kotowicz-net-examples/blob/master/crossdomain-upload/evil/flickr.html"&gt;Flickr PoC&lt;/a&gt; to support multiple POST parameters.&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;i&gt;Grabbing the binary file&lt;/i&gt;&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;I am using snippet code from &lt;a href="http://hublog.hubmed.org/archives/001941.html"&gt;here&lt;/a&gt; - the getBinary() function works fine in the latest Firefox (8.x) and Chrome (15.0.874.121).&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
&lt;i&gt;Blob Type&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;I have integrated sendUpload() function into the fileUpload() one, with a modification around the Blob type, which is used to store the binary file. Below is the modified line:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;var bb = new (window.BlobBuilder || window.WebKitBlobBuilder)();&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;This change was done because Chrome was complaining about the New BlobBuilder data type used in the original sendUpload() function.&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
&lt;b&gt;Further Notes&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;The getBinary() function is used to get the file and considering CRSF occurs from a malicious site, then there are no issues with SOP, as the malicious file is served from the same domain.&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;A minor issue that I encountered during this work was related to single and double quotes in the filename value. In Kotowicz's &lt;/span&gt;&lt;a href="https://github.com/koto/blog-kotowicz-net-examples/blob/master/crossdomain-upload/evil/flickr.html" style="font-family: Arial, Helvetica, sans-serif;"&gt;original PoC&lt;/a&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;, the Content-Disposition: header is set as an "attachment". The filename value is quoted with single quotes. However, in my case the single quotes PoC was not working. I have noticed that Firefox and Chrome automatically&amp;nbsp;quote the filename with double quotes when the upload is performed with user interaction. The excerpt below is from an&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp;intercepted file upload request with Firefox:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;pre class="brush:text; highlight:[16]" name="code" style="font-family: Arial,Helvetica,sans-serif;"&gt;POST /vulnerableappupload HTTP/1.1
Host: apphost
[snip]
Content-Type: multipart/form-data; boundary=---------------------------9040894219264
Content-Length: YYYY

-----------------------------9040894219264
Content-Disposition: form-data; name="extraParam1"

value1
-----------------------------9040894219264
Content-Disposition: form-data; name="extraParam2"

value2
-----------------------------9040894219264
Content-Disposition: form-data; name="filenameId"; filename="test.png"
Content-Type: image/png
[snip]
&lt;/pre&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;However, in some cases, it is possible to&amp;nbsp;successfully&amp;nbsp;upload a file by&amp;nbsp;submitting the filename between single quotes or even without quotes. It depends on the way the file upload application functionality parses the&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;Content-Disposition: header and related values from the browser&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;div style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="font-family: Arial, Helvetica, sans-serif;"&gt;Beside, I also did realise (lately) that there was a more recent PoC&amp;nbsp;&lt;a href="https://github.com/koto/blog-kotowicz-net-examples/commit/d8ec839cefaceb7a0be5a2a201f9b40ed027b0ef"&gt;commit&lt;/a&gt; pushed by Kotowicz which was using the double quotes approach. My bad for missing it, as it would have saved quite some time.&lt;/div&gt;&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;Anyway, I got curios about the single quote/double quote issue and I had checked the &lt;a href="http://www.ietf.org/rfc/rfc2183.txt"&gt;RFC 2813&lt;/a&gt;. It doesn't specify whether the filename value has to be enclosed with single quotes or double quotes, so I am &lt;b&gt;assuming&lt;/b&gt; that depends on the browser. Actually, in the examples included in the RFC 2813, the filename doesn't have quotes at all!&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;For those readers who are more interested, here is a&amp;nbsp;&lt;a href="http://greenbytes.de/tech/tc2231/"&gt;page&lt;/a&gt; including a comprehensive testing conducted against the Content-Disposition header using different browsers.&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;Another minor note should be paid to the boundary value used in the file upload. The boundary in a multipart/byte request is a MIME boundary. This boundary value should not appear anywhere else in the data except between the multiple parts of the data. Also, the boundary value has to be the same to separate each part, so if you intend to reuse the PoC make sure you don't mess with that. I did that resulting in further wasted time :-).&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;b&gt;Constraint&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;The &lt;a href="https://github.com/malerisch/blog-kotowicz-net-examples/blob/master/crossdomain-upload/evil/upload.html"&gt;PoC&lt;/a&gt; would only work for a single step file upload process. If the application requires multiple steps to complete the file upload, then further logic needs to be added to the PoC.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5593108060941425908-4832384612549905381?l=blog.malerisch.net' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Malerisch/~4/DHUuW4fAIts" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.malerisch.net/feeds/4832384612549905381/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.malerisch.net/2011/12/csrf-file-upload-poc.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5593108060941425908/posts/default/4832384612549905381?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5593108060941425908/posts/default/4832384612549905381?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Malerisch/~3/DHUuW4fAIts/csrf-file-upload-poc.html" title="CSRF - File Upload PoC" /><author><name>Roberto Suggi Liverani</name><uri>http://www.blogger.com/profile/00603006078110455351</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://blog.malerisch.net/2011/12/csrf-file-upload-poc.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEABQ3ozeip7ImA9WhRQGUw.&quot;"><id>tag:blogger.com,1999:blog-5593108060941425908.post-4331885285267810446</id><published>2011-12-15T15:39:00.000+13:00</published><updated>2011-12-15T15:39:12.482+13:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-15T15:39:12.482+13:00</app:edited><title>New Blog</title><content type="html">I recently decided to use Blogger.com for my blogging activity. Here is the URL of the new blog:&amp;nbsp;&lt;a href="http://blog.malerisch.net/"&gt;http://blog.malerisch.net&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
All previous articles and research can still be found at my previous site: &lt;a href="http://malerisch.net/"&gt;http://malerisch.net&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
In future, articles will only appear here. So make sure to bookmark this site or follow feeds to get timely updates.&lt;br /&gt;
&lt;br /&gt;
Thanks for your attention.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5593108060941425908-4331885285267810446?l=blog.malerisch.net' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Malerisch/~4/hXBv7YJNYQI" height="1" width="1"/&gt;</content><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5593108060941425908/posts/default/4331885285267810446?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5593108060941425908/posts/default/4331885285267810446?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Malerisch/~3/hXBv7YJNYQI/new-blog.html" title="New Blog" /><author><name>Roberto Suggi Liverani</name><uri>http://www.blogger.com/profile/00603006078110455351</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><feedburner:origLink>http://blog.malerisch.net/2011/12/new-blog.html</feedburner:origLink></entry></feed>

