<summary><strong>Jifunze kuhusu kudukua AWS kutoka sifuri hadi shujaa na</strong><ahref="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
* Ikiwa unataka kuona **kampuni yako inatangazwa kwenye HackTricks** au **kupakua HackTricks kwa muundo wa PDF** Angalia [**MPANGO WA KUJIUNGA**](https://github.com/sponsors/carlospolop)!
* Pata [**swag rasmi ya PEASS & HackTricks**](https://peass.creator-spring.com)
* Gundua [**The PEASS Family**](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** 🐦 [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.**
* **Shiriki mbinu zako za kudukua kwa kuwasilisha PR kwa** [**HackTricks**](https://github.com/carlospolop/hacktricks) na [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) repos za github.
Bahati nzuri, PHP kwa sasa mara nyingi hutumiwa kupitia PHP-FPM na Nginx. Nginx inatoa kipengele cha [kubadilisha mwili wa mteja](https://nginx.org/en/docs/http/ngx\_http\_core\_module.html#client\_body\_buffer\_size) ambacho kinaweza kusababisha kuandikwa kwa faili za muda ikiwa mwili wa mteja (si mdogo kwa post) ni kubwa kuliko kizingiti fulani.
Kipengele hiki kinawezesha LFIs kudukuliwa bila njia nyingine yoyote ya kuunda faili, ikiwa Nginx inaendeshwa kama mtumiaji sawa na PHP (ambayo mara nyingi hufanyika kama www-data).
Inaonekana kwamba **tempfile inafutwa mara moja** baada ya kufunguliwa na Nginx. Bahati nzuri **procfs inaweza kutumika bado kupata kumbukumbu** ya faili iliyofutwa kupitia mbio:
Maelezo: Hapa huwezi kuingiza moja kwa moja `/proc/34/fd/15` kwenye mfano huu kwa sababu PHP's `include` itatatua njia kuwa `/var/lib/nginx/body/0000001368 (imefutwa)` ambayo haipo kwenye mfumo wa faili. Kizuizi kidogo hiki kinaweza kuepukwa kwa kutumia njia ya kuelekeza kama vile: `/proc/self/fd/34/../../../34/fd/15` ambayo mwishowe itatekeleza maudhui ya faili iliyofutwa `/var/lib/nginx/body/0000001368`.
In some cases, a Local File Inclusion (LFI) vulnerability can be escalated to Remote Code Execution (RCE) by exploiting temporary files created by the Nginx web server. This technique can be used to gain unauthorized access to the target system and execute arbitrary commands.
## Exploitation
1. Identify the LFI vulnerability: Look for user-controllable input points where file inclusion is possible, such as URL parameters or cookies.
2. Exploit the LFI vulnerability: Inject a payload that includes the path to the Nginx temporary directory. This can be achieved by appending the payload to the file parameter, for example: `http://example.com/index.php?page=/var/tmp/nginx/client_body/xxxxx.php`.
3. Trigger the creation of a temporary file: Access the URL containing the payload to trigger the creation of the temporary file on the server.
4. Execute the payload: Access the temporary file by appending its name to the URL, for example: `http://example.com/index.php?page=/var/tmp/nginx/client_body/xxxxx.php`.
## Mitigation
To prevent LFI to RCE via Nginx temp files, consider the following mitigation techniques:
- File permissions: Ensure that the Nginx temporary directory has appropriate permissions to prevent unauthorized access.
- File deletion: Regularly clean up temporary files to minimize the risk of exploitation.
- Web server hardening: Follow best practices for securing the Nginx web server, such as disabling unnecessary features and applying security patches.
By implementing these mitigation techniques, you can reduce the risk of LFI to RCE via Nginx temp files and enhance the security of your web application.
Hii ni kutoka [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>Jifunze kuhusu kudukua AWS kutoka sifuri hadi shujaa na</strong><ahref="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
* Ikiwa unataka kuona **kampuni yako inatangazwa kwenye HackTricks** au **kupakua HackTricks kwa PDF** Angalia [**MPANGO WA KUJIUNGA**](https://github.com/sponsors/carlospolop)!
* Pata [**swag rasmi wa PEASS & HackTricks**](https://peass.creator-spring.com)
* Gundua [**The PEASS Family**](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** 🐦 [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.**
* **Shiriki mbinu zako za kudukua kwa kuwasilisha PR kwa** [**HackTricks**](https://github.com/carlospolop/hacktricks) na [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) repos za github.