GCP - Cloud Functions Enum

Support HackTricks

Cloud Functions

Google Cloud Functions は、ホストオペレーティングシステムの管理を必要とせずに、イベントに応じて実行されるコードをホストするように設計されています。さらに、これらの関数は、コードが利用できる環境変数の保存をサポートしています。

Storage

Cloud Functions のコードは GCP Storage に保存されます。したがって、GCP のバケットに対する読み取りアクセス権を持つ人は誰でも、Cloud Functions のコードを読むことができます。 コードは次のようなバケットに保存されます:

  • gcf-sources-<number>-<region>/<function-name>-<uuid>/version-<n>/function-source.zip

  • gcf-v2-sources-<number>-<region>/<function-name>function-source.zip

例えば: gcf-sources-645468741258-us-central1/function-1-003dcbdf-32e1-430f-a5ff-785a6e238c76/version-4/function-source.zip

Cloud Function を保存しているバケットに対する読み取り権限を持つユーザーは、実行されるコードを読むことができます。

Artifact Registry

クラウド関数がプロジェクト内の Artifact Registry リポジトリ内に格納された Docker コンテナを実行するように設定されている場合、リポジトリに対する読み取りアクセス権を持つ人は誰でもイメージをダウンロードしてソースコードを確認できます。詳細については次を参照してください:

GCP - Artifact Registry Enum

SA

指定されていない場合、デフォルトでEditor 権限を持つApp Engine Default Service Accountが Cloud Function にアタッチされます。

Triggers, URL & Authentication

Cloud Function が作成されるときにトリガーを指定する必要があります。一般的なものの一つはHTTPSで、これにより関数をウェブブラウジングでトリガーできる URLが作成されます。 他のトリガーには pub/sub、Storage、Filestore などがあります。

URL の形式は https://<region>-<project-gcp-name>.cloudfunctions.net/<func_name> です。

HTTPS トリガーが使用される場合、呼び出し元が関数を呼び出すために IAM 認証が必要か、または誰でも呼び出せるかが示されます:

Inside the Cloud Function

コードは**/workspace** フォルダー内にダウンロードされ、Cloud Function 内のファイルと同じファイル名で保存され、www-data ユーザーで実行されます。 ディスクは読み取り専用としてマウントされていません。

Enumeration

# List functions
gcloud functions list
gcloud functions describe <func_name> # Check triggers to see how is this function invoked
gcloud functions get-iam-policy <func_name>

# Get logs of previous runs. By default, limits to 10 lines
gcloud functions logs read <func_name> --limit [NUMBER]

# Call a function
curl https://<region>-<project>.cloudfunctions.net/<func_name>
gcloud functions call <func_name> --data='{"message": "Hello World!"}'

# If you know the name of projects you could try to BF cloud functions names

# Get events that could be used to trigger a cloud function
gcloud functions event-types list

# Access function with authentication
curl -X POST https://<region>-<project>.cloudfunctions.net/<func_name> \
-H "Authorization: bearer $(gcloud auth print-identity-token)" \
-H "Content-Type: application/json" \
-d '{}'

Privilege Escalation

次のページでは、クラウドファンクションの権限を悪用して特権を昇格させる方法を確認できます:

GCP - Cloudfunctions Privesc

Unauthenticated Access

GCP - Cloud Functions Unauthenticated Enum

Post Exploitation

GCP - Cloud Functions Post Exploitation

Persistence

GCP - Cloud Functions Persistence

References

Support HackTricks

Last updated