Google Workspace Object Copied from External Drive and Access Granted to Custom Application

Detects when a user copies a Google spreadsheet, form, document or script from an external drive. Sequence logic has been added to also detect when a user grants a custom Google application permission via OAuth shortly after. An adversary may send a phishing email to the victim with a Drive object link where "copy" is included in the URI, thus copying the object to the victim's drive. If a container-bound script exists within the object, execution will require permission access via OAuth in which the user has to accept.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2023/03/07"
  3integration = ["google_workspace"]
  4maturity = "production"
  5min_stack_comments = "Breaking changes for Google Workspace integration."
  6min_stack_version = "8.4.0"
  7updated_date = "2023/06/22"
  8
  9[rule]
 10author = ["Elastic"]
 11description = """
 12Detects when a user copies a Google spreadsheet, form, document or script from an external drive. Sequence logic has
 13been added to also detect when a user grants a custom Google application permission via OAuth shortly after. An
 14adversary may send a phishing email to the victim with a Drive object link where "copy" is included in the URI, thus
 15copying the object to the victim's drive. If a container-bound script exists within the object, execution will require
 16permission access via OAuth in which the user has to accept.
 17"""
 18false_positives = [
 19    """
 20    Google Workspace users typically share Drive resources with a shareable link where parameters are edited to indicate
 21    when it is viewable or editable by the intended recipient. It is uncommon for a user in an organization to manually
 22    copy a Drive object from an external drive to their corporate drive. This may happen where users find a useful
 23    spreadsheet in a public drive, for example, and replicate it to their Drive. It is uncommon for the copied object to
 24    execute a container-bound script either unless the user was intentionally aware, suggesting the object uses
 25    container-bound scripts to accomplish a legitimate task.
 26    """,
 27]
 28from = "now-130m"
 29index = ["filebeat-*", "logs-google_workspace*"]
 30interval = "10m"
 31language = "eql"
 32license = "Elastic License v2"
 33name = "Google Workspace Object Copied from External Drive and Access Granted to Custom Application"
 34note = """## Triage and analysis
 35
 36### Investigating Google Workspace Resource Copied from External Drive and Access Granted to Custom Application
 37
 38Google Workspace users can share access to Drive objects such as documents, sheets, and forms via email delivery or a shared link. Shared link URIs have parameters like `view` or `edit` to indicate the recipient's permissions. The `copy` parameter allows the recipient to copy the object to their own Drive, which grants the object with the same privileges as the recipient. Specific objects in Google Drive allow container-bound scripts that run on Google's Apps Script platform. Container-bound scripts can contain malicious code that executes with the recipient's privileges if in their Drive.
 39
 40This rule aims to detect when a user copies an external Drive object to their Drive storage and then grants permissions to a custom application via OAuth prompt.
 41
 42#### Possible investigation steps
 43- Identify user account(s) associated by reviewing `user.name` or `source.user.email` in the alert.
 44- Identify the name of the file copied by reviewing `file.name` as well as the `file.id` for triaging.
 45- Identify the file type by reviewing `google_workspace.drive.file.type`.
 46- With the information gathered so far, query across data for the file metadata to determine if this activity is isolated or widespread.
 47- Within the OAuth token event, identify the application name by reviewing `google_workspace.token.app_name`.
 48    - Review the application ID as well from `google_workspace.token.client.id`.
 49    - This metadata can be used to report the malicious application to Google for permanent blacklisting.
 50- Identify the permissions granted to the application by the user by reviewing `google_workspace.token.scope.data.scope_name`.
 51    - This information will help pivot and triage into what services may have been affected.
 52- If a container-bound script was attached to the copied object, it will also exist in the user's drive.
 53    - This object should be removed from all users affected and investigated for a better understanding of the malicious code.
 54
 55### False positive analysis
 56- Communicate with the affected user to identify if these actions were intentional
 57- If a container-bound script exists, review code to identify if it is benign or malicious
 58
 59### Response and remediation
 60- Initiate the incident response process based on the outcome of the triage.
 61- Disable or limit the account during the investigation and response.
 62- Identify the possible impact of the incident and prioritize accordingly; the following actions can help you gain context:
 63    - Identify the account role in the cloud environment.
 64    - Assess the criticality of affected services and servers.
 65    - Work with your IT team to identify and minimize the impact on users.
 66    - Identify if the attacker is moving laterally and compromising other accounts, servers, or services.
 67    - Identify any regulatory or legal ramifications related to this activity.
 68- Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords or delete API keys as needed to revoke the attacker's access to the environment. Work with your IT teams to minimize the impact on business operations during these actions.
 69    - Resetting passwords will revoke OAuth tokens which could have been stolen.
 70- Reactivate multi-factor authentication for the user.
 71- Review the permissions assigned to the implicated user to ensure that the least privilege principle is being followed.
 72- Implement security defaults [provided by Google](https://cloud.google.com/security-command-center/docs/how-to-investigate-threats).
 73- Determine the initial vector abused by the attacker and take action to prevent reinfection via the same vector.
 74- Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
 75
 76## Setup
 77The Google Workspace Fleet integration, Filebeat module, or similarly structured data is required to be compatible with this rule.
 78### Important Information Regarding Google Workspace Event Lag Times
 79- As per Google's documentation, Google Workspace administrators may observe lag times ranging from minutes up to 3 days between the time of an event's occurrence and the event being visible in the Google Workspace admin/audit logs.
 80- This rule is configured to run every 10 minutes with a lookback time of 130 minutes.
 81- To reduce the risk of false negatives, consider reducing the interval that the Google Workspace (formerly G Suite) Filebeat module polls Google's reporting API for new events.
 82- By default, `var.interval` is set to 2 hours (2h). Consider changing this interval to a lower value, such as 10 minutes (10m).
 83- See the following references for further information:
 84  - https://support.google.com/a/answer/7061566
 85  - https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-module-google_workspace.html"""
 86references = [
 87    "https://www.elastic.co/security-labs/google-workspace-attack-surface-part-one",
 88    "https://developers.google.com/apps-script/guides/bound",
 89    "https://support.google.com/a/users/answer/13004165#share_make_a_copy_links",
 90]
 91risk_score = 47
 92rule_id = "f33e68a4-bd19-11ed-b02f-f661ea17fbcc"
 93severity = "medium"
 94tags = ["Domain: Cloud", "Data Source: Google Workspace", "Tactic: Initial Access", "Resources: Investigation Guide"]
 95type = "eql"
 96
 97query = '''
 98sequence by source.user.email with maxspan=3m
 99[file where event.dataset == "google_workspace.drive" and event.action == "copy" and
100
101    /* Should only match if the object lives in a Drive that is external to the user's GWS organization */
102    google_workspace.drive.owner_is_team_drive == "false" and google_workspace.drive.copy_type == "external" and
103
104    /* Google Script, Forms, Sheets and Document can have container-bound scripts */
105    google_workspace.drive.file.type: ("script", "form", "spreadsheet", "document")]
106
107[any where event.dataset == "google_workspace.token" and event.action == "authorize" and
108
109    /* Ensures application ID references custom app in Google Workspace and not GCP */
110    google_workspace.token.client.id : "*apps.googleusercontent.com"]
111'''
112
113
114[[rule.threat]]
115framework = "MITRE ATT&CK"
116[[rule.threat.technique]]
117id = "T1566"
118name = "Phishing"
119reference = "https://attack.mitre.org/techniques/T1566/"
120[[rule.threat.technique.subtechnique]]
121id = "T1566.002"
122name = "Spearphishing Link"
123reference = "https://attack.mitre.org/techniques/T1566/002/"
124
125
126
127[rule.threat.tactic]
128id = "TA0001"
129name = "Initial Access"
130reference = "https://attack.mitre.org/tactics/TA0001/"

