You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pentesting-cloud/gcp-security/gcp-privilege-escalation/gcp-compute-privesc/gcp-add-custom-ssh-metadata.md
### Modifying the metadata <ahref="#modifying-the-metadata"id="modifying-the-metadata"></a>
5
+
## Modifying the metadata <ahref="#modifying-the-metadata"id="modifying-the-metadata"></a>
10
6
11
7
Metadata modification on an instance could lead to **significant security risks if an attacker gains the necessary permissions**.
12
8
13
-
####**Incorporation of SSH Keys into Custom Metadata**
9
+
### **Incorporation of SSH Keys into Custom Metadata**
14
10
15
11
On GCP, **Linux systems** often execute scripts from the [Python Linux Guest Environment for Google Compute Engine](https://github.com/GoogleCloudPlatform/compute-image-packages/tree/master/packages/python-google-compute-engine#accounts). A critical component of this is the [accounts daemon](https://github.com/GoogleCloudPlatform/compute-image-packages/tree/master/packages/python-google-compute-engine#accounts), which is designed to **regularly check** the instance metadata endpoint for **updates to the authorized SSH public keys**.
16
12
17
13
Therefore, if an attacker can modify custom metadata, he could make the the daemon find a new public key, which will processed and **integrated into the local system**. The key will be added into `~/.ssh/authorized_keys` file of an **existing user or potentially creating a new user with `sudo` privileges**, depending on the key's format. And the attacker will be able to compromise the host.
18
14
19
-
####**Add SSH key to existing privileged user**
15
+
### **Add SSH key to existing privileged user**
20
16
21
17
1.**Examine Existing SSH Keys on the Instance:**
22
18
@@ -57,7 +53,7 @@ Therefore, if an attacker can modify custom metadata, he could make the the daem
57
53
sudo id
58
54
```
59
55
60
-
#### **Create a new privileged user and add a SSH key**
56
+
### **Create a new privileged user and add a SSH key**
61
57
62
58
If no interesting user is found, it's possible to create a new one which will be given `sudo` privileges:
#### SSH keys at project level <a href="#sshing-around" id="sshing-around"></a>
78
+
### SSH keys at project level <a href="#sshing-around" id="sshing-around"></a>
83
79
84
80
It's possible to broaden the reach of SSH access to multiple Virtual Machines (VMs) in a cloud environment by **applying SSH keys at the project level**. This approach allows SSH access to any instance within the project that hasn't explicitly blocked project-wide SSH keys. Here's a summarized guide:
0 commit comments