Skip to content

Commit 5fd9ed5

Browse files
authored
Update gcp-add-custom-ssh-metadata.md
1 parent 3157069 commit 5fd9ed5

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/pentesting-cloud/gcp-security/gcp-privilege-escalation/gcp-compute-privesc/gcp-add-custom-ssh-metadata.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,17 @@
22

33
{{#include ../../../../banners/hacktricks-training.md}}
44

5-
## GCP - Add Custom SSH Metadata
6-
7-
8-
9-
### Modifying the metadata <a href="#modifying-the-metadata" id="modifying-the-metadata"></a>
5+
## Modifying the metadata <a href="#modifying-the-metadata" id="modifying-the-metadata"></a>
106

117
Metadata modification on an instance could lead to **significant security risks if an attacker gains the necessary permissions**.
128

13-
#### **Incorporation of SSH Keys into Custom Metadata**
9+
### **Incorporation of SSH Keys into Custom Metadata**
1410

1511
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**.
1612

1713
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.
1814

19-
#### **Add SSH key to existing privileged user**
15+
### **Add SSH key to existing privileged user**
2016

2117
1. **Examine Existing SSH Keys on the Instance:**
2218

@@ -57,7 +53,7 @@ Therefore, if an attacker can modify custom metadata, he could make the the daem
5753
sudo id
5854
```
5955

60-
#### **Create a new privileged user and add a SSH key**
56+
### **Create a new privileged user and add a SSH key**
6157

6258
If no interesting user is found, it's possible to create a new one which will be given `sudo` privileges:
6359
@@ -79,7 +75,7 @@ gcloud compute instances add-metadata [INSTANCE_NAME] --metadata-from-file ssh-k
7975
ssh -i ./key "$NEWUSER"@localhost
8076
```
8177
82-
#### 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>
8379
8480
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:
8581

0 commit comments

Comments
 (0)