mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-07-28 22:51:09 -07:00
Translated ['', 'src/pentesting-cloud/gcp-security/gcp-unauthenticated-e
This commit is contained in:
+105
-14
@@ -4,27 +4,27 @@
|
||||
|
||||
## API Keys
|
||||
|
||||
APIキーに関する詳細情報は、以下を確認してください:
|
||||
API Keys についての詳細は以下を確認してください:
|
||||
|
||||
{{#ref}}
|
||||
../gcp-services/gcp-api-keys-enum.md
|
||||
{{#endref}}
|
||||
|
||||
### OSINT技術
|
||||
### OSINT techniques
|
||||
|
||||
**Google APIキーは、クライアント側から使用されるあらゆる種類のアプリケーションで広く使用されています**。ウェブサイトのソースコードやネットワークリクエスト、モバイルアプリケーション、またはGithubのようなプラットフォームで正規表現を検索することで見つけることが一般的です。
|
||||
**Google API Keys are widely used by any kind of applications** that uses from the client side. ソースコードや network requests の中、mobile applications、または Github のような platform で regex を検索するだけで見つかることがよくあります。
|
||||
|
||||
正規表現は次のとおりです:**`AIza[0-9A-Za-z_-]{35}`**
|
||||
The regex is: **`AIza[0-9A-Za-z_-]{35}`**
|
||||
|
||||
例えば、Githubで次のように検索します:[https://github.com/search?q=%2FAIza%5B0-9A-Za-z\_-%5D%7B35%7D%2F\&type=code\&ref=advsearch](https://github.com/search?q=%2FAIza%5B0-9A-Za-z_-%5D%7B35%7D%2F&type=code&ref=advsearch)
|
||||
例えば Github で以下を使って検索できます: [https://github.com/search?q=%2FAIza%5B0-9A-Za-z\_-%5D%7B35%7D%2F\&type=code\&ref=advsearch](https://github.com/search?q=%2FAIza%5B0-9A-Za-z_-%5D%7B35%7D%2F&type=code&ref=advsearch)
|
||||
|
||||
### 元のGCPプロジェクトを確認
|
||||
### Check origin GCP project
|
||||
|
||||
これは、**見つけたAPIキーがどのGCPプロジェクトに属しているかを確認するのに非常に便利です**。いくつかのオプションがあります:
|
||||
これは、**見つけた API key がどの GCP project に属するか** を確認するのに非常に有用です。いくつかの方法があります:
|
||||
|
||||
- `https://www.googleapis.com/identitytoolkit/v3/relyingparty/getProjectConfig?key=<api-key>`に連絡します。
|
||||
- Contact `https://www.googleapis.com/identitytoolkit/v3/relyingparty/getProjectConfig?key=<api-key>`
|
||||
|
||||
簡潔さのために出力は切り捨てられましたが、完全な出力ではプロジェクトIDが5回以上表示されます。
|
||||
簡潔さのため出力は省略されていますが、完全な出力では project ID が 5 回以上表示されます
|
||||
```bash
|
||||
curl -s "https://www.googleapis.com/identitytoolkit/v3/relyingparty/getProjectConfig?key=AIzaSyD[...]uE8Y"
|
||||
|
||||
@@ -34,9 +34,9 @@ curl -s "https://www.googleapis.com/identitytoolkit/v3/relyingparty/getProjectCo
|
||||
"message": "Identity Toolkit API has not been used in project 943955951114 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/identitytoolkit.googleapis.com/overview?project=943955951114 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
|
||||
[...]
|
||||
```
|
||||
- `https://www.googleapis.com/identitytoolkit/v3/relyingparty/getProjectConfig?key=<api-key>` に連絡します。
|
||||
- `https://identitytoolkit.googleapis.com/v1/projects?key=<api-key>` に contact する
|
||||
|
||||
簡潔さのために出力は切り捨てられましたが、完全な出力にはプロジェクトIDが5回以上表示されます。
|
||||
簡潔さのため output は truncated されているが、complete output では project ID が 5回以上表示される
|
||||
```bash
|
||||
curl -s "https://identitytoolkit.googleapis.com/v1/projects?key=AIzaSyD[...]uE8Y"
|
||||
|
||||
@@ -46,7 +46,7 @@ curl -s "https://identitytoolkit.googleapis.com/v1/projects?key=AIzaSyD[...]uE8Y
|
||||
"message": "Identity Toolkit API has not been used in project 943955951114 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/identitytoolkit.googleapis.com/overview?project=943955951114 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
|
||||
[...]
|
||||
```
|
||||
- [この方法はもう機能しません!] `apikeys.keys.lookup`
|
||||
- [これはもう動作しません!] `apikeys.keys.lookup`
|
||||
```bash
|
||||
# If you have permissions
|
||||
gcloud services api-keys lookup AIzaSyD[...]uE8Y
|
||||
@@ -69,8 +69,99 @@ resource: projects/89123452509
|
||||
service: cloudresourcemanager.googleapis.com
|
||||
reason: AUTH_PERMISSION_DENIED
|
||||
```
|
||||
### ブルートフォースAPIエンドポイント
|
||||
### Discovery-document driven API recon
|
||||
|
||||
プロジェクトでどのAPIが有効になっているかわからない場合、ツール[https://github.com/ozguralp/gmapsapiscanner](https://github.com/ozguralp/gmapsapiscanner)を実行し、**APIキーで何にアクセスできるかを確認するのは興味深いでしょう。**
|
||||
有効な key を入手したら、目につく public API だけを試すのではなく、Google 環境では、**discovery documents** を machine-readable な attack-surface map として使え、**resources, methods, paths, HTTP verbs, parameters, and request/response schemas** を公開できます。
|
||||
|
||||
有用な target:
|
||||
```bash
|
||||
# Public / common path
|
||||
curl -s 'https://serviceusage.googleapis.com/$discovery/rest?key=<api-key>'
|
||||
|
||||
# Hidden docs behind a visibility label
|
||||
curl -s 'https://serviceusage.googleapis.com/$discovery/rest?labels=GOOGLE_INTERNAL&key=<api-key>'
|
||||
```
|
||||
Notes:
|
||||
|
||||
- `GOOGLE_INTERNAL` のようなラベルの有無で、document size と method count を比較する。
|
||||
- **真の nonexistent method** は通常 **HTML 404** を返す。`Method not found.` を含む **JSON 404** は、その method は存在するが **API key project に必要な visibility label が欠けている** ことを示している場合がある。
|
||||
- 一部の first-party APIs は、public API explorer よりも `*.clients6.google.com` や undocumented な `*-pa.googleapis.com` hosts 経由の方が到達しやすい。
|
||||
|
||||
これは特に、Internet に誤って exposed された **internal/admin APIs** を enumerate するのに有用で、JSON fields を手作業で推測する代わりに schema から custom fuzzers を作るのにも役立つ。
|
||||
|
||||
### Key ownership filtering at scale
|
||||
|
||||
APK、browser traffic、IPA、binary などから多くの Google API keys を収集した場合、**どの project が各 key を所有しているか**、またそれが target company に属するかを素早く識別したくなることがある。
|
||||
|
||||
実用的な手法として、key に対して **有効化されていない** API を意図的に呼び出す。Google はエラー内にバックエンドの **project number** を頻繁に leak する:
|
||||
```bash
|
||||
curl -s 'https://protos.googleapis.com/$discovery/rest?key=<api-key>'
|
||||
```
|
||||
次のようなメッセージを探してください:
|
||||
```text
|
||||
Protos API has not been used in project 244648151629 before or it is disabled
|
||||
```
|
||||
その project number は、他の endpoints、leaked metadata、または社内の company-mapping logic と照合して、customer / third-party projects から **in-scope first-party keys** を分離できます。
|
||||
|
||||
### key を破棄する前に restrictions を確認する
|
||||
|
||||
restricted key は必ずしも役に立たないわけではありません。key が見つかった context を保持し、対応する headers で requests を再実行します:
|
||||
```bash
|
||||
# Browser restricted
|
||||
curl -H 'X-Goog-Api-Key: <api-key>' \
|
||||
-H 'Referer: https://target.google.com' \
|
||||
'https://servicemanagement.googleapis.com/v1/operations'
|
||||
|
||||
# iOS restricted
|
||||
curl -H 'X-Goog-Api-Key: <api-key>' \
|
||||
-H 'X-Ios-Bundle-Identifier: com.google.GoogleMobile' \
|
||||
'https://servicemanagement.clients6.google.com/v1/operations'
|
||||
|
||||
# Android restricted
|
||||
curl -H 'X-Goog-Api-Key: <api-key>' \
|
||||
-H 'X-Android-Package: com.google.android.settings.intelligence' \
|
||||
-H 'X-Android-Cert: <sha1-signing-cert>' \
|
||||
'https://servicemanagement.clients6.google.com/v1/operations'
|
||||
```
|
||||
一般的な制限クラス:
|
||||
|
||||
- **HTTP Referer**
|
||||
- **iOS bundle ID** (`X-Ios-Bundle-Identifier`)
|
||||
- **Android package + signing cert** (`X-Android-Package` + `X-Android-Cert`)
|
||||
- **Server IP** 制限。これは通常、リモートからはバイパスできません
|
||||
|
||||
### first-party auth / origin whitelist のヒント
|
||||
|
||||
いくつかの Google web APIs は、**session cookie + first-party authorization headers** の組み合わせを受け付け、`*.clients6.google.com` 上でホストされています。これらの API をテストする際は:
|
||||
|
||||
- `Origin` と `Referer` を、通常その API を使う product と互換に保つ
|
||||
- `reason: SESSION_COOKIE_INVALID` を伴う `401` は、cookie が悪いのではなく、**origin が whitelisted されていない**ことを意味する場合があります
|
||||
- `*.corp.google.com` のような内部 origin だけを受け付ける public に到達可能な API は、broken access control レビューの高価値候補です
|
||||
|
||||
### brute force 可能な API と documented methods の fuzz
|
||||
|
||||
どの API が project で enabled されているか分からない場合、ツール [https://github.com/ozguralp/gmapsapiscanner](https://github.com/ozguralp/gmapsapiscanner) を実行して、**API key で何にアクセスできるか** を確認するとよいでしょう。
|
||||
|
||||
到達可能な service を特定したら、blind guessing よりも **schema-driven fuzzing** を優先します:
|
||||
|
||||
- discovery docs から直接 request を生成する
|
||||
- 同じ request を **既知の working keys すべて** で再生する
|
||||
- error を正規化して、**invalid input** と **visibility-label / auth / restriction** の failure を区別する
|
||||
- 数値の object identifier には、`ID-1`, `ID+1`, `1`, `2`, `100`, `1000` のような近い値を試す
|
||||
- **cross-user data access** や、他の実際の authorization failure を確認できた場合のみ report する。単なる enumeration だけでは通常十分ではありません
|
||||
|
||||
### common vuln pattern: unauthenticated direct-object reference
|
||||
|
||||
繰り返し見られる bug pattern は、**internal/admin API** が victim-controlled な identifier(たとえば `gaiaId`)を受け取り、request に有効な API key が含まれていることだけを検証し、**caller がその特定の object にアクセスする権限を持つかどうかを決してチェックしない**というものです。
|
||||
```bash
|
||||
curl 'https://gfibervoice-pa.googleapis.com/v1/BssGetVoiceSettings?gaiaId=<victim_gaia_id>' \
|
||||
-H 'X-Goog-Api-Key: <api-key>'
|
||||
```
|
||||
もしその endpoint が別ユーザーの電話番号、メールアドレス、settings、または他の private fields を返す場合、それは典型的な **IDOR / broken access control** の問題として扱ってください。
|
||||
|
||||
## References
|
||||
|
||||
- [Hacking Google with AI: AI-Assisted Discovery-Document Fuzzing of Google APIs](https://brutecat.com/articles/hacking-google-with-ai)
|
||||
- [Google APIs Explorer](https://developers.google.com/apis-explorer)
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
Reference in New Issue
Block a user