Triage and analysis

Investigating Google Workspace Resource Copied from External Drive and Access Granted to Custom Application

Google Workspace users can share access to Drive objects such as documents, sheets, and forms via email delivery or a shared link. Shared link URIs have parameters like view or edit to indicate the recipient's permissions. The copy parameter allows the recipient to copy the object to their own Drive, which grants the object with the same privileges as the recipient. Specific objects in Google Drive allow container-bound scripts that run on Google's Apps Script platform. Container-bound scripts can contain malicious code that executes with the recipient's privileges if in their Drive.

This rule aims to detect when a user copies an external Drive object to their Drive storage and then grants permissions to a custom application via OAuth prompt.

Possible investigation steps

  • Identify user account(s) associated by reviewing user.name or source.user.email in the alert.
  • Identify the name of the file copied by reviewing file.name as well as the file.id for triaging.
  • Identify the file type by reviewing google_workspace.drive.file.type.
  • With the information gathered so far, query across data for the file metadata to determine if this activity is isolated or widespread.
  • Within the OAuth token event, identify the application name by reviewing google_workspace.token.app_name.
    • Review the application ID as well from google_workspace.token.client.id.
    • This metadata can be used to report the malicious application to Google for permanent blacklisting.
  • Identify the permissions granted to the application by the user by reviewing google_workspace.token.scope.data.scope_name.
    • This information will help pivot and triage into what services may have been affected.
  • If a container-bound script was attached to the copied object, it will also exist in the user's drive.
    • This object should be removed from all users affected and investigated for a better understanding of the malicious code.

False positive analysis

  • Communicate with the affected user to identify if these actions were intentional
  • If a container-bound script exists, review code to identify if it is benign or malicious

Response and remediation

  • Initiate the incident response process based on the outcome of the triage.
  • Disable or limit the account during the investigation and response.
  • Identify the possible impact of the incident and prioritize accordingly; the following actions can help you gain context:
    • Identify the account role in the cloud environment.
    • Assess the criticality of affected services and servers.
    • Work with your IT team to identify and minimize the impact on users.
    • Identify if the attacker is moving laterally and compromising other accounts, servers, or services.
    • Identify any regulatory or legal ramifications related to this activity.
  • Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords or delete API keys as needed to revoke the attacker's access to the environment. Work with your IT teams to minimize the impact on business operations during these actions.
    • Resetting passwords will revoke OAuth tokens which could have been stolen.
  • Reactivate multi-factor authentication for the user.
  • Review the permissions assigned to the implicated user to ensure that the least privilege principle is being followed.
  • Implement security defaults provided by Google.
  • Determine the initial vector abused by the attacker and take action to prevent reinfection via the same vector.
  • Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).

Setup

The Google Workspace Fleet integration, Filebeat module, or similarly structured data is required to be compatible with this rule.

Important Information Regarding Google Workspace Event Lag Times

  • As per Google's documentation, Google Workspace administrators may observe lag times ranging from minutes up to 3 days between the time of an event's occurrence and the event being visible in the Google Workspace admin/audit logs.
  • This rule is configured to run every 10 minutes with a lookback time of 130 minutes.
  • To reduce the risk of false negatives, consider reducing the interval that the Google Workspace (formerly G Suite) Filebeat module polls Google's reporting API for new events.
  • By default, var.interval is set to 2 hours (2h). Consider changing this interval to a lower value, such as 10 minutes (10m).
  • See the following references for further information:

References

Related rules

to-top