美文网首页
注入waf绕过(进阶)

注入waf绕过(进阶)

作者: 喵了个咪0 | 来源:发表于2020-03-02 14:06 被阅读0次

https://www.cnblogs.com/backlion/p/10569976.html

一·  利用pipline绕过[该方法经测试会被某狗拦截]

原理

http协议是由tcp协议封装而来,当浏览器发起一个http请求时,浏览器先和服务器建立起连接tcp连接,然后发送http数据包(即我们用burpsuite截获的数据),其中包含了一个Connection字段,一般值为close,apache等容器根据这个字段决定是保持该tcp连接或是断开。当发送的内容太大,超过一个http包容量,需要分多次发送时,值会变成keep-alive,即本次发起的http请求所建立的tcp连接不断开,直到所发送内容结束Connection为close为止。

1. 关闭burp的Repeater的Content-Length自动更新,如图四所示,点击红圈的Repeater在下拉选项中取消update Content-Length选中。这一步至关重要!!!

2. burp截获post提交

id=1and1=1

,显示被waf拦截如图五所示。

3. 复制图五中的数据包黏贴到

id=1and1=1

后面如图六所示。

4. 接着修改第一个数据包的数据部分,即将

id=1+and+1%3D1

修改为正常内容id=1,再将数据包的Content-Length的值设置为修改后的【id=1】的字符长度即4,最后将Connection字段值设为keep-alive。提交后如图七所示,会返回两个响应包,分别对应两个请求。

注意:从结果看,第一个正常数据包返回了正确内容,第二个包含有效载荷的数据包被某狗waf拦截,说明两数据包都能到达服务器,在面对其他waf时有可能可以绕过。无论如何这仍是一种可学习了解的绕过方法,且可以和接下来的方法进行组合使用绕过。

二.利用分块编码传输绕过[该方法可绕某狗]

原理:

在头部加入 Transfer-Encoding: chunked 之后,就代表这个报文采用了分块编码。这时,post请求报文中的数据部分需要改为用一系列分块来传输。每个分块包含十六进制的长度值和数据,长度值独占一行,长度不包括它结尾的,也不包括分块数据结尾的,且最后需要用0独占一行表示结束。

1. 开启上个实验中已关闭的content-length自动更新。给post请求包加入Transfer-Encoding: chunked后,将数据部分id=1 and 1=1进行分块编码(注意长度值必须为十六进制数),每一块里长度值独占一行,数据占一行如图八所示。

2.将上面图八数据包的

id=1and1=1

改为

id=1and1=2

 即将图八中所标的第4块的1改为2。如图九所示没有返回数据,payload生效。

注意:分块编码传输需要将关键字and,or,select ,union等关键字拆开编码,不然仍然会被waf拦截。编码过程中长度需包括空格的长度。最后用0表示编码结束,并在0后空两行表示数据包结束,不然点击提交按钮后会看到一直处于waiting状态。

三.利用协议未覆盖进行绕过[同样会被某狗拦截]

原理:

HTTP头里的Content-Type一般有application/x-www-form-urlencoded,multipart/form-data,text/plain三种,其中multipart/form-data表示数据被编码为一条消息,页上的每个控件对应消息中的一个部分。所以,当waf没有规则匹配该协议传输的数据时可被绕过。

1.将头部Content-Type改为multipart/form-data; boundary=69   然后设置分割符内的Content-Disposition的name为要传参数的名称。数据部分则放在分割结束符上一行。

由于是正常数据提交,所以从图十可知数据是能被apache容器正确解析的,尝试1 and 1=1也会被某狗waf拦截,但如果其他waf没有规则拦截这种方式提交的数据包,那么同样能绕过。

2.一般绕waf往往需要多种方式结合使用,如图十的示例中,只需将数据部分1 and 1=1用一个小数点”.”当作连接符即1.and 1=1就可以起到绕过作用。当然,这只是用小数点当连接符所起的作用而已。如图十一所示。

四.分块编码+协议未覆盖组合绕过

1.在协议未覆盖的数据包中加入Transfer-Encoding: chunked ,然后将数据部分全部进行分块编码,如图十二所示(数据部分为1 and 1=1)。

注意:第2块,第3块,第7块,和第8块。

第2块中需要满足

长度值 空行 Content-Disposition: name="id"空行

这种形式,且长度值要将两个空行的长度计算在内(空行长度为2)。

第3块,即数据开始部分需满足

长度值 空行 数据

形式,且需将空行计算在内。

第7块即分割边界结束部分,需满足

长度值 空行 分割结束符 空行

形式,且计算空行长度在内。

第8块需满足

0空行 空行

形式。如果不同时满足这四块的形式要求,payload将不会生效。

0x04  绕过WAF技巧

一、技巧1:使用注释扰乱分块数据包

一些如Imperva,360等比较好的WAF已经对传输编码的分块传输做了处理,可以把分块组合成完整的HTTP数据包,这时直接使用常规的分块传输方法尝试绕过的话,会被WAF直接识别并阻断。

我们可以在[RFC7230]中查看到有关分块传输的定义规范。

Chunked Transfer Coding: The chunked transfer coding wraps the payload body

in order to

  transfer it as a series of chunks, each with its own size indicator,

  followed by an OPTIONAL trailer containing header fields.  Chunked

  enables content streams of unknown size to be transferred as a

  sequence of length-delimited buffers, which enables the sender to

  retain connection persistence and the recipient to know when it has

  received the entire message.

    chunked-body  = *chunk

                      last-chunk

                      trailer-part

                      CRLF

    chunk          = chunk-size [ chunk-ext ] CRLF

                      chunk-data CRLF

    chunk-size    =1*HEXDIG

    last-chunk    =1*("0") [ chunk-ext ] CRLF

    chunk-data    =1*OCTET ; a sequence of chunk-size octets

  The chunk-size fieldisastring of hex digits indicating the size of

  the chunk-datainoctets.  The chunked transfer codingis complete

  when a chunk with a chunk-size of zerois received, possibly followed

  by a trailer, andfinally terminated by an empty line.

  A recipient MUST be able to parse and decode the chunked transfer

  coding.

Chunk Extensions:

  The chunked encoding allows each chunk to include zero or more chunk

  extensions, immediately following the chunk-size,for the sake of

  supplying per-chunk metadata (suchas a signature or hash),

  mid-message control information, or randomization of message body

  size.

    chunk-ext      = *(";"chunk-ext-name ["="chunk-ext-val ] )

    chunk-ext-name = token

    chunk-ext-val  = token / quoted-string  The chunked encoding is specific to each connection andis likely to

  be removed or recoded by each recipient (including intermediaries)

  before any higher-level application would have a chance to inspect

  the extensions.  Hence, use of chunk extensions isgenerally limited

通过阅读规范发现分块传输可以在长度标识处加上分号“;”作为注释,如:

9;kkkkk1234567=14;ooo=22223450(两个换行)

几乎所有可以识别传输编码数据包的WAF,都没有处理分块数据包中长度标识处的注释,导致在分块数据包中加入注释的话,WAF就识别不出这个数据包了。

现在我们在使用了Imperva的应用防火墙的网站测试常规的分块传输数据包:

POST /xxxxxx.jsp HTTP/1.1 ......

Transfer-Encoding: Chunked9xxxxxxxxx9xx=xxxxxx9xxxxxxxxx1d9&a=1    and    32=20(两个换行)

返回的结果如下图所示。

可以看到我们的攻击有效载荷“和2 = 2”被Imperva的WAF拦截了。

这时我们将分块传输数据包加入注释符。

POST /xxxxxx.jsp HTTP/1.1......

Transfer-Encoding: Chunked9xxxxxxxxx9xx=xxxxxx9xxxxxxxxx1;testsdasdsad

d9;test&a=1    and    3;test444442=20(两个换行)

返回的结果如下图所示。

可以看到Imperva的已经不拦截这个负荷了。

二、技巧2:绕过ModSecurity

众所周知的ModSecurity是加载在中间件上的插件,所以不需要理会解析HTTP数据包的问题,因为中间件已经帮它处理完了,那么无论使用常规的分块还是加了注释的分块数据包,ModSecurity的都能直接获取到完整的HTTP数据包然后匹配危险关键字,所以一些基于ModSecurity的做的WAF产品难道就不受影响吗?

接下来我们在apache+ ModSecurity的环境做测试。

sql.php代码如下:

ini_set("display_errors","On");

error_reporting(E_ALL);

$con = mysql_connect("localhost","root","");if(!$con)

{

    die('Could not connect: ' . mysql_error());

}

mysql_select_db("test", $con);

$id = $_REQUEST["id"];

$sql ="select * from user where id=$id";

$result = mysql_query($sql,$con);while($row = mysql_fetch_array($result))

{

    echo $row['name'] ."". $row['password']."n";

}

mysql_close($con);

print"========GET==========n";

print_r($_GET);

print"========POST==========n";

print_r($_POST);?> sdfsdf

ModSecurity的加载的规则拦截了请求包中的关键字“联盟”。

下面我们的请求和返回结果如下:

请求: http://10.10.10.10/sql.php?id=2%20union 返回:

404Not Found

Not Found

The requested URL /sql.php was not found onthisserver.


Apache/2.2.15(CentOS) Server at10.10.10.10Port80

可以看到我们的“联盟”关键字被拦截了。

接下来我们传输一个畸形的分块数据包看看。

请求: POST /sql.php?id=2%20union HTTP/1.1 ...... Transfer-Encoding: chunked 1 aa 0 (两个换行) 返回:

400Bad Request

Bad Request

Your browser sent a request thatthisserver could not understand.


Apache/2.2.15(CentOS) Server at10.10.10.10Port80========GET==========Array

(

  [id] =>2 union

)========POST==========Array

(

)

可以看到虽然apache的报错了,但是因为apache的容错很强,所以我们提交的参数依然传到了PHP中,而我们的ModSecurity的并没有处理400错误的数据包,最终绕过了ModSecurity的。

接下来我们把的ModSecurity的规则改为过滤返回数据中包含的“根”的字符串,然后在sql.php脚本中加入打印“根”关键字的代码。

接着我们做如下测试:

请求: http:

//10.10.10.10/sql.php?id=1返回:

403Forbidden

Forbidden

You don't have permission to access /sql.phponthisserver.


Apache/2.2.15(CentOS) Server at10.10.10.10Port80

因为sql.php脚本中返回了带有“根”的关键字,所以直接就被ModSecurity的拦截了。这时我们改为发送畸形的分块数据包。

请求: POST /sql.php?id=

HTTP/1.1Host: 10.10.10.10Connection: keep-alive

Content-Type: application/x-www-form-urlencoded

Transfer-Encoding: chunked

Content-Length:16312310(两个换行)

返回:

400Bad Request

Bad Request

Your browser sent a request thatthisserver could not understand.


Apache/2.2.15(CentOS) Server at10.10.10.10Port80root 123456========GET==========Array

(

  [id] =>1)========POST==========Array

(

)

通过两个测试可以发现使用畸形的分块数据包可以直接绕过的ModSecurity的检测。这个问题我们在2017年4月已提交给了ModSecurity官方,但是因为种种问题目前依然未修复。

相关文章

  • 注入waf绕过(进阶)

    https://www.cnblogs.com/backlion/p/10569976.html 一· 利用pip...

  • 🎪waf绕过

    ? waf注入绕过检测方法 云waf直接找真实ip就可绕过 方法总结:绕过waf的方法: 1、白名单绕过2、大小写...

  • sql 注入绕过waf

    6.特殊符号 特殊字符是什么?除了字符串和数字都是特殊字符 比如~!@#¥%…………&*()— 乌云的一篇waf绕...

  • 注入waf绕过(基础)

    sql注入过滤的绕过 一直感觉自己的注入技术太过垃圾,这里利用python来测试一下如果利用等价的字符来绕过特定...

  • Sql 注入 绕过 WAF

    1.大小写绕过 2.替换关键字 3.URL双重编码 4.使用注释 5.同功能的函数替换 6.特殊符号 7.HTTP...

  • [SQL注入]一些绕过WAF的技术

    [SQL注入]一些绕过WAF的技术 本文是在各种方法的WAF的总结,我们可以在测试bypass WAF使用下面的方...

  • 绕过waf进行SQL注入

    转自:https://security.tencent.com/index.php/blog/msg/66 waf...

  • 绕过waf方法

    参考:绕过WAF、安全狗知识整理 - 珍惜少年时 - 博客园 SQL注入 | 9种绕过Web应用程序防火墙的方式 ...

  • 11.绕过waf sql注入

    绕过waf的方法:1.白名单、2改变请求方法、3.大小写绕过 、4.url编码绕过、5.组合绕过、6.复参数绕过7...

  • sql注入绕过安全狗waf

    看了某个师傅sql注入绕过安全狗waf的文章,自己搭建平台重现一番。 环境部署 安装phpstudy: 安全狗关闭...

网友评论

      本文标题:注入waf绕过(进阶)

      本文链接:https://www.haomeiwen.com/subject/bggphhtx.html