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,59 +4,58 @@
## Lambda
Amazon Web Services (AWS) Lambda is described as a **compute service** that enables the execution of code without the necessity for server provision or management. It is characterized by its ability to **automatically handle resource allocation** needed for code execution, ensuring features like high availability, scalability, and security. A significant aspect of Lambda is its pricing model, where **charges are based solely on the compute time utilized**, eliminating the need for initial investments or long-term obligations.
Amazon Web Services (AWS) Lambda è descritta come un **servizio di calcolo** che consente l'esecuzione di codice senza la necessità di provisioning o gestione dei server. È caratterizzata dalla sua capacità di **gestire automaticamente l'allocazione delle risorse** necessarie per l'esecuzione del codice, garantendo funzionalità come alta disponibilità, scalabilità e sicurezza. Un aspetto significativo di Lambda è il suo modello di pricing, dove **i costi sono basati esclusivamente sul tempo di calcolo utilizzato**, eliminando la necessità di investimenti iniziali o obblighi a lungo termine.
To call a lambda it's possible to call it as **frequently as you wants** (with Cloudwatch), **expose** an **URL** endpoint and call it, call it via **API Gateway** or even based on **events** such as **changes** to data in a **S3** bucket or updates to a **DynamoDB** table.
Per chiamare una lambda è possibile invocarla **con la frequenza desiderata** (con Cloudwatch), **esporre** un **endpoint URL** e chiamarlo, invocarlo tramite **API Gateway** o anche in base a **eventi** come **cambiamenti** nei dati in un **S3** bucket o aggiornamenti a una tabella **DynamoDB**.
The **code** of a lambda is stored in **`/var/task`**.
Il **codice** di una lambda è memorizzato in **`/var/task`**.
### Lambda Aliases Weights
A Lambda can have **several versions**.\
And it can have **more than 1** version exposed via **aliases**. The **weights** of **each** of the **versions** exposed inside and alias will decide **which alias receive the invocation** (it can be 90%-10% for example).\
If the code of **one** of the aliases is **vulnerable** you can send **requests until the vulnerable** versions receives the exploit.
Una Lambda può avere **diverse versioni**.\
E può avere **più di 1** versione esposta tramite **alias**. I **pesi** di **ciascuna** delle **versioni** esposte all'interno di un alias decideranno **quale alias riceve l'invocazione** (può essere 90%-10% ad esempio).\
Se il codice di **uno** degli alias è **vulnerabile**, puoi inviare **richieste fino a quando la versione vulnerabile** riceve l'exploit.
![](<../../../images/image (223).png>)
### Resource Policies
Lambda resource policies allow to **give access to other services/accounts to invoke** the lambda for example.\
For example this is the policy to allow **anyone to access a lambda exposed via URL**:
Le politiche delle risorse Lambda consentono di **dare accesso ad altri servizi/account per invocare** la lambda, ad esempio.\
Ad esempio, questa è la politica per consentire **a chiunque di accedere a una lambda esposta tramite URL**:
<figure><img src="https://lh4.googleusercontent.com/4PNFKBdzr3nMrPqeKkTslgwWDKxkXMdQ1SNdv7NPHykj3GX8wODrQyXOFbjk4fxHfZ8pDm5ijWgk2Vq2EGXiPRT3TQfZf1fHycvdEKBuDxJDYos1CJeMHXSeg86ZB-Ol7CNtten6xkVFQj6AhDUEWNQJrQ=s2048" alt=""><figcaption></figcaption></figure>
Or this to allow an API Gateway to invoke it:
O questa per consentire a un API Gateway di invocarla:
<figure><img src="https://lh3.googleusercontent.com/Su0JlR0wBqb-99Z4N_2-_kMlX0Xzx2n_GpZuOPW5IeXR3FYbm8OHFDM3Ora1BpXiSjHpDVUlq4yEyXwaI3nBuze6DJ-wRf2ATsCuWbq0wuBCd34E9uIpqwheE6Cc_PopviI_93O_j2ZKXc1-AJtsBoLVUw=s2048" alt=""><figcaption></figcaption></figure>
### Lambda Database Proxies
When there are **hundreds** of **concurrent lambda requests**, if each of them need to **connect and close a connection to a database**, it's just not going to work (lambdas are stateless, cannot maintain connections open).\
Then, if your **Lambda functions interact with RDS Proxy instead** of your database instance. It handles the connection pooling necessary for scaling many simultaneous connections created by concurrent Lambda functions. This allows your Lambda applications to **reuse existing connections**, rather than creating new connections for every function invocation.
Quando ci sono **centinaia** di **richieste lambda concorrenti**, se ognuna di esse deve **connettersi e chiudere una connessione a un database**, semplicemente non funzionerà (le lambdas sono senza stato, non possono mantenere le connessioni aperte).\
Quindi, se le tue **funzioni Lambda interagiscono con RDS Proxy invece** della tua istanza di database. Gestisce il pooling delle connessioni necessario per scalare molte connessioni simultanee create da funzioni Lambda concorrenti. Questo consente alle tue applicazioni Lambda di **riutilizzare le connessioni esistenti**, piuttosto che creare nuove connessioni per ogni invocazione della funzione.
### Lambda EFS Filesystems
To preserve and even share data **Lambdas can access EFS and mount them**, so Lambda will be able to read and write from it.
Per preservare e persino condividere i dati, **le Lambdas possono accedere a EFS e montarle**, in modo che Lambda possa leggere e scrivere da esse.
### Lambda Layers
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.
Un layer Lambda è un archivio .zip che **può contenere codice aggiuntivo** o altro contenuto. Un layer può contenere librerie, un [runtime personalizzato](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html), dati o file di configurazione.
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.
È possibile includere fino a **cinque layer per funzione**. Quando includi un layer in una funzione, i **contenuti vengono estratti nella directory `/opt`** nell'ambiente di esecuzione.
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.
Per **definizione**, i **layer** che crei sono **privati** al tuo account AWS. Puoi scegliere di **condividere** un layer con altri account o di **rendere** il layer **pubblico**. Se le tue funzioni consumano un layer pubblicato da un account diverso, le tue funzioni possono **continuare a utilizzare la versione del layer dopo che è stata eliminata, o dopo che il tuo permesso di accesso al layer è stato revocato**. Tuttavia, non puoi creare una nuova funzione o aggiornare funzioni utilizzando una versione di layer eliminata.
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.
Le funzioni distribuite come immagine del contenitore non utilizzano layer. Invece, impacchetti il tuo runtime preferito, librerie e altre dipendenze nell'immagine del contenitore quando costruisci l'immagine.
### Lambda Extensions
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**.
Le estensioni Lambda migliorano le funzioni integrandosi con vari **strumenti di monitoraggio, osservabilità, sicurezza e governance**. Queste estensioni, aggiunte tramite [.zip archivi utilizzando i layer Lambda](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html) o incluse nelle [distribuzioni di immagini del contenitore](https://aws.amazon.com/blogs/compute/working-with-lambda-layers-and-extensions-in-container-images/), operano in due modalità: **interna** ed **esterna**.
- **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**.
- Le **estensioni interne** si fondono con il processo di runtime, manipolando il suo avvio utilizzando **variabili ambientali specifiche del linguaggio** e **script wrapper**. Questa personalizzazione si applica a una gamma di runtime, inclusi **Java Correto 8 e 11, Node.js 10 e 12, e .NET Core 3.1**.
- Le **estensioni esterne** vengono eseguite come processi separati, mantenendo l'allineamento operativo con il ciclo di vita della funzione Lambda. Sono compatibili con vari runtime come **Node.js 10 e 12, Python 3.7 e 3.8, Ruby 2.5 e 2.7, Java Corretto 8 e 11, .NET Core 3.1**, e **runtime personalizzati**.
### Enumeration
```bash
aws lambda get-account-settings
@@ -93,11 +92,9 @@ aws lambda list-event-source-mappings
aws lambda list-code-signing-configs
aws lambda list-functions-by-code-signing-config --code-signing-config-arn <arn>
```
### Invocare una lambda
### Invoke a lambda
#### Manual
#### Manuale
```bash
# Invoke function
aws lambda invoke --function-name FUNCTION_NAME /tmp/out
@@ -106,83 +103,70 @@ aws lambda invoke --function-name FUNCTION_NAME /tmp/out
## user_name = event['user_name']
aws lambda invoke --function-name <name> --cli-binary-format raw-in-base64-out --payload '{"policy_names": ["AdministratorAccess], "user_name": "sdf"}' out.txt
```
#### Via exposed URL
#### Via URL esposta
```bash
aws lambda list-function-url-configs --function-name <function_name> #Get lambda URL
aws lambda get-function-url-config --function-name <function_name> #Get lambda URL
```
#### Call Lambda function via URL
Now it's time to find out possible lambda functions to execute:
Ora è il momento di scoprire le possibili funzioni lambda da eseguire:
```
aws --region us-west-2 --profile level6 lambda list-functions
```
![](<../../../images/image (262).png>)
A lambda function called "Level6" is available. Lets find out how to call it:
Una funzione lambda chiamata "Level6" è disponibile. Scopriamo come chiamarla:
```bash
aws --region us-west-2 --profile level6 lambda get-policy --function-name Level6
```
![](<../../../images/image (102).png>)
Now, that you know the name and the ID you can get the Name:
Ora che conosci il nome e l'ID, puoi ottenere il Nome:
```bash
aws --profile level6 --region us-west-2 apigateway get-stages --rest-api-id "s33ppypa75"
```
![](<../../../images/image (237).png>)
And finally call the function accessing (notice that the ID, Name and function-name appears in the URL): [https://s33ppypa75.execute-api.us-west-2.amazonaws.com/Prod/level6](https://s33ppypa75.execute-api.us-west-2.amazonaws.com/Prod/level6)
E infine chiama la funzione accedendo (nota che l'ID, il Nome e il nome della funzione appaiono nell'URL): [https://s33ppypa75.execute-api.us-west-2.amazonaws.com/Prod/level6](https://s33ppypa75.execute-api.us-west-2.amazonaws.com/Prod/level6)
`URL:`**`https://<rest-api-id>.execute-api.<region>.amazonaws.com/<stageName>/<funcName>`**
#### Other Triggers
#### Altri Trigger
There are a lot of other sources that can trigger a lambda
Ci sono molte altre fonti che possono attivare un lambda
<figure><img src="../../../images/image (167).png" alt=""><figcaption></figcaption></figure>
### Privesc
In the following page you can check how to **abuse Lambda permissions to escalate privileges**:
Nella pagina seguente puoi controllare come **abusare dei permessi di Lambda per escalare i privilegi**:
{{#ref}}
../aws-privilege-escalation/aws-lambda-privesc.md
{{#endref}}
### Unauthenticated Access
### Accesso Non Autenticato
{{#ref}}
../aws-unauthenticated-enum-access/aws-lambda-unauthenticated-access.md
{{#endref}}
### Post Exploitation
### Post Sfruttamento
{{#ref}}
../aws-post-exploitation/aws-lambda-post-exploitation/
{{#endref}}
### Persistence
### Persistenza
{{#ref}}
../aws-persistence/aws-lambda-persistence/
{{#endref}}
## References
## Riferimenti
- [https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-concepts.html#gettingstarted-concepts-layer](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-concepts.html#gettingstarted-concepts-layer)
- [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/)
{{#include ../../../banners/hacktricks-training.md}}