<summary><strong>Naučite hakovanje AWS-a od nule do heroja sa</strong><ahref="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
* Ako želite da vidite **vašu kompaniju reklamiranu na HackTricks-u** ili **preuzmete HackTricks u PDF formatu** proverite [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)!
* **Pridružite se** 💬 [**Discord grupi**](https://discord.gg/hRep4RUj7f) ili [**telegram grupi**](https://t.me/peass) ili nas **pratite** na **Twitter-u** 🐦 [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.**
* **Podelite svoje hakovanje trikove slanjem PR-ova na** [**HackTricks**](https://github.com/carlospolop/hacktricks) i [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repozitorijume.
Srećom, PHP se trenutno često implementira putem PHP-FPM i Nginx-a. Nginx nudi lako previdljivu funkcionalnost [client body buffering](https://nginx.org/en/docs/http/ngx\_http\_core\_module.html#client\_body\_buffer\_size) koja će kreirati privremene fajlove ako je telo klijenta (ne samo ograničeno na POST) veće od određenog praga.
Ova funkcionalnost omogućava iskorišćavanje LFI-ja bez ikakvog drugog načina kreiranja fajlova, ukoliko Nginx radi kao isti korisnik kao i PHP (što je vrlo često slučaj, kao što je www-data).
Vidljivo je da se **privremena datoteka odmah uklanja** nakon što je otvorena od strane Nginx-a. Srećom, **procfs može se koristiti da se i dalje dobije referenca** na obrisani fajl putem trke:
Napomena: U ovom primeru nije moguće direktno uključiti `/proc/34/fd/15`, jer bi PHP-ova `include` funkcija razrešila putanju u `/var/lib/nginx/body/0000001368 (obrisano)`, koja ne postoji u fajl sistemu. Srećom, ovu manju restrikciju možemo zaobići korišćenjem neke vrste indirekcije kao što je `/proc/self/fd/34/../../../34/fd/15`, što će na kraju izvršiti sadržaj obrisanog fajla `/var/lib/nginx/body/0000001368`.
This technique allows an attacker to escalate a Local File Inclusion (LFI) vulnerability to Remote Code Execution (RCE) by exploiting Nginx temporary files.
## Exploitation
1. Identify the LFI vulnerability in the target web application.
2. Determine the location of the Nginx temporary directory. This can usually be found in the Nginx configuration file (`nginx.conf`).
3. Craft a payload that will write a malicious PHP file to the Nginx temporary directory. For example:
```php
<?php echo system($_GET['cmd']); ?>
```
4. Use the LFI vulnerability to include the crafted payload into a PHP file on the target server.
5. Trigger the inclusion of the PHP file containing the payload.
6. The payload will be executed by the server, resulting in remote code execution.
## Prevention
To prevent this type of attack, it is recommended to:
- Regularly update Nginx to the latest version.
- Restrict access to the Nginx temporary directory.
- Implement input validation and sanitization to prevent LFI vulnerabilities.
- Use a Web Application Firewall (WAF) to detect and block malicious requests.
Ovo je sa [https://lewin.co.il/winning-the-impossible-race-an-unintended-solution-for-includers-revenge-counter-hxp-2021/](https://lewin.co.il/winning-the-impossible-race-an-unintended-solution-for-includers-revenge-counter-hxp-2021/)
# This method creates a path from random amount of ProcFS path components. A generated path will look like /proc/<nginx pid 1>/cwd/proc/<nginx pid 2>/root/proc/<nginx pid 3>/root
<summary><strong>Naučite hakovanje AWS-a od nule do heroja sa</strong><ahref="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
* Ako želite da vidite **vašu kompaniju oglašenu na HackTricks-u** ili **preuzmete HackTricks u PDF formatu** proverite [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)!
* **Pridružite se** 💬 [**Discord grupi**](https://discord.gg/hRep4RUj7f) ili [**telegram grupi**](https://t.me/peass) ili nas **pratite** na **Twitter-u** 🐦 [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.**
* **Podelite svoje hakovanje trikove slanjem PR-ova na** [**HackTricks**](https://github.com/carlospolop/hacktricks) i [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repozitorijume.