# GCP - Storage Post Exploitation

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

## Cloud Storage

Vir meer inligting oor Cloud Storage, kyk na hierdie blad:

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

### Gee openbare toegang

Dit is moontlik om eksterne gebruikers (met of sonder aanmelding by GCP) toegang tot bucket-inhoud te gee. Tog is die opsie om 'n bucket publiek bloot te stel standaard gedeaktiveer:
```bash
# 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
```
As jy probeer om **ACLs aan 'n bucket met gedeaktiveerde ACLs** te gee, sal jy hierdie fout kry: `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`

Om toegang tot oop buckets via 'n blaaier te kry, besoek die URL `https://<bucket_name>.storage.googleapis.com/` of `https://<bucket_name>.storage.googleapis.com/<object_name>`

### `storage.objects.delete` (`storage.objects.get`)

Om 'n object te verwyder:
```bash
gcloud storage rm gs://<BUCKET_NAME>/<OBJECT_NAME> --project=<PROJECT_ID>
```
### `storage.buckets.delete`, `storage.objects.delete` & `storage.objects.list`

Om 'n bucket te verwyder:
```bash
gcloud storage rm -r gs://<BUCKET_NAME>
```
### Deaktiveer HMAC-sleutels

Die `storage.hmacKeys.update` toestemming laat toe om HMAC-sleutels te deaktiveer, en die `storage.hmacKeys.delete` toestemming laat 'n identiteit toe om HMAC-sleutels wat geassosieer is met diensrekeninge in Cloud Storage te verwyder.
```bash
# Deactivate
gcloud storage hmac update <ACCESS_ID> --deactivate

# Delete
gcloud storage hmac delete <ACCESS_ID>
```
### `storage.buckets.setIpFilter` & `storage.buckets.update`
Die `storage.buckets.setIpFilter`-toestemming, tesame met die `storage.buckets.update`-toestemming, stel 'n identiteit in staat om IP-adresfilters op 'n Cloud Storage bucket te konfigureer, en spesifiseer watter IP-reekse of adresse toegelaat word om toegang tot die bucket se hulpbronne te kry.

Om die IP-filter heeltemal te verwyder, kan die volgende opdrag gebruik word:
```bash
gcloud storage buckets update gs://<BUCKET_NAME> --project=<PROJECT_ID>
```
Om die gefilterde IPs te verander, kan die volgende kommando gebruik word:
```bash
gcloud storage buckets update gs://<BUCKET_NAME> \
--ip-filter-file=ip-filter.json \
--project=<PROJECT_ID>
```
Die JSON-lêer verteenwoordig die filter self, iets soos:
```bash
{
"mode": "Enabled",
"publicNetworkSource": {
"allowedIpCidrRanges": ["<IP>/<MASK>"]
},
"allowCrossOrgVpcs": false,
"allowAllServiceAgentAccess": false
}
```
### `storage.buckets.restore`
Herstel 'n bucket met behulp van:
```bash
gcloud storage restore gs://<BUCKET_NAME>#<GENERATION> \
--project=<PROJECT_ID>
```
{{#include ../../../banners/hacktricks-training.md}}
