# GCP - Logging Post Exploitation {% hint style="success" %} Learn & practice AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\ Learn & practice GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
Support HackTricks * Check the [**subscription plans**](https://github.com/sponsors/carlospolop)! * **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks_live)**.** * **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
{% endhint %} ## Basic Information For more information check: {% content-ref url="../gcp-services/gcp-logging-enum.md" %} [gcp-logging-enum.md](../gcp-services/gcp-logging-enum.md) {% endcontent-ref %} For other ways to disrupt monitoring check: {% content-ref url="gcp-monitoring-post-exploitation.md" %} [gcp-monitoring-post-exploitation.md](gcp-monitoring-post-exploitation.md) {% endcontent-ref %} ### Default Logging **By default you won't get caught just for performing read actions. Fore more info check the Logging Enum section.** ### Add Excepted Principal 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) is possible to add principals to not generate logs. An attacker could abuse this to prevent being caught. ### Read logs - `logging.logEntries.list` {% code overflow="wrap" %} ```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 ``` {% endcode %} ### `logging.logs.delete` {% code overflow="wrap" %} ```bash # Delete all entries from a log in the _Default log bucket - logging.logs.delete gcloud logging logs delete ``` {% endcode %} ### Write logs - `logging.logEntries.create` {% code overflow="wrap" %} ```bash # Write a log entry to try to disrupt some system gcloud logging write LOG_NAME "A deceptive log entry" --severity=ERROR ``` {% endcode %} ### `logging.buckets.update` {% code overflow="wrap" %} ```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 ``` {% endcode %} ### `logging.buckets.delete` ```bash # Delete log bucket gcloud logging buckets delete BUCKET_NAME --location= ``` ### `logging.links.delete` {% code overflow="wrap" %} ```bash # Delete link gcloud logging links delete --bucket --location ``` {% endcode %} ### `logging.views.delete` ```bash # Delete a logging view to remove access to anyone using it gcloud logging views delete --bucket= --location=global ``` ### `logging.views.update` {% code overflow="wrap" %} ```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" ``` {% endcode %} ### `logging.logMetrics.update` {% code overflow="wrap" %} ```bash # Update log based metrics - logging.logMetrics.update gcloud logging metrics update --description="Changed metric description" --log-filter="severity>CRITICAL" --project=PROJECT_ID ``` {% endcode %} ### `logging.logMetrics.delete` ```bash # Delete log based metrics - logging.logMetrics.delete gcloud logging metrics delete ``` ### `logging.sinks.delete` ```bash # Delete sink - logging.sinks.delete gcloud logging sinks delete ``` ### `logging.sinks.update` {% code overflow="wrap" %} ```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 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 ``` {% endcode %} {% hint style="success" %} Learn & practice AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\ Learn & practice GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
Support HackTricks * Check the [**subscription plans**](https://github.com/sponsors/carlospolop)! * **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks_live)**.** * **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
{% endhint %}