<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>An Autonomous Zone</title>
	<atom:link href="http://anautonomouszone.com/blog/feed" rel="self" type="application/rss+xml" />
	<link>http://anautonomouszone.com/blog</link>
	<description>An autonomous zone to promote an exchange of ideas, skills, and experiences with computer (in)security.</description>
	<lastBuildDate>Thu, 09 Apr 2009 23:23:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Grendel-Scan</title>
		<link>http://anautonomouszone.com/blog/archives/26</link>
		<comments>http://anautonomouszone.com/blog/archives/26#comments</comments>
		<pubDate>Thu, 09 Apr 2009 18:19:05 +0000</pubDate>
		<dc:creator>Chuck B.</dc:creator>
				<category><![CDATA[Web App Hacking]]></category>

		<guid isPermaLink="false">http://anautonomouszone.com/blog/?p=26</guid>
		<description><![CDATA[Grendel-Scan is a new(ish) web application scanner that a friend of mine is writing. One of the cool things that I like about Grendel is it&#8217;s Cross Site Scripting (XSS) vulnerabilitiy detection.
The way David approached the XSS vulnerability scanning cuts down on the amount of requests being made to the web application as well as [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.grendel-scan.com/">Grendel-Scan</a> is a new(ish) web application scanner that a friend of mine is writing. One of the cool things that I like about Grendel is it&#8217;s Cross Site Scripting (XSS) vulnerabilitiy detection.</p>
<p>The way David approached the XSS vulnerability scanning cuts down on the amount of requests being made to the web application as well as the number of false positives as compared to other scanners that I&#8217;ve checked out.</p>
<p>Like all web application scanners when trying to detect non-persistent XSS Grendel substitutes a known parameter value for a value that includes javascript code. As mentioned in my previous posts it might change something like this:</p>
<p>param=123</p>
<p>to something like this:</p>
<p>param=123/&gt;&lt;SCRIPT&gt;alert(’XSS’);&lt;/SCRIPT&gt;</p>
<p>Generally when the scanner sees the signature included in the response (/&gt;&lt;SCRIPT&gt;alert(’XSS’);&lt;/SCRIPT&gt; in the above example) then they’ll flag it as a possible XSS vulnerability.</p>
<p>Now for the most part a web app scanner will have many, many different XSS signatures (different javascript-type parameter substitution values) that it will try on a particular parameter value. For instance, for the sake of thoroughness a web app scanner might have 40+ different XSS signatures that it will try for each and every parameter that it records going to the application to detect XSS.</p>
<p>Like I mentioned most scanners are extremely inefficient and noisy in the sense that they&#8217;ll continue to submit as many requests as there are XSS signatures until it flags a particular request as being vulnerable to non-persistent XSS. So if there are 53 XSS signatures a typical scanner will submit 53 requests per parameter (again, unless it flags a request within the 53 signatures that it sends as being vulnerable).</p>
<p>If you&#8217;re scanning an application that has a lot of parameter values (like hundreds or thousands) being sent in a request, as most applications do, this can end up being a lot of traffic being sent to the application being scanned.</p>
<p>If you&#8217;re scanning a staged or development environment this usually isn&#8217;t too much of a concern but if you&#8217;re scanning a production environment &#8211; this can cause concerns. One of the biggest problems with sending out all of the XSS signatures per parameter in an application (besides bandwidth and resource saturation) is form submissions that generate emails. For certain form submissions on a number of applications, such as a &#8220;Contact Us&#8221; form the submission information is emailed to a particular person or persons within the organization who is in control of the application. This generates one email per request sent to the particular form.</p>
<p>This means if you have a form that has 10 parameters and your app scanner has 53 XSS signatures you&#8217;ll have at around 530 emails being sent to someone &#8211; keeping in mind this is only for XSS detection. You&#8217;re likely to have a whole lot more submissions being sent and emailed to someone when you&#8217;re scanner is looking for other issues like SQL injection vulnerabilities, CRLF vulnerabilities, directory traversal vulnerabilities, etc. At the end of the scan it&#8217;s very, very possible someone will open their mailbox and have thousands of junk emails from scanning the site.</p>
<p>So &#8211; what does David do different when discovering XSS with Grendel? Before throwing each XSS signature at every parameter Grendel will first send a random value  (a token) as a parameter value with a fixed 4 digit prefix (keep in mind that in order for an application to be vulnerable to non-persistent XSS it first has to echo back the parameter value in the response).</p>
<p>So it&#8217;d be something like this:</p>
<p>param=fds5fds34</p>
<p>Each response is searched for the prefix. The fixed four digit prefix (fds5) doesn&#8217;t change throughout the scan &#8211; which makes it easier to look for tokens in responses. If the prefix is found then the six characters following it are looked up (that way you don&#8217;t have to search for every token in the response).</p>
<p>If Grendel sees the token being returned in a response only then will it continue to send the XSS attack signatures. This cuts down on the amount of &#8220;useless&#8221; XSS attack signature requests being made to the web server. If the application doesn&#8217;t echo back a token value &#8211; then it&#8217;s not going to be vulnerable to non-persistent XSS in the first place.</p>
<p>Not only is this a lot better for production sites, it cuts down on scanning time because less meaningless requests are being sent to the application.</p>
<p>Another thing that David has done to reduce false positives with XSS is he&#8217;s implemented the Rhino javascript engine from Mozilla into his scanner. This way a XSS vulnerabilitiy is cataloged with Grendel only if the response triggers the javascript engine to fire.</p>
<p>This cuts down on XSS false positives tremendously. As a neat bonus he&#8217;s included a module called input/output flow that records any request that responds with a token value &#8211; just in case there is a posibilitiy of a XSS issue being present but the supplied XSS attack signatures was not able to trigger the javascript engine.</p>
<p>Grendel was released at DEFCON last year and becuase of his hectic work schedule he hasn&#8217;t updated it much in the last few months but I hear he (and a few others) are working on it now and should have a new release really soon.</p>
<p>You can find it here: <a href="http://www.grendel-scan.com/">http://www.grendel-scan.com/</a></p>
<p>Cheers,</p>
<p>ChuckB.</p>
]]></content:encoded>
			<wfw:commentRss>http://anautonomouszone.com/blog/archives/26/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Pai Mei Beginnings</title>
		<link>http://anautonomouszone.com/blog/archives/24</link>
		<comments>http://anautonomouszone.com/blog/archives/24#comments</comments>
		<pubDate>Tue, 15 Jul 2008 14:19:40 +0000</pubDate>
		<dc:creator>Chuck B.</dc:creator>
				<category><![CDATA[Reversing]]></category>

		<guid isPermaLink="false">http://anautonomouszone.com/blog/?p=24</guid>
		<description><![CDATA[I&#8217;ve been meaning to play with Pai Mei for a while &#8211; and I&#8217;m a little late for hopping on the bandwagon for this great framework.
However, better late than never. In the last couple of days I finally installed it on a box and I&#8217;m in the process of screwing around it and trying to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been meaning to play with Pai Mei for a while &#8211; and I&#8217;m a little late for hopping on the bandwagon for this great framework.</p>
<p>However, better late than never. In the last couple of days I finally installed it on a box and I&#8217;m in the process of screwing around it and trying to learn some of its really cool and useful features.</p>
<p>One of the things that I&#8217;d like to do with Pai Mei is integrate it (pstalker) into my fuzzing program so I can measure code coverage when fuzzing. This is really nothing new, but I think it&#8217;ll help out my fuzzing program a lot that I have going on.</p>
<p>While trying to learn about Pai Mei and while installing it I came across some tutorials written by <a title="http://ricardonarvaja.googlepages.com/" href="http://ricardonarvaja.googlepages.com/">Ricardo Narvaja</a>. I came across them on <a title="http://www.woodmann.com/forum/archive/index.php/t-10851.html" href="http://www.woodmann.com/forum/archive/index.php/t-10851.html">woodman&#8217;s RCE forums</a>. These are really cool because there&#8217;s not too much as far as how-to&#8217;s or tutorials on using Pai Mei. His tutorials have been really useful to me even though they are in Spanish&#8230;</p>
<p>So I decided to do a bit of translating on them (just using google translate) and they came out sort of decent. One that doesn&#8217;t know Spanish could pretty much follow along using a bit of common sense, the google translation, and by looking at the screenshots and examples.</p>
<p>I&#8217;ve posted them <a title="tutorials" href="http://anautonomouszone.com/blog/tutorials">here</a>.</p>
<p>BTW &#8211; Ricardo, you kick ass, and thanks for your contributions to the community.</p>
<p>Cheers,</p>
<p>Chuck B.</p>
]]></content:encoded>
			<wfw:commentRss>http://anautonomouszone.com/blog/archives/24/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More on Web App Scanners</title>
		<link>http://anautonomouszone.com/blog/archives/22</link>
		<comments>http://anautonomouszone.com/blog/archives/22#comments</comments>
		<pubDate>Mon, 14 Jul 2008 04:52:30 +0000</pubDate>
		<dc:creator>Chuck B.</dc:creator>
				<category><![CDATA[Web App Hacking]]></category>

		<guid isPermaLink="false">http://anautonomouszone.com/blog/?p=22</guid>
		<description><![CDATA[In a previous post I talked a bit about NTOSpider, how it was &#8220;o.k.&#8221; with what it did, and how I was generally disappointed overall in the effectiveness of web app scanners in the market. As a matter of fact, Caleb Sima (founder and CTO of SPI Dynamics) actually had a couple of good points [...]]]></description>
			<content:encoded><![CDATA[<p>In a previous <a title="http://anautonomouszone.com/blog/archives/16#more-16" href="http://anautonomouszone.com/blog/archives/16#more-16">post</a> I talked a bit about NTOSpider, how it was &#8220;o.k.&#8221; with what it did, and how I was generally disappointed overall in the effectiveness of web app scanners in the market. As a matter of fact, Caleb Sima (founder and CTO of SPI Dynamics) actually had a couple of good points in a comment he left on that one.</p>
<p>I figured it was a bold statement when I said &#8220;I mean to build a web app scanner generally isn’t rocket science,&#8221; and I thought it might ruffle the feathers of some who have vested time into a really robust web app scanner project. Now, I&#8217;m sure that Caleb didn&#8217;t get too bothered by my post &#8211; but his response included the following &#8220;&#8230;at the surface it may seem like that but there is nothing farther from the truth. It is one of the most complicated pieces of technology I have ever had to deal with. Its not as simple as parsing out HREFs and sticking single quotes in params.&#8221;</p>
<p>He was referring to a scanner I <a title="http://www.gdssecurity.com/l/t/extendedscanner.zip" href="http://www.gdssecurity.com/l/t/extendedscanner.zip">referenced</a> in sentence I wrote: &#8220;There’s actually a really good how-to write your own web app scanner in the O’Reilly book “Network Security Tools, Writing, Hacking, and Modifying Security Tools.” The code for that one is available <a title="http://www.gdssecurity.com/l/t/extendedscanner.zip" href="http://www.gdssecurity.com/l/t/extendedscanner.zip">here</a>.&#8221; Which pretty much does &#8211; just what Caleb said it does &#8211; not too much. It&#8217;s simple and limited, but the right basic theory is there for a good and solid web app scanner.</p>
<p>Before I break all this down and go on &#8211; let me first say that I don&#8217;t think there&#8217;s an automated solution on the market (and there likely won&#8217;t ever be) that can find every vulnerability in your web application. There are things that scanners are good at picking up, input validation problems like xss and sql injection, directory listing stuff, CRLF injection, etc. And there are things that they aren&#8217;t too good at picking up, like logic based errors which grant you some sort of privilege escalation or give you access to something you shouldn&#8217;t have &#8211; like a sensitive file (the scanner might not know that you shouldn&#8217;t have access to that file) that is specific to that custom application.</p>
<p>Another metric that is typically used when judging the effectiveness of an automated web app scanner besides how well it finds vulnerabilities (and how many vulnerabilities it finds) is application coverage when crawling a site. For instance, when you are looking for vulnerabilities in an application you want to make sure that you&#8217;re looking at all of the pages and/or functionality of the application. If you (or the automated crawling functionality of a scanner) miss parts of the application and those parts of the application don&#8217;t get tested &#8211; then that&#8217;s a problem. Therefore, I always like to have a two-pronged approach when blackbox testing. I like to crawl the site manually <strong>and </strong>have a good crawler hit the application and feed the requests to a scanner, that way if one method misses something &#8211; hopefully the other method will have picked it up &#8211; this way we can be sure we&#8217;re maximizing application coverage to the best of our ability.</p>
<p>That being said &#8211; I don&#8217;t think that testing web apps should ever be an automated <strong>or</strong> manual kind of a process, but more of an automated <strong>and</strong> manual kind of a process (that is, if you really care about the overall security posture of your application). I don&#8217;t think there&#8217;s too many experienced web app pentesters out there who would disagree with me on that one.</p>
<p>However, let&#8217;s focus on some things that web app scanners are good at, like finding XSS and SQL injection vulnerabilities &#8211; and talk about possible tools (scanners) that one might use to accomplish this (for free). And with a little modification to these free tools, such as incorporating some of the concepts discussed below, one could possibly garnish better/more results (XSS, SQL injection vulnerabilities being identified) than some scanners out there that cost you thousands of dollars.</p>
<p>So going back to what I think scanners are good at, like fuzzing parameter values to look for things like XSS and SQL injection problems.</p>
<p>First off, the basic and fundamental way web app scanners work &#8211; is they essentially send a request to the application, then they look at a response to see if the request the scanner made affected the application in some way and made it send something back that it shouldn&#8217;t have (in a way that could be a potential security problem or vulnerability).</p>
<p>I&#8217;ll talk about a few examples that are probably the two most common (and arguably the highest impact) vulnerabilities in web applications that most scanners look for, XSS and SQL injection.</p>
<p>Let&#8217;s talk about XSS &#8211; the basic (easy, yet effective) way most scanners look for XSS is they send a request to the web server &#8211; and they replace or add on to the original value of the parameter with some potential javascript code &#8211; then see if it gets echoed back in a response. For example, a scanner might change something like this:</p>
<p>param=123</p>
<p>to something like this:</p>
<p>param=123&#8243;/&gt;&lt;SCRIPT&gt;alert(&#8217;XSS&#8217;);&lt;/SCRIPT&gt;</p>
<p>Then they simply perform a regex on the response looking for /&gt;&lt;SCRIPT&gt;alert(&#8217;XSS&#8217;);&lt;/SCRIPT&gt;. If they see it &#8211; then they&#8217;ll flag it as a possible XSS vulnerability. Really not too hard.</p>
<p>Now there are some applications or web app firewalls that filter things like &lt;SCRIPT&gt;, &lt;IMG&gt;, etc. so what you can do is add say, RSnake&#8217;s <a title="http://ha.ckers.org/xss.html" href="http://ha.ckers.org/xss.html">XSS list for filter evasion</a> (a list of signatures) to what your scanner adds or substitutes for parameter values. Simply cycle through that list of signatures until (if and when) you come across one that gets echoed back in a response. RSnake&#8217;s cheat sheet can be used as a starter for signatures. As you play with web apps more and become more acquainted with filter evasion and XSS you can just add those to your list of signatures in your scanner.</p>
<p>Now I do have a friend who is working on a scanner that is a bit more sophisticated in detecting XSS, in that  it will eliminate false positives and cut down on the number of overall requests (like not having to cycle through the whole list of XSS signatures on every parameter being submitted to the web application). But I told him I won&#8217;t talk about it too much until after he releases it at Def Con. However, even though his technique is more efficient &#8211; the above technique is what 99% of web app scanners do when looking for XSS &#8211; and this method works quite well, even though for some reason &#8211; there&#8217;s a lot of expensive web app scanners out there that can&#8217;t even get this part right, and manage to screw this part up somehow.</p>
<p>SQL injections are a little more complicated to look for in a scanner, but not much &#8211; remember, this isn&#8217;t rocket science.</p>
<p>There&#8217;s basically two different kind of SQL injections &#8211; regular (verbose database messages) and blind SQL injections.</p>
<p>To check for regular or verbose SQL injections &#8211; you send a request, like using a single tick ( &#8216; ) as a parameter value, or at the end of a parameter value and look for the response.</p>
<p>Using our example of param=123 we might substitute the original value for something like paramm=123&#8242;1</p>
<p>If you get some database error message like this in the response then chalk it up as a possible SQL injection:</p>
<p>Microsoft OLE DB Provider for ODBC Drivers error</p>
<p>So there could be different back end databases that they might be using so you might want to look for other error messages from different databases other than MSSQL like Oracle, IBM DB2, MS Access, PostgreSQL, MySQL, etc.</p>
<p>Also, we could try different encoding on our single ticks like CHAR(39), 0xbf27, amongst others.</p>
<p>Besides single quotes (or ticks) we can also try to sneak in things like semi-colons ( ; ) and double dashes ( &#8212; ) and their encoded equivalents to try and generate database error messages.</p>
<p>Blind SQL injections are a little bit different beast in that we don&#8217;t just regex a response looking for a database error message, but rather we look for a change in behavior of some sort from the application.</p>
<p>There are basically two different types of blind SQL injections &#8211; conditional and time delays.</p>
<p>We&#8217;ll cover how to test both really quick.</p>
<p>For the time delay blind SQL injection detection you simply add something like this to the original parameter value:</p>
<p>&#8216;;WAITFOR+DELAY+&#8217;0:0:10&#8242;&#8211; (MSSQL)</p>
<p>This tells the SQL backend to wait for ten seconds before responding. So a way to implement this in a scanner is you make a regular (non-fuzzed) request with no &#8220;waitfor delay&#8221; manipulation in the parameter value, then you calculate the time it took to make a regular request (let&#8217;s say it takes 950ms). Then, go ahead and send the time delay fuzzed parameter value (such as param=123&#8242;;WAITFOR+DELAY+&#8217;0:0:10&#8242;&#8211;). If you get a response right away &#8211; then, mark the parameter as not vulnerable, if you get a response from the webserver that took 10 seconds or later (you can calculate in the time it takes for the request such as the 950ms) then you can mark that as being a possible time based SQL injection vulnerability.</p>
<p>One can also use other time based queries for different databases other than MSSQL, such as the following:</p>
<p>SELECT pg_sleep(10); (PostgreSQL)</p>
<p>BENCHMARK() function (MySql)</p>
<p>Also &#8211; we could try adding parenthesis and such to escape from SQL subqueries like the following:</p>
<p>param=123;waitfor+delay+&#8217;0:0:10&#8242;&#8211;<br />
param=123);waitfor+delay+&#8217;0:0:10&#8242;&#8211;<br />
param=123&#8242;;waitfor+delay+&#8217;0:0:10&#8242;&#8211;<br />
param=123&#8242;);waitfor+delay+&#8217;0:0:10&#8242;&#8211;<br />
param=123));waitfor+delay+&#8217;0:0:10&#8242;&#8211;<br />
param=123&#8242;));waitfor+delay+&#8217;0:0:10&#8242;&#8211;</p>
<p>Also &#8211; we would want to try the encoded equivalents of semi-colons (%3B), dashes (%2D), plus signs (%2B), etc. with all of these queries.</p>
<p>Next, we have conditional blind SQL injection vulnerabilities to hunt for. For this type of SQL injection vulnerability identification the scanner must also look for some behavioral change from the application.</p>
<p>According to <a title="http://www.webappsec.org/projects/threat/classes/sql_injection.shtml" href="http://www.webappsec.org/projects/threat/classes/sql_injection.shtml">webappsec.org</a> the following is how to detect blind conditional SQL injection vulnerabilities:</p>
<p><em>A common way to detect Blind  SQL Injection is to put a false and true statement into the parameter  value.</em></p>
<p><em>Executing the following request to a web site:</em></p>
<p><em>http://example/article.asp?ID=2+and+1=1</em></p>
<p><em>should return the same web page as:</em></p>
<p><em>http://example/article.asp?ID=2</em></p>
<p><em>because the SQL statement &#8216;and 1=1&#8242; is always true.</em></p>
<p><em>Executing the following request to a web site:</em></p>
<p><em>http://example/article.asp?ID=2+and+1=0</em></p>
<p><em>would then cause the web site to return a friendly error or no page at  all. This is because the SQL statement &#8220;and 1=0&#8243; is always false.<br />
</em></p>
<p>They&#8217;re not far off, by issuing a series of true/false type queries in a request (parameter value) then we can see if there is any difference behaviorally with the application &#8211; sometimes in a &#8220;false&#8221; query you get an error page, sometimes other types of changes in the response.</p>
<p>Easy enough, so for a scanner we can just do something like the following:</p>
<p>param=123&#8242; and &#8216;1&#8242;=&#8217;1</p>
<p>and</p>
<p>param=123&#8242; and &#8216;1&#8242;=&#8217;2</p>
<p>If we get a different page for each response &#8211; then we could chalk that up as being a possible vulnerability and worthy of looking into.</p>
<p>We could also use different true/false queries such as:</p>
<p>param=123&#8242; or &#8216;a&#8217;='a</p>
<p>param=123&#8242; or &#8216;a&#8217;='b</p>
<p>or even better, just substitute some random string for &#8216;a&#8217; and another random string for &#8216;b.&#8217;</p>
<p>There are other things &#8211; that one could look for in (and add to) a web app scanner such as command injection, directory traversal attacks, CRLF injection, CSRF, session problems like session fixation, etc. but, again &#8211; it&#8217;s all fundamentally based on the concept of making a request to the application, then checking the  response to see if the request the scanner made affected the application in some way and made it send something back that it shouldn&#8217;t have (in a way that could be a potential security problem or vulnerability).</p>
<p>I did mention that there was something out there that one could get for free that is a really good starting point for a good scanner. Here it is: <a title="http://www.securitytechscience.com/resources/sts-scanner.php" href="http://www.securitytechscience.com/resources/sts-scanner.php">sts-scanner</a>. It is pretty limited in it&#8217;s functionality &#8211; much like the original ExtendedScanner, as a matter of fact it&#8217;s based on the ExtendedScanner. But with a few tweaks &#8211; like adding some more XSS signatures and adding some of the SQL injection scanning logic mentioned above (it already includes some of it, plus things like column enumeration when it finds a sql injection) &#8211; I would put money on it against any of the expensive (or non-free) web app scanners out there when it came to looking for things that it was designed to look for.</p>
<p>Cheers,</p>
<p>Chuck B.</p>
]]></content:encoded>
			<wfw:commentRss>http://anautonomouszone.com/blog/archives/22/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Windows Messaging and Shatter Attacks</title>
		<link>http://anautonomouszone.com/blog/archives/21</link>
		<comments>http://anautonomouszone.com/blog/archives/21#comments</comments>
		<pubDate>Tue, 08 Jul 2008 20:50:35 +0000</pubDate>
		<dc:creator>Chuck B.</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://anautonomouszone.com/blog/?p=21</guid>
		<description><![CDATA[I was chatting a while ago about Windows Messaging with someone and the pitfalls associated with it.
So – if one is unfamiliar with Windows Message Handling here’s a decent brush-up:
http://www.codeproject.com/KB/dialog/messagehandling3.aspx
BTW – the following is pretty much taken from toassa (like one of the best tech books ever written): http://taossa.com/
Essentially – Windows OS’s deliver messages to [...]]]></description>
			<content:encoded><![CDATA[<p>I was chatting a while ago about Windows Messaging with someone and the pitfalls associated with it.</p>
<p>So – if one is unfamiliar with Windows Message Handling here’s a decent brush-up:</p>
<p><a title="http://www.codeproject.com/KB/dialog/messagehandling3.aspx" href="http://www.codeproject.com/KB/dialog/messagehandling3.aspx">http://www.codeproject.com/KB/dialog/messagehandling3.aspx</a></p>
<p>BTW – the following is pretty much taken from toassa (like one of the best tech books ever written): <a title="http://taossa.com/" href="http://taossa.com/">http://taossa.com/</a></p>
<p><em>Essentially – Windows OS’s deliver messages to windows in a FIFO queue. Messages can be generated by system events like mouse movements or key presses. They can also be generated by other threads on the same desktop. Windows messages control most aspects of the UI, including clipboard operations and properties of a window.</em></p>
<p><em>There are 4 essential steps in creating a functional windowed application:</em></p>
<p><em>1. Creating a WindowProc() function to handle messages.<br />
2. Defining a class that associates this WindowProc() to a window type.<br />
3. Creating an instance of the Window class.<br />
4. Creating a message-processing loop.</em></p>
<p>Anyways, any process with a handle to a window station can send messages to any other window on a desktop object within that window station (any process can send a message to any other desktop object on the same desktop). All that’s needed is a SendMessage() function.</p>
<p>LRESULT SendMessage (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);</p>
<p>So this brings us to shatter attacks.</p>
<p><em>The Windows API ties a lot of functionality into a simple, unprotected, messaging architecture. Every aspect of the user interface is controlled by window messages, and the design of the API provides no method of restricting or verifying a message source.</em></p>
<p>The original shatter attack from 2002 &#8211; Chris Paget&#8217;s paper titled, &#8220;<a title="http://web.archive.org/web/20060115174629/http://security.tombom.co.uk/shatter.html" href="http://web.archive.org/web/20060115174629/http://security.tombom.co.uk/shatter.html">Exploiting design flaws in the Win32 API for privilege escalation</a>&#8220;) exploited window message design by sending a WM_PASTE message to a privileged process with a message pump on the same window station. The WM_PASTE message allows attackers to place a buffer of shell code in the address space of the privileged process. The attack is then completed by sending a WM_TIMER message that includes the address of the shell code buffer. The default handler for the WM_TIMER message simply accepts the address parameter as a function pointer, then runs the code that it points to. The result is a straightforward privilege escalation.</p>
<p>The immediate response to the shatter vulnerability was to simply filter the WM_TIMER message in any privileged process interacting with a user’s desktop. However, there are many other messages that allow manipulation of memory in a target process.</p>
<p>In 2004 Brett Moore had a talk at BlackHat about this:</p>
<p><a title="http://www.blackhat.com/presentations/bh-usa-04/bh-us-04-moore/bh-us-04-moore-up.ppt " href="http://www.blackhat.com/presentations/bh-usa-04/bh-us-04-moore/bh-us-04-moore-up.ppt ">http://www.blackhat.com/presentations/bh-usa-04/bh-us-04-moore/bh-us-04-moore-up.ppt </a></p>
<p>For instance, according to his <a title="http://www.blackhat.com/presentations/bh-usa-04/bh-us-04-moore/bh-us-04-moore-whitepaper.pdf" href="http://www.blackhat.com/presentations/bh-usa-04/bh-us-04-moore/bh-us-04-moore-whitepaper.pdf">whitepaper</a>: <em>Previous shatter attacks have been based on the use of messages that accept a pointer as a parameter. This pointer deirects execution flow to data that has been supplied by the attacer, therefore allowing the attacker to have a process execute code of their choice.</em></p>
<p><em>Several windows message will accept a pointer to a callback function as one of the parameters to the SendMessage API. One of these is LVM_SORTITEMS&#8230;</em></p>
<p>He also mentions messages like HDM_GETITEMRECT, <em>which accepts a pointer to a POINT or RECT structure which will be used to retrieve GDI information about windows. These pointers do not appear to be validated in any way&#8230;<br />
</em></p>
<p>Also &#8211; he has an exploit that demonstrates the use of Progress Control message shatter attacks and discusses other vulnerable messages that can come in handy to exploit.</p>
<p>As a matter of fact, he discovered a more recent vulnerability in a Symantec product using a Shatter Attack (Feb. 2008):</p>
<p><a title="http://www.securityfocus.com/bid/27645 " href="http://www.securityfocus.com/bid/27645 ">http://www.securityfocus.com/bid/27645 </a></p>
<p>For someone looking at the code of the program,  toassa summarizes the following steps to identify potential shatter attack exposures for a given service:</p>
<p><em>1. Check the MMC snap-in for the service to see whether it runs as the interactive user. Use MMC -&gt; open the Properties dialog box for the service -&gt; check the “Log On” tab to see whether the “Allow Service to Interact with Desktop” option is selected.</em></p>
<p><em>2. Examine the code to determine whether it manually attaches to the interactive user’s desktop.</em></p>
<p><em>3. If either case is true, determine whether a message pump is in operation for receiving window messages. If a message pump is in operation, you can consider the application to be at risk.</em></p>
<p>Also, according to my favorite reference &#8211; <a title="http://taossa.com/" href="http://taossa.com/">taossa</a>, certain COM applications can create background messages windows which can be vulnerable as well.</p>
<p>In Brett Moore’s Blackhat 2004 <a title="http://www.blackhat.com/presentations/bh-usa-04/bh-us-04-moore/bh-us-04-moore-up.ppt " href="http://www.blackhat.com/presentations/bh-usa-04/bh-us-04-moore/bh-us-04-moore-up.ppt ">preso</a> (which I also cited earlier) he also makes references to attacking thick applications on windows using shatter attacks – which will probably hit home a lot more for people who don&#8217;t do too much testing on traditional C/C++ programs.</p>
<p>Now Microsoft has done certain things to try to stop shatter attacks over the years – from Wikipedia “<em>In December 2002, Microsoft issued a patch for Windows NT 4.0, Windows 2000, and Windows XP that closed off some avenues of exploitation. This was only a partial solution, however, as the fix was limited to services included with Windows that could be exploited using this technique;</em>”</p>
<p>Also – they did some stuff with Vista using User Interface Privilege Isolation (UIPI).</p>
<p>So most of the vulnerable programs will be third-party applications.</p>
<p>Really – the most devastating scenario that I can think of – and probably the most common is someone with “normal” user privileges exploits a third-party program running as system over Terminal Servers. This would effectively give a normal, segregated user (Term. Services) control over the whole system (system privileges).</p>
<p>Chris Paget originally had these recommendations to solve the problem:</p>
<p><em>I can see two quick and dirty methods which will break a whole lotta functionality, and one very long-winded solution which is never going to be a total solution. Let me explain.</em></p>
<p><em>1. Don&#8217;t allow people to enumerate windows Nasty. Multiple breakages. Theoretically possible, but I&#8217;d hate to see people trying to work around not knowing what windows are on the desktop when they need to.</em></p>
<p><em>2. Don&#8217;t allow messages to pass between applications with different privileges Means that you couldn&#8217;t interact with any window on your desktop that&#8217;s not running as you; means that VirusScan at the very least (probably most personal firewalls, too) would need a whole lotta redesigning.</em></p>
<p><em>3. Add source info to messages, and depend on applications to decide whether or not to process the messages Would need an extension to the Win32 API, and a whole lotta work for people to use it. Big job, and people would still get it wrong. Look at buffer overflows &#8211; they&#8217;ve been around for years, and they&#8217;re still fairly common.</em></p>
<p>So what would someone do if they really wanted to build a safe (not vulnerable to shatter attacks) application that had a desktop GUI?</p>
<p>All would probably agree that it does make sense to run the application as one of least privilege and that might be a first thought – but that’s not always possible as some applications need to communicate to things on a privileged level and make certain system level  calls.</p>
<p>To someone that really, really cares about it &#8211; I might recommend the following as a solution to shatter attacks for an application (This is actually from Wikipedia – don’t laugh – but I think it makes sense):</p>
<p><em>…a two-process design where a process is loaded into the user&#8217;s session that interacts with the service process through inter-process communication. Additionally, when a privileged operation is required to be undertaken, an authenticated call is made that loads additional service code. Once that privileged code is finished doing what needs to be done, it is unloaded from memory so that it does not remain in memory to be a possible target for later exploitation.</em></p>
<p>So – essentially one would need to design the window interface with lower privileges and communicate through IPC to another, more higher privileged (server) process to make the calls that require higher privileges.</p>
<p>Brett Moore – in his 2004 whitepaper concludes with the following (after a lot of patches that Microsoft released in 2002 to protect some system applications that the OS’s shipped with):</p>
<p><em>The exploitation of shatter attacks have come a long way from when the original vulnerability was announced. As we have shown in this document, even the most obscure of messages can be used to make a process execute code that it was not intended to run.</em></p>
<p><em>While there have been discussions around the filtering of messages to protect interactive applications that run under a higher security context. It is becoming apparent that the only sure solution is to not have these applications running on an untrusted users desktop.</em></p>
<p><em>Application designers and system administrators need to be aware of the dangers associated with running higher privileged applications on a users desktop, and take steps to prevent them from been exploited. The examples included in this paper can be used against any interactive application that runs at a higher level, simply by specifying parameters such as the window title. Successful exploitation would allow a user to then execute commands under this higher-level security context.</em></p>
<p>So Brett says there’s not too much one can do either to prevent shatter attacks (but he didn’t mention the whole thing where we can split up the program into 2 different processes and have them communicate over IPC).</p>
<p>Of course &#8211; this is hard to do &#8211; especially when you think your application is not vulnerable because it doesn&#8217;t have any windowing GUI&#8217;s. According to his post <a title="http://archives.neohapsis.com/archives/ntbugtraq/2004-q4/0066.html" href="http://archives.neohapsis.com/archives/ntbugtraq/2004-q4/0066.html">here</a>,  he attacked an application that didn&#8217;t even have a window &#8211; well, not normally anyways:</p>
<p><em>We discovered that [Service X], that did not normally have a window, could<br />
be enticed into generating an error that would display a window. The<br />
service stored a pointer to a lookup table in the window memory pointed to<br />
by GWL_USERDATA. This lookup table held the address of functions, and was<br />
later used to retrieve an address and pass it to a CALL instruction.</em></p>
<p><em>By using the process mapped heap, as explained in my Blackhat presentation,<br />
it was possible to place our shellcode into a known location. We could also<br />
construct a new lookup table, pointing to our shellcode, in a known<br />
location.</em></p>
<p><em>Then by using SetWIndowLongPtr() API we replaced the pointer to the lookup<br />
table with the address of our new lookup table. The service would use our<br />
lookup table and execution would therefore reach the shellcode.</em></p>
<p><em></em>We should keep in mind as well – that it could be a whole different ballgame with Vista and Server 2008. Microsoft did a couple of things to try to fix the problem of shatter attacks (that’s a whole other post).</p>
<p>Although – I was just thinking a little while ago, how one could gain a name really quickly and some easy PR through this kind of research. Just find some programs that have a windowed desktop and that run with system level privilege – read up a little more about shatter attack stuff, then just publish a vulnerability like this: <a title="http://www.securityfocus.com/bid/27645" href="http://www.securityfocus.com/bid/27645">http://www.securityfocus.com/bid/27645</a>. I figure it’d be a good way to get one’s name in print – this particular one (also referenced above) was just released in Feb. 08.</p>
<p>Cheers,</p>
<p>Chuck B.</p>
]]></content:encoded>
			<wfw:commentRss>http://anautonomouszone.com/blog/archives/21/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Breach Misconceptions</title>
		<link>http://anautonomouszone.com/blog/archives/19</link>
		<comments>http://anautonomouszone.com/blog/archives/19#comments</comments>
		<pubDate>Mon, 07 Jul 2008 03:20:36 +0000</pubDate>
		<dc:creator>Chuck B.</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://anautonomouszone.com/blog/?p=19</guid>
		<description><![CDATA[I came across an interesting blog post of security misconceptions from Errata Sec. a while ago:
http://erratasec.blogspot.com/2008/06/verizon-500-breach-report.html
Basically the data came from a report/study of 500 forensic investigations that Verizon released.
http://www.verizonbusiness.com/resources/security/databreachreport.pdf 
Personally – I think the security industry is chock-full of misconceptions of the what/how/why of hackers and breaches.
While this report is interesting – the biggest problem [...]]]></description>
			<content:encoded><![CDATA[<p>I came across an interesting blog post of security misconceptions from Errata Sec. a while ago:</p>
<p><a title="http://erratasec.blogspot.com/2008/06/verizon-500-breach-report.html" href="http://erratasec.blogspot.com/2008/06/verizon-500-breach-report.html">http://erratasec.blogspot.com/2008/06/verizon-500-breach-report.html</a></p>
<p>Basically the data came from a report/study of 500 forensic investigations that Verizon released.</p>
<p><a title="http://www.verizonbusiness.com/resources/security/databreachreport.pdf " href="http://www.verizonbusiness.com/resources/security/databreachreport.pdf ">http://www.verizonbusiness.com/resources/security/databreachreport.pdf </a></p>
<p>Personally – I think the security industry is chock-full of misconceptions of the what/how/why of hackers and breaches.</p>
<p>While this report is interesting – the biggest problem with this report is that it’s a study drawn from 500 forensic engagements handled by the Verizon Business Investigative Response Team, which means the information is gathered from breaches and forensics engagements of large organizations (people who can afford to pay for Verizon forensics services). What’s wrong with this one might ask?</p>
<p>Well – in my opinion – large organizations generally have a larger security budget than say small businesses and home users – which means large organizations generally have things like regular security testing (a lot of the times by law or regulation of some sort), patch-management policies, etc. and they don’t constitute the majority of “breaches.” Sure – they’re still getting hacked, otherwise there wouldn’t be a report like this – but the majority of systems that get compromised/hacked don’t belong to large organizations that have some sort of security entity (person or department) in charge of their systems, rather it’s the small businesses and home users, such as the non-tech savvy grandmas that click on cute and free animated screen saver links from emails and web sites that get compromised. These end users – the people who most likely get hacked aren’t represented here.</p>
<p>Much like trying to gather statistical information from the impact of Cross-Site Scripting (or any client side exploit – which is the most predominate type of exploit these days) – gathering information or statistics on the really vulnerable systems on the internet is almost impossible. These client side exploits generally affect home users, which – by the sheer number of home users it’s really hard to gather test cases. I’d even say that most of the people/systems that have been “hacked” aren’t even aware that they were compromised (like people who lend their system to a botnet).</p>
<p>The thing is – when end users of an organization get hacked, like in a Cross-Site Scripting or Microsoft Office exploit it is generally the lowest-hanging fruit and can have just as much impact as the organization servers getting hacked (confidential information, personal credit card data, etc. being stolen).</p>
<p>This is (again, imho) the way the majority of organizations/systems get compromised these days – and this report doesn’t really take this into account – again it’s very rare that forensics engagements deal with client side breaches.</p>
<p>This is one of the reasons I like to follow Dancho Danchev’s <a title="http://ddanchev.blogspot.com/" href="http://ddanchev.blogspot.com/">blog</a> – it’s a great peek into the latest and greatest what is “really going on” in the blackhat hacker market (motives, techniques, methodologies, etc.).</p>
<p>Here’s are some of the misconceptions that were talked about in the Errata sec. blog:</p>
<p><strong>Misconception:</strong> Hackers target their victims.<br />
<strong>Verizon data:</strong> 85% of attacks were &#8220;opportunistic&#8221;, the hackers didn&#8217;t know who their victims were until after they broke in.</p>
<p><strong>Misconception:</strong> Certified anti-virus products detect over 99% of all viruses.<br />
<strong>Verizon data:</strong> 25% of viruses/malware were customized to their victims and undetectable with standard anti-virus.</p>
<p><strong>Misconception:</strong> Hackers are smart, clever, geniuses, wizards, etc.<br />
<strong>Verizon data:</strong> 55% where of attacks required essentially no skills, the level of &#8220;script kiddies&#8221; running automated tools. Only 17% required &#8220;advanced&#8221; skills.</p>
<p><strong>Misconception:</strong> It&#8217;s the insider threat. No, wait, it&#8217;s outsiders. No, I mean, it&#8217;s the partners.<br />
<strong>Verizon data:</strong> 73% external, 18% internal, 39% partners. However, external breaches tended to be minor, whereas internal and partner breeches were major. Their numbers show that all three are important threats and that it&#8217;s hard to measure which one is worse.</p>
<p><strong>Misconception:</strong> Numbers are definitive.<br />
<strong>Verizon data: </strong>These numbers are bit subjective. For example, they notice that &#8220;physical breaches&#8221; were rare, but that&#8217;s because Verizon wouldn&#8217;t be called in to investigate a physical breach.</p>
<p><strong>Question:</strong> What are hackers after?<br />
<strong>Verizon data:</strong> Credit Card data (84%), Personal identity (32%), Username/passwords (15%)</p>
<p><strong>Question:</strong> How old are the vulnerability exploits hackers use?<br />
<strong>Verizon data:</strong> 71% older than 1-year, another 19% older than 6 months.</p>
<p>(&#8230;)<br />
Cheers,</p>
<p>Chuck B.</p>
]]></content:encoded>
			<wfw:commentRss>http://anautonomouszone.com/blog/archives/19/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>IPC Pipe pitfalls, mistakes and solutions</title>
		<link>http://anautonomouszone.com/blog/archives/18</link>
		<comments>http://anautonomouszone.com/blog/archives/18#comments</comments>
		<pubDate>Mon, 07 Jul 2008 01:18:18 +0000</pubDate>
		<dc:creator>Chuck B.</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://anautonomouszone.com/blog/?p=18</guid>
		<description><![CDATA[IPC Pipes (especially on Windows) are a pretty interesting topic for me because it has a lot to do with generic object and file security.
First, here’s the definition of a Pipe from msdn: http://msdn2.microsoft.com/en-us/library/aa365780(VS.85).aspx :
A pipe is a section of shared memory that processes use for communication. The process that creates a pipe is the [...]]]></description>
			<content:encoded><![CDATA[<p>IPC Pipes (especially on Windows) are a pretty interesting topic for me because it has a lot to do with generic object and file security.</p>
<p>First, here’s the definition of a Pipe from msdn: <a title="http://msdn.microsoft.com/en-us/library/aa365780(VS.85).aspx" href="http://msdn.microsoft.com/en-us/library/aa365780(VS.85).aspx">http://msdn2.microsoft.com/en-us/library/aa365780(VS.85).aspx</a> :</p>
<p>A pipe is a section of shared memory that processes use for communication. The process that creates a pipe is the pipe server. A process that connects to a pipe is a pipe client. One process writes information to the pipe, then the other process reads the information from the pipe. This overview describes how to create, manage, and use pipes.</p>
<p>And a little more here <a title="http://msdn.microsoft.com/en-us/library/aa365137(VS.85).aspx" href="http://msdn.microsoft.com/en-us/library/aa365137(VS.85).aspx">http://msdn2.microsoft.com/en-us/library/aa365137(VS.85).aspx</a> :</p>
<p>There are two types of pipes: anonymous pipes and named pipes. Anonymous pipes require less overhead than named pipes, but offer limited services.</p>
<p>The term pipe, as used here, implies that a pipe is used as an information conduit. Conceptually, a pipe has two ends. A one-way pipe allows the process at one end to write to the pipe, and allows the process at the other end to read from the pipe. A two-way (or duplex) pipe allows a process to read and write from its end of the pipe.</p>
<p>So to begin with all pipes are securable objects, so they have specific access rights associated with their DACL entries (much like files).</p>
<p>While looking into this topic a bit a while ago I came across this paper (Discovering and Exploiting Named Pipe Security Flaws for Fun and Profit):</p>
<p><a title="http://www.blakewatts.com/namedpipepaper.html" href="http://www.blakewatts.com/namedpipepaper.html">http://www.blakewatts.com/namedpipepaper.html</a></p>
<p>Here’s some highlights from the paper:<br />
<em><br />
A named pipe is a mechanism that enables interprocess communication for applications to communicate locally or remotely. The application that creates the pipe is known as the pipe server, and the application that connects to the pipe is known as the pipe client. Similar to sockets, after the server creates the named pipe, pipe clients may connect to the server. The function CreateNamedPipe provides the means to create the pipe. Clients use the CreateFile function to connect to the server-end of the named pipe. After the client and server have established a connection, they use the ReadFile and WriteFile functions to communicate.</em></p>
<p><em>The way in which named pipes are created and connected to is conceptually identical to how files are created on a file system&#8211;that&#8217;s no coincidence. Internally, named pipes are implemented as a file system (more on this later). The &#8220;file location&#8221; of creating and connecting to a pipe follows a standard naming convention. This effectively ensures that the creation and connection requests of pipes are internally routed correctly. That convention is as follows: \\.\pipe\pipename. The \\.\ segment is used to route the creation and connection of the pipe to the appropriate file system. The period in the \\.\ segment may be replaced with a remote system name. This enables the associated function to be invoked remotely.<br />
</em><br />
So the above is just a bit about how pipes work and all that. But we probably need this interesting background info as well before we can really talk a lot about vulnerabilities with pipes – “Named Pipe Impersonation”:</p>
<p><em>Impersonation is the process of a pipe server temporarily assuming the security context of the client of its pipe. Pipe servers impersonate their client&#8217;s security context by calling the function ImpersonateNamedPipeClient. The requirements of impersonation are that a client connects to the pipe server and writes some data to it. After the pipe server reads the data from the client, its call to ImpesonateNamedPipeClient will succeed, and it is granted an &#8216;impersonation&#8217; token of the client. The requirement of reading data from the pipe can be bypassed, and is discussed in the &#8216;File System Vulnerabilities&#8217; section.</em></p>
<p><em>Some readers may be wondering as to why in the world would impersonation exist in an interprocess communication mechanism. Impersonation and IPC, implemented properly, can actually lead to better-designed software architecture. In its conception, it was created so that privileged subsystems and services could temporally lower their own security context while processing the requests of its clients. However, if implemented improperly malicious applications can attain full control of the system.</em></p>
<p>So this is really interesting because it leaves room for client attacks:</p>
<p><em>When a client connects to the server-end of a named pipe it may unknowingly be giving the server-end of the pipe the ability to perform any task on their behalf&#8211;by impersonating their security context. Clients can control their impersonation &#8220;level&#8221; by specifying specific flags in their CreateFile call (which is used for connecting the client to the server pipe), however is seldom performed. This process is formally known as setting the security quality of service. So the question on most readers mind is, &#8220;What if the server isn&#8217;t started, or has crashed?&#8221; Well, the answer is very simple. Their security context is up for grabs. Any security context (interactive user, service, etc.) may create the pipe that the client is looking for and assume their security context. This vulnerability classification is known as Superfluous Pipe Connectivity.<br />
</em><br />
This is really interesting because through named pipe impersonation one can gain the privilege level of the client (if the client didn’t specify an impersonation level in the call to CreateFile() when creating the pipe).</p>
<p>Of course, we’re keeping in mind that “client” doesn’t always mean “lower privileged process.”</p>
<p>This type of attack lead to this (system privilege level) vulnerability (it’s actually a combination of client pipe and pipe namesquating):</p>
<p>Service Control Manager Named Pipe Impersonation Vulnerability (http://www.microsoft.com/technet/security/Bulletin/MS00-053.mspx)</p>
<p>There’s also vulnerabilities that were discovered like these:</p>
<p>http://secunia.com/advisories/9229/ (SQL Server Named Pipe Privilege Escalation Vulnerability)<br />
http://www.microsoft.com/technet/security/Bulletin/MS01-031.mspx (Telnet Server Named Pipe Privilege Escalation Vulnerability)</p>
<p>The paper also says this:<br />
<em><br />
Coaxing an application or service into connecting to a pipe is usually trivial in most situations. For instance, when starting a service, the service will typically connect to another service&#8217;s named pipe. A monitoring tool, such as Security Internals&#8217; Pipe Security Explorer, will yield all the named pipes that an application or service connects to. It is probable that some pipes will not exist. If a client application attempts to connect to a server pipe without verifying that the server is running and has created the corresponding named pipe, it&#8217;s possible that at some point in time the client&#8217;s security context may be usurped by a malicious application.</em></p>
<p>Cheers,</p>
<p>Chuck B.</p>
]]></content:encoded>
			<wfw:commentRss>http://anautonomouszone.com/blog/archives/18/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Weak Permissions and Dangerous Signals and Stuff</title>
		<link>http://anautonomouszone.com/blog/archives/17</link>
		<comments>http://anautonomouszone.com/blog/archives/17#comments</comments>
		<pubDate>Mon, 07 Jul 2008 00:56:54 +0000</pubDate>
		<dc:creator>Chuck B.</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://anautonomouszone.com/blog/?p=17</guid>
		<description><![CDATA[So I think this a really cool blog entry by the Windows master Mark Russinovich: “The Case of the Insecure Security Software”.
In short it discusses a tool he wrote called AccessChk which helps identify weak permissions problems. Apparently he had received some requests from groups within Microsoft and elsewhere to extend its coverage of securable [...]]]></description>
			<content:encoded><![CDATA[<p>So I think this a really cool blog entry by the Windows master Mark Russinovich: “<a title="http://blogs.technet.com/markrussinovich/archive/2007/06/19/1256677.aspx" href="http://blogs.technet.com/markrussinovich/archive/2007/06/19/1256677.aspx">The Case of the Insecure Security Software</a>”.</p>
<p>In short it discusses a tool he wrote called AccessChk which helps identify weak permissions problems. Apparently he had received some requests from groups within Microsoft and elsewhere to extend its coverage of securable objects analyzed to include the Object Manager namespace (which stores named mutexes, semaphores and memory-mapped files), the Service Control Manager, and named pipes.</p>
<p>After he had revised AccessChk he ran the tool on his box to see what system-global objects the Everyone and Users groups can modify.</p>
<p>As he states: <em>The ability to change those objects almost always indicates the ability for unprivileged users to compromise other accounts, elevate to system or administrative privilege, or prevent services or programs run by the system or other users from functioning. For example, if an unprivileged user can change an executable in the %programfiles% directory they might be able to cause another user to execute their code. Some applications include Windows services, so if a user could change the service executable they could obtain system privileges.</em></p>
<p>He also played with write access from the Authenticated Users and Users groups on different namespaces. According to the blog:</p>
<p><em>An output line, which looks like “RW C:\Program Files\Vendor”, reveals a probable security flaw.<br />
To my surprise and dismay, I found security holes in several namespaces. The security settings on one application’s global synchronization and memory mapping objects, as well as on its installation directory, allow unprivileged users to effectively shut off the application, corrupt its configuration files, and replace its executables to elevate to Local System privileges. What application has such grossly insecure permissions? Ironically, that of a top-tier security vendor.<br />
For instance, AccessChk showed output that indicated the Users group has write access to the application’s configuration directory (note that names have been changed):<br />
RW C:\Program Files\SecurityVendor\Config\<br />
RW C:\Program Files\ SecurityVendor\Config\scanmaster.db<br />
RW C:\Program Files\ SecurityVendor\Config\realtimemaster.db</em><br />
…<br />
<em>Because Malware would run in the Users group, it could modify the configuration data or create its own version and prevent the security software from changing it. It could also watch for dynamic updates to the files and reset their contents.<br />
For the object namespace, it reported output lines like this:<br />
RW [Section]    \basenamedobjects\12345678-abcd-1234-cdef-123456789abc<br />
RW [Mutant]     \basenamedobjects\87654321-cdab-3124-efcd-6789abc12345</em><br />
…<br />
He also states:</p>
<p><em>In the wake of my discovery, I analyzed the rest of my systems, as well as trial versions of other popular security, game, ISP and consumer applications. A number of the most popular in each category had problems similar to those of the security software installed on my development system. I felt like I was shining a flashlight under a house and finding rotten beams where I had assumed there was a sturdy foundation.<br />
</em><br />
Then he kind of hit the nail on the head:</p>
<p><em>The security research community has focused its efforts uncovering local elevations via buffer overflows and unverified parameters, but has completely overlooked these obvious problems – problems often caused by the software of security ISVs, or in some cases, their own.</em></p>
<p>Now, while I’m sure that the security research hasn’t “completely overlooked these obvious problems” I would bet that it’s an area that could garnish some nice results with a bit of looking into.</p>
<p>Through the process of reading “<a title="http://taossa.com/" href="http://taossa.com/">The Art of Software Security Assessment</a>” I came across a few really cool problems in software similar to this. I had heard of some of these problems before, but I hadn’t gotten into too much detail concerning them.</p>
<p>There are chapters in the book that go into a bit of detail on issues like this that provide a really good fundamental understanding of similar problems:</p>
<p>Chapter 11: Windows I: Objects and the File System<br />
Chapter 12: Windows II: Interprocess Communication</p>
<p>Another cool chapter / subject is Chapter 13:  Synchronization and State. It talks about Reentrancy (Reentrancy refers to a function’s capacity to work correctly, even when it’s interrupted by another running thread that calls the same function), Asynchronous-Safe Code, Signals and other things.</p>
<p>Most pentesters know about buffer/heap overflows, integer overflows, off-by-ones, race conditions, and similar common exploitable vulnerabilities, but what about using Signals to escalate privilege or cause a double free() in code that is not asynchronous-safe?</p>
<p>Here is a great paper by Michael Zalewski “<a title="http://lcamtuf.coredump.cx/signals.txt" href="http://lcamtuf.coredump.cx/signals.txt">Delivering Signals for Fun and Profit</a>” that talks about this:</p>
<p>From the paper:</p>
<p><em>Below is a sample &#8216;vulnerable program&#8217; code:</em></p>
<p><em>&#8212; vuln.c &#8212;<br />
#include &lt;signal.h&gt;<br />
#include &lt;syslog.h&gt;<br />
#include &lt;string.h&gt;<br />
#include &lt;stdlib.h&gt;</em></p>
<p><em>void *global1, *global2;<br />
char *what;</em></p>
<p><em>void sh(int dummy) {<br />
syslog(LOG_NOTICE,&#8221;%s\n&#8221;,what);<br />
free(global2);<br />
free(global1);<br />
sleep(10);<br />
exit(0);<br />
}</em></p>
<p><em>int main(int argc,char* argv[]) {<br />
what=argv[1];<br />
global1=strdup(argv[2]);<br />
global2=malloc(340);<br />
signal(SIGHUP,sh);<br />
signal(SIGTERM,sh);<br />
sleep(10);<br />
exit(0);<br />
}<br />
&#8212;- EOF &#8212;-</em></p>
<p><em>You can exploit it, forcing free() to be called on a memory region filled with 0&#215;41414141 (you can see this value in the registers at the time of crash &#8211; the bytes represented as 41 in hex are set by the &#8216;A&#8217; input characters in the variable $LOG below). Sample command lines for a Bash shell are:</em></p>
<p><em>$ gcc vuln.c -o vuln<br />
$ PAD=`perl -e &#8216;{print &#8220;x&#8221;x410}&#8217;`<br />
$ LOG=`perl -e &#8216;{print &#8220;A&#8221;x100}&#8217;`<br />
$ ./vuln $LOG $PAD &amp; sleep 1; killall -HUP vuln; sleep 1; killall -TERM vuln</em></p>
<p><em>The result should be a segmentation fault followed by nice core dump (for Linux glibc 2.1.9x and 2.0.7).<br />
(gdb) back</em></p>
<p><em>#0  chunk_free (ar_ptr=0&#215;4013dce0, p=0&#215;80499a0) at malloc.c:3069<br />
#1  0&#215;4009b334 in __libc_free (mem=0&#215;80499a8) at malloc.c:3043<br />
#2  0&#215;80485b8 in sh ()<br />
#4  0&#215;400d5971 in __libc_nanosleep () from /lib/libc.so.6<br />
#5  0&#215;400d5801 in __sleep (seconds=10) at ../sysdeps/unix/sysv/linux/sleep.c:85<br />
#6  0&#215;80485d6 in sh ()</em></p>
<p><em>So, as you can see, failure was caused when signal handler was re-entered. __libf_free function was called with a parameter of 0&#215;080499a8, which points somewhere in the middle of our AAAs:</em></p>
<p><em>(gdb) x/s 0&#215;80499a8<br />
0&#215;80499a8:       &#8216;A&#8217; &lt;repeats 94 times&gt;, &#8220;\n&#8221;</em></p>
<p><em>You can find 0&#215;41414141 in the registers, as well, showing this data is being processed. For more analysis, please refer to the paper mentioned above.</em></p>
<p><em>For the description, impact and fix information on Sendmail signal handling vulnerability, please refer to the RAZOR advisory at: adv_sm8120.</em></p>
<p><em>Obviously, that is just an example of this attack. Whenever signal handler execution is non-atomic, attacks of this kind are possible by re-entering the handler when it is in the middle of performing non-reentrant operations. Heap damage is the most obvious vector of attack, in this case, but not the only one.</em></p>
<p>Anyways, none of this stuff is new, but it’s food for thought for anyone who wasn’t really familiar with these type of vulnerabilities.</p>
<p>Cheers,</p>
<p>Chuck B.</p>
]]></content:encoded>
			<wfw:commentRss>http://anautonomouszone.com/blog/archives/17/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Someone else actually likes NTOSpider?</title>
		<link>http://anautonomouszone.com/blog/archives/16</link>
		<comments>http://anautonomouszone.com/blog/archives/16#comments</comments>
		<pubDate>Mon, 07 Jul 2008 00:41:16 +0000</pubDate>
		<dc:creator>Chuck B.</dc:creator>
				<category><![CDATA[Web App Hacking]]></category>

		<guid isPermaLink="false">http://anautonomouszone.com/blog/?p=16</guid>
		<description><![CDATA[NTOSpider  &#8211; I generally use it as a  scanner (amongst others) when I&#8217;m looking for web app input validation issues, and I’ve thought it to be pretty decent. By no means is it the best one out there &#8211; which I&#8217;ll talk about in a sec, but it is a scanner that has [...]]]></description>
			<content:encoded><![CDATA[<p>NTOSpider  &#8211; I generally use it as a  scanner (amongst others) when I&#8217;m looking for web app input validation issues, and I’ve thought it to be pretty decent. By no means is it the best one out there &#8211; which I&#8217;ll talk about in a sec, but it is a scanner that has decent spidering (automatic code coverage) capabilities and decent XSS identification. In my opinion, it&#8217;s semi-alright for a point-and-shoot web app scanner (but I don&#8217;t think I&#8217;ve ever found one that I think is real good).</p>
<p>The web app scanner market is really odd. For some reason, the market just can&#8217;t seem to get it right. I&#8217;ve worked at places that have had head-to-head comparisons of all the major web application scanners because they had built a proprietary scanner (but it wasn&#8217;t for sale &#8211; they sold a service that used the scanner) and would have these comparison tests every once in a while to see how their product stood against the competition. Now, I didn&#8217;t really run the tests myself because I was doing billable work (mostly web app testing) at that moment, but a friend at the company working right next to me was doing the comparison testing &#8211; so he&#8217;d share the results with me whenever I continually look over his shoulder and asked about them.</p>
<p>It was kind of a funny thing. One was always better at picking up XSS than another, Some other one was good at picking up SQL injection, while some weren&#8217;t, one was always better at code coverage when using an automatic crawl functionality, some wouldn&#8217;t work well in certain authentication scenarios, etc., etc.</p>
<p>I mean &#8211; web app security is a hot market these days, and rightfully so. Most (not all) organizations (for the external infrastructure) generally have firewalls up blocking most un-needed services. They&#8217;re aware of shutting down extraneous services, incorporate some sort of patching solution, etc. but almost all have a web site.</p>
<p>As time goes on, and security awareness goes up, rules or laws instituted making companies liable for compromises, things like finding an mssql server on port 1433 with a weak password, anonymous ftp, un-patched webservers become less and less common in an external environment.</p>
<p>But again, almost every company has a port 80 or 443 open with some application somewhere. Web applications provide, by far, the largest external attack surface in an organization &#8211; there&#8217;s typically hundreds of user-controlled parameters going into the application, which are all a potential threat. Plus, a lot of the time there&#8217;s all kinds of interesting things when web apps get exploited, like user names and passwords that can be used for other services throughout the organization, credit card numbers, personal identification information, and more. And luckily for people who are into (in)security, most of the time it&#8217;s custom code written by people who know nothing about security &#8211; and don&#8217;t have that much experience, as opposed to other services that they have externally facing that generally have a lot less attack surface and have been written by some well-known company or a community, tested a lot and have more-or-less stood the test of time (like most PPTP or SSH servers).</p>
<p>So I could never understand &#8211; with the market so hot (like &#8211; if you&#8217;re a security company and you&#8217;re not selling web application work when you are offering the service then something is seriously wrong with your sales team) why a company or open source project has never got it right.</p>
<p>Why not try out all the web app scanners on the market, take the features, techniques, signatures of the ones that perform certain functions the best (or better than the others) and combine them into one tool? Someone could make real decent money doing that. I&#8217;d almost be tempted myself &#8211; but I it&#8217;s just not something I&#8217;m really interested in. Look at how much money IBM/WatchFire&#8217;s AppScan and HP/SPI Dynamics WebInspect pull in for them &#8211; and their products really aren&#8217;t that great, like at all.</p>
<p>I mean to build a web app scanner generally isn&#8217;t rocket science (or even computer science most of the time). There&#8217;s actually a really good how-to write your own web app scanner in  the O&#8217;Reilly book &#8220;Network Security Tools, Writing, Hacking, and Modifying Security Tools.&#8221; The code for that one is available <a title="http://www.gdssecurity.com/l/t/extendedscanner.zip" href="http://www.gdssecurity.com/l/t/extendedscanner.zip">here</a>.</p>
<p>But for some reason I think that the developers for web app scanners think that they don&#8217;t need to check out the competition before they release something &#8211; they must think that whatever they&#8217;re doing, it must be the best way. Otherwise we wouldn&#8217;t have so many people charging a lot of money for low-quality web app scanners on the market.</p>
<p>So &#8211; back to NTOSpider a bit: of course, there&#8217;s no one automated scanner that&#8217;s going to be an end-all-be-all solution for webapps – (there’s just way too many business logic types of flaws in applications to have a non-intelligent scanner catch these types of things). But it does a decent job I guess for what it was meant to do &#8211; mainly fuzz parameters.</p>
<p>However, I do usually throw a couple different webapp scanners at an app either before or during manual analysis to catch any low-hanging fruit and to let me know where I might want to concentrate some exploit efforts on (like, for instance on a possible sql injection finding).</p>
<p>I know,  I know – I&#8217;ve heard some pentesters say that they aren’t supposed to mention that they use automated tools like nessus or webapp scanners &#8211; they do all manual testing.</p>
<p>However, IMHO there is definitely a time and a place for scanners. I’m not saying they should *strictly rely* on them and only run a couple of scanners on a test and call it quits (because you *will* miss a lot of cool findings) – but I do run automated scanning tools on just about every single test I perform (like nmap).</p>
<p>So, again I do think that there are things that webapp scanners are really good for – fuzzing parameters (in the case of webapps, scanners are usually really good at catching XSS, sql injection points, and CRLF). When fuzzing anything it is generally done in an automated fashion – keeping in mind it usually does take a lot of manual effort to generate meaningful fuzzing data sets to get the best results possible – but once you have meaningful data sets to fuzz with it should be an automated process.</p>
<p>The process of fuzzing stuff is actually kind of what a computer is meant to do. The four basic functions of computing come to mind – input, processing, output and storage. The combination of these functions is exactly what we do when fuzzing!</p>
<p>I think scanning tools probably got a bad rap from the community when “pentesters” started using/condoning  automated tools for their complete efforts of the pentest like running nessus on a network or a webapp scanner on a web application and calling it quits. Now just running automated tools on some application, system or network is not a pentest in any sense of the word, any decent pentester will tell you that – but in the same sense I feel that there is some backlash against these very same tools from others in the community. I can kind of understand – no automated tool can take the place of an experienced pentester. On the other hand I think these very same tools can definitely bring informative issues to the table when testing.</p>
<p>Now that I have in some sense justified (at least in my own mind) scanning tools for particular purposes I guess I’ll get to the original point of this post – which is someone else actually likes NTOSpider (even the though the both the <a title="http://www.stratdat.com/webscan.pdf" href="http://www.stratdat.com/webscan.pdf">report</a> and the metrics that Larry Suto use are pretty wack):</p>
<p>Cheers,</p>
<p>Chuck B.</p>
]]></content:encoded>
			<wfw:commentRss>http://anautonomouszone.com/blog/archives/16/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Anyone interested in finding bugs?</title>
		<link>http://anautonomouszone.com/blog/archives/15</link>
		<comments>http://anautonomouszone.com/blog/archives/15#comments</comments>
		<pubDate>Sun, 06 Jul 2008 20:50:25 +0000</pubDate>
		<dc:creator>Chuck B.</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://anautonomouszone.com/blog/?p=15</guid>
		<description><![CDATA[So I’ve written a couple of posts about some fuzzing methodologies, mods to tools, etc. Basically they kind of went over the fact that at the moment I’m into fuzzing compressed binary files like zip, cab, rar, etc. and my thoughts on how I’m going about doing it.
For the last little while I’ve been looking [...]]]></description>
			<content:encoded><![CDATA[<p>So I’ve written a couple of posts about some fuzzing methodologies, mods to tools, etc. Basically they kind of went over the fact that at the moment I’m into fuzzing compressed binary files like zip, cab, rar, etc. and my thoughts on how I’m going about doing it.</p>
<p>For the last little while I’ve been looking into decent ways to fuzz things like how to generate “smart” data sets to fuzz with and how to automate the fuzzing process along with decent ways to monitor and log exceptions/signals.</p>
<p>At this point, I pretty much have a system down. I’ve modified a few fuzzers like Autodafe and Filefuzz to get them to generate (at least what I think is) more meaningful test cases to fuzz with. So now the bulk of the time is usually spent in tearing apart binary file formats in order to perform intelligent block-based fuzzing (which isn’t usually that hard – one can usually find documentation and a breakdown of the format somewhere like wotsit.org or use templates from 010 editor or even in the docs of the program you’re fuzzing). It’s useful to do this for things like knowing where potential trouble areas would be – like a length field or generally breaking down the structures of a binary format for things like knowing when to perform a CRC32 checksum on a structure to get more code coverage in the binary when fuzzing so it doesn’t just fail a checksum and exit – things like that. A smaller portion of the time is pretty much just generating the files using some fuzzers then firing them off. Lastly – there is the fun part of looking over the results when any exceptions are logged / generated and confirming anything found (usually in a debugger).</p>
<p>So I’m thinking that it might be lucrative if I start looking into media format things. I’m thinking files like avi, bmp, tiff (one’s gotta have love for those iphone/safari tiff vulns. out there), pm3, jpg, png, wav, wmf, wmx, mpeg, mpa, midi, rmi, cda, ivf, divx, mov, rm, rts, qt, swf, etc. There are *tons* of different media formats out there and *tons* of different applications that open them (including media players, browsers, plug-ins, etc.).</p>
<p>As I’m going through the motions with this I’m thinking to myself “Self – it would be really cool if a few other cats were in on this – we could get a system going and just pump out a lot of tests, more testing = more potential bugs to be found.”</p>
<p>And so, finally the whole point to my post: if anyone is interested in helping out to find some 0-days it would be really cool. If anyone is interested but doesn’t have much experience with fuzzing (but is willing to learn how to do it) I will be totally down in explaining everything I know about it and where to find the material that I read to learn about it (so that whomever else is interested in learning about it can read it as well). If anyone else is interested in fuzzing stuff to find bugs and they have some experience then I’d really like to hear how they went about it – two (or more) heads are always better than one.</p>
<p>Like I said – I pretty much have a system down and some tools written – it would just be cool to have some extra hands and ideas in the mix.</p>
<p>Interested persons – just hit me up.</p>
<p>anautonomouszone [at] gmail [dot] com</p>
<p>Cheers,</p>
<p>Chuck B.</p>
]]></content:encoded>
			<wfw:commentRss>http://anautonomouszone.com/blog/archives/15/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>File Fuzzing &#8211; Part 2</title>
		<link>http://anautonomouszone.com/blog/archives/14</link>
		<comments>http://anautonomouszone.com/blog/archives/14#comments</comments>
		<pubDate>Sun, 06 Jul 2008 15:31:12 +0000</pubDate>
		<dc:creator>Chuck B.</dc:creator>
				<category><![CDATA[Fuzzing]]></category>

		<guid isPermaLink="false">http://anautonomouszone.com/blog/?p=14</guid>
		<description><![CDATA[
So in light of it being the beginning of October I decided to celebrate by spending a little time on re-writing some of the functionalities of FileFuzz.
As I had mentioned in a previous post about this topic, fuzzing typically falls into two different categories – brute force (mutation-based fuzzing) and intelligent brute force (generation-based) fuzzing. [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal">
<p class="MsoNormal">So in light of it being the beginning of October I decided to celebrate by spending a little time on re-writing some of the functionalities of FileFuzz.</p>
<p class="MsoNormal">As I had mentioned in a previous post about this topic, fuzzing typically falls into two different categories – brute force (mutation-based fuzzing) and intelligent brute force (generation-based) fuzzing. Just to recap, mutation based fuzzing is where we get some sample files of the file type and the fuzzer generator creates mutations of them. With intelligent brute force fuzzing we actually have to research the file specification. An intelligent fuzzing engine is still brute force attacking, but it relies on configuration files from the user, making the process more intelligent. Think of templates that the fuzzing engine will use that has a list of data structures, positions relative to each other, and possible values.</p>
<p class="MsoNormal">In the last little while, in my free time, I’ve been looking into different fuzzing generators in order to generate malformed files for different file formats. I decided to go with Autodafe for the generation based fuzzing. I have a newer release of Autodafe than the public version, (just because I emailed Martin Vuagnoux and he was cool enough to send me the newest he had at the time) – and I modified how it generates files for hex fuzzing. The stock version of Autodafe is missing the hex generator functionality. You can pick up the hex fuzzing mod  that I did for it <a title="generator_w_hex.sh" href="http://anautonomouszone.com/tools/generator_w_hex.sh">here</a>.</p>
<p class="MsoNormal">I also decided to spend a little time and modify FileFuzz for the mutation-based fuzzing.</p>
<p class="MsoNormal">One thing I tried to keep in mind while trying to figure out how to generate the data was exactly what data to generate. I figured I’d have greater success of finding bugs if I could generate smart data sets.</p>
<p class="MsoNormal">So let’s talk about “smart data sets” for a minute pertaining to mutation-based fuzzing (I also like to think of mutation-based fuzzing as file bit-flipping).</p>
<p class="MsoNormal">Bit flipping files can be really handy for not only finding integer overflows/underflows but also for other length calculations on data.</p>
<p class="MsoNormal">Let’s look at an example of length calculation stuff (this is pretty much taken from Pedram’s fuzzing book &#8211; &#8220;Fuzzing – Brute Force Vulnerability Discovery&#8221;). For example, MS04-028 “Buffer Overrun in JPEG Processing (GDI+) Could Allow Code Execution.” The JPEG format allows comments to be embedded within the image itself. Comments are preceded by the 0xFFFE byte sequence, followed by a 16-bit word value indicating the total size of the comment. The size includes the two bytes used for the size and the header ends with the comment itself.</p>
<p class="MsoNormal">We would see something like this in the file:</p>
<p class="MsoNormal">FF FE 00 06 66 75 7A 7A</p>
<p class="MsoNormal">Breakdown:</p>
<p class="MsoNormal">FF FE                                     Comment Preface</p>
<p class="MsoNormal">00 06                                    Length of comments in bytes</p>
<p class="MsoNormal">66 75 7A 7A                         ASCII value of ‘fuzz’</p>
<p class="MsoNormal">Now if the Length of comments in bytes was changed (flipped) from 0&#215;0006 to 0&#215;0000 we have an overflow in the vulnerable version of Windows Picture and Fax Viewer (shimgvw.dll).</p>
<p class="MsoNormal">The other big class of vulns. that typically found with bit flipping are the integer related overflow/underflow guys.</p>
<p class="MsoNormal">Continuing with “smart data sets” we can guess that the two extreme border cases (0 and 0xFFFFFFFF) are obvious choices to flip bits to – but let’s think of other choices as well.</p>
<p class="MsoNormal">For example (again from Pedram’s book) it’s not uncommon for additional space to be included with the specified size to accommodate a header, footer, or terminating NULL byte. The following code is an example:</p>
<p class="MsoNormal">int size = read_ccr_size(packet);</p>
<p class="MsoNormal">// save space for NULL termination.</p>
<p class="MsoNormal">buffer = (char *) malloc(size + 1);</p>
<p class="MsoNormal">Therefore, it might be a good idea to include near-border test cases such as 0XFFFFFFFF-1, 0XFFFFFFFF-2, 0XFFFFFFFF-3, (or even + sometimes) etc.</p>
<p class="MsoNormal">Then there’s also 16-bit integers (0xFFFF) and 8-bit integers to think about (0xFF).</p>
<p class="MsoNormal">Also there’s a host of other meaningful (“smart”) values we might want to try that could yield results:</p>
<p class="MsoNormal">0&#215;100</p>
<p class="MsoNormal">0&#215;1000</p>
<p class="MsoNormal">0&#215;3fffffff</p>
<p class="MsoNormal">0&#215;7ffffffe</p>
<p class="MsoNormal">0&#215;7fffffff</p>
<p class="MsoNormal">0&#215;80000000</p>
<p class="MsoNormal">0xfffffffe</p>
<p class="MsoNormal">0&#215;10000</p>
<p class="MsoNormal">0&#215;100000</p>
<p class="MsoNormal">0&#215;2000</p>
<p class="MsoNormal">0&#215;8000</p>
<p class="MsoNormal">etc…</p>
<p class="MsoNormal">So as I had mentioned previously I decided to work with FileFuzz to generate malformed (bit-flipped) files. The way Sutton designed FileFuzz there’s essentially two different ways to bit flip files. One is to use the “All Bytes” option which you can specify the Byte(s) to Overwrite (flip to) and the number of bytes to overwrite. It might be clearer with a small example:</p>
<p class="MsoNormal">Let’s say I have a file with the current values:</p>
<p class="MsoNormal">FF FE 00 06 66 75 7A 7A</p>
<p class="MsoNormal">If I specified the “All Bytes” option with the Byte(s) to Overwrite to be 0xBB and the number of bytes to be overwritten to be 2 the following would be the first file generated:</p>
<p class="MsoNormal">BB BB 00 06 66 75 7A 7A</p>
<p class="MsoNormal">The second file would be:</p>
<p class="MsoNormal">FF BB BB 06 66 75 7A 7A</p>
<p class="MsoNormal">The third file:</p>
<p class="MsoNormal">FF FE BB BB 66 75 7A 7A</p>
<p class="MsoNormal">and so on…</p>
<p class="MsoNormal">Using this technique one could generate a lot of files with combinations like 0&#215;00 x 4 (to create 0&#215;00000000 in place of our BB BB above we would overwrite 4 bytes at a time with 00 00 00 00), etc.</p>
<p class="MsoNormal">But we couldn’t generate different value pairs of bytes to overwrite like 0xFFFE or 0&#215;00000001, or even 0&#215;7FFE….</p>
<p class="MsoNormal">There’s also the “Depth” option in FileFuzz in which case you specify a location (bytes number) to fuzz in the file and the bytes to overwrite that location with.</p>
<p class="MsoNormal">Using our example hex values again:</p>
<p class="MsoNormal">FF FE 00 06 66 75 7A 7A</p>
<p class="MsoNormal">If I were to specify location 2 with the bytes to overwrite being 0&#215;01to 0&#215;03 the result would generate the following date in the files:</p>
<p class="MsoNormal">First file:</p>
<p class="MsoNormal">FF FE 01 06 66 75 7A 7A</p>
<p class="MsoNormal">Second file:</p>
<p class="MsoNormal">FF FE 02 06 66 75 7A 7A</p>
<p class="MsoNormal">Third file:</p>
<p class="MsoNormal">FF FE 03 06 66 75 7A 7A</p>
<p class="MsoNormal">So the “Depth” option just concentrates on one byte location at a time.</p>
<p class="MsoNormal">These options given to us by Sutton are pretty limiting. When I first used this and generated my first case of malformed zip files for fuzzing I used the “All Bytes” function to create files for 0&#215;00 (x 1) which gave me files for 0&#215;00, then I generated files with 0&#215;00 (x2) which gave me 0&#215;0000, then 0&#215;00 (x3) which is 0&#215;000000, and finally (x4) 0&#215;00000000, I did the same for 0xFF, 0&#215;01, 0&#215;80, 0&#215;10, 0&#215;3F, 0X7F and a few others.</p>
<p class="MsoNormal">I had generated a bunch but in the end I had to enter the Byte(s) to Overwrite / flip to (0&#215;00, 0xFF, 0&#215;01, 0&#215;80, 0&#215;10, 0&#215;3F, 0X7F, etc.) and the number of bytes to overwrite (1-4) and for each instance I had to enter the information in FileFuzz manually.</p>
<p class="MsoNormal">Well, luckily it came with the source code. What I did was I modified the “All Bytes” function to go ahead and produce a lot of malformed files for different cases without having to enter in the data in FileFuzz each time.</p>
<p class="MsoNormal">The different cases are the following at the moment:</p>
<p class="MsoNormal">It will generate files using “Bytes to Overwrite” with values of 0&#215;00 and 0xFF and the number of bytes to overwrite from 1-4.</p>
<p class="MsoNormal">I also prepend and append the following values if the number of bytes is &gt;= 2:</p>
<p class="MsoNormal">&#8220;00&#8243;, &#8220;FF&#8221;, &#8220;3F&#8221;, &#8220;7F&#8221;, &#8220;01&#8243;, &#8220;02&#8243;, &#8220;80&#8243;, &#8220;FE&#8221;, &#8220;10&#8243;, &#8220;20&#8243;, &#8220;40&#8243;, &#8220;60&#8243;</p>
<p class="MsoNormal">So, if the “Bytes to Overwrite” is 0&#215;00 and the number of bytes is 1 then it will simply overwrite each byte at a time with 0&#215;00.</p>
<p class="MsoNormal">If the “Bytes to Overwrite” is 0&#215;00 and the number of bytes is 2 then it will create the following values to bit flip each bit location with:</p>
<p class="MsoNormal">0&#215;0000</p>
<p class="MsoNormal">0xFF00</p>
<p class="MsoNormal">0&#215;3F00</p>
<p class="MsoNormal">0&#215;7F00</p>
<p class="MsoNormal">0&#215;0100</p>
<p class="MsoNormal">0&#215;0200</p>
<p class="MsoNormal">0&#215;8000</p>
<p class="MsoNormal">0xFE00</p>
<p class="MsoNormal">0&#215;1000</p>
<p class="MsoNormal">0&#215;2000</p>
<p class="MsoNormal">0&#215;4000</p>
<p class="MsoNormal">0&#215;6000</p>
<p class="MsoNormal">0&#215;00FF</p>
<p class="MsoNormal">0&#215;003F</p>
<p class="MsoNormal">0&#215;007F</p>
<p class="MsoNormal">0&#215;0001</p>
<p class="MsoNormal">0&#215;0002</p>
<p class="MsoNormal">0&#215;0080</p>
<p class="MsoNormal">0&#215;00FE</p>
<p class="MsoNormal">0&#215;0010</p>
<p class="MsoNormal">0&#215;0020</p>
<p class="MsoNormal">0&#215;0040</p>
<p class="MsoNormal">0&#215;0060</p>
<p class="MsoNormal">Then for good measure I if the number of bytes to overwrite is &gt;= 2 then I also prepend the values with 7F and append the value with FE. In which case I’d also generate files with bits that flip to</p>
<p class="MsoNormal">0&#215;7FFE</p>
<p class="MsoNormal">0&#215;7FFFFE</p>
<p class="MsoNormal">0&#215;7FFFFFFE</p>
<p class="MsoNormal">In the end, it’s a lot of test cases – which brings me to my next thought: creating the base test file which FileFuzz will use to do the mutations against.</p>
<p class="MsoNormal">So, at first I thought it was important to use a very simple test file (for example in my zip test base file I zipped up one text file in a directory that had like 4 bytes written in it). The goal was to keep the file simple and small – because brute force fuzzing (bit flipping) is inefficient. We want to focus on the file headers not the data itself. For example, if I was fuzzing a JPEG I’d want to create a JPEG image with like a 1 x 1 white pixel.</p>
<p class="MsoNormal">My base test zip file is 248 bytes, which by my modified FileFuzz I got back 36207 different files to fuzz.</p>
<p class="MsoNormal">If we used a meduim or large (any format type) file the amount of files we&#8217;d generate would be way too much to realistically try and fuzz &#8211; it would generate way too many test cases, and most of them would be useless because we&#8217;d be fuzzing mostly the data in the file, not the headers (the stuff we generally really care about).</p>
<p class="MsoNormal">Which makes total sense. However, there are some files (like, say randomly downloaded from the Internet) that have more and/or wacky extraneous stuff in the headers that seem to trip up programs much better than just some simple vanilla test file that you create yourself.</p>
<p class="MsoNormal">For instance, I&#8217;ve fuzzed programs with pdf files using a base test case with the same data content (the word &#8220;test&#8221; in the pdf file, highlighted, bolded, red in color, etc.) from a pdf generated from a Microsoft Word plugin and a pdf generated from a different program. One made Adobe reader crash and the other one didn&#8217;t.</p>
<p class="MsoNormal">So I modified another version of FileFuzz: one that  has a modified Range of bytes functionality. The modifications I did to the previous version only pertained to the All bytes functionality. Now with this newer version we can modify a range of bytes in the file. This way we can concentrate on just fuzzing interesting ranges of a larger file (like the file headers).</p>
<p class="MsoNormal">Also &#8211; there was a bug in FileFuzz that I had to fix. It kept crapping out on me when generating certain files (generally larger ones over a certain size) and I tracked the problem down to line 78 in Read.cs:</p>
<p>while (brSourceFile.PeekChar() != -1)</p>
<p>has to be changed to this:</p>
<p>while (brSourceFile.BaseStream.Position != brSourceFile.BaseStream.Length)</p>
<p>So this thing is semi-interesting too.</p>
<p>So, just for the background info here’s brSourceFile being declared:</p>
<p>private BinaryReader brSourceFile;</p>
<p>instantiated like this:</p>
<p>brSourceFile = new BinaryReader(File.Open(sourceFile, FileMode.Open));</p>
<p>Then later in the code we get the while loop to read the data from our test file:</p>
<p>while (brSourceFile.PeekChar() != -1){</p>
<p>//readfile…</p>
<p>}</p>
<p>Turns out the problem is in PeekChar(). This method tries to peek at a char (with UTF8 encoding as default) and can get into an error state if it sees a byte that it can’t understand.</p>
<p>I guess Microsoft is “actively looking to obsolete BinaryReader.PeekChar in a future release since it has some design issues.”</p>
<p>Heh – I guess PeekChar() is a method in the BinaryReader class that can only handle chars (not binary as the class name suggests)</p>
<p class="MsoNormal">Anyways, if anyone comes up with more interesting datasets to use for brute-force fuzzing or any other thoughts on how I might improve my modified version of FileFuzz let me know&#8230;</p>
<p class="MsoNormal">Cheers,</p>
<p class="MsoNormal">Chuck B.</p>
]]></content:encoded>
			<wfw:commentRss>http://anautonomouszone.com/blog/archives/14/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
