Detection rules › Kusto

GCP IAM - High privileged role added to service account

Status
available
Severity
high
Time window
15m
Source
github.com/Azure/Azure-Sentinel

'Detects when high privileged role was added to service account.'

MITRE ATT&CK coverage

TacticTechniques
Privilege Escalation

Rules detecting the same action

These rules filter on the same operation.

Rule body

id: 86112c4b-2535-4178-aa0e-ed9e32e3f054
name: GCP IAM - High privileged role added to service account
description: |
  'Detects when high privileged role was added to service account.'
severity: High
status: Available
requiredDataConnectors:
  - connectorId: GCPIAMDataConnector
    dataTypes:
      - GCP_IAM
queryFrequency: 15m
queryPeriod: 15m
triggerOperator: gt
triggerThreshold: 0
tactics:
  - PrivilegeEscalation
relevantTechniques:
  - T1078
query: |
  let privileged_roles = dynamic(['roles/iam.securityAdmin', 'roles/secretmanager.admin', 'roles/secretmanager.secretAccessor', 'roles/apigateway.admin', 'roles/logging.admin', 'roles/iam.organizationRoleAdmin', 'roles/iam.roleAdmin', 'roles/iam.serviceAccountAdmin', 'roles/iam.serviceAccountCreator', 'roles/iam.serviceAccountKeyAdmin']);
  GCP_IAM
  | where PayloadMethodname =~ 'SetIamPolicy'
  | extend action = parse_json(todynamic(PayloadServicedataPolicydeltaBindingdeltas))[0]['action']
  | where action =~ 'ADD'
  | extend role = parse_json(todynamic(PayloadServicedataPolicydeltaBindingdeltas))[0]['role']
  | where role in~ (privileged_roles)
  | project-away action
  | extend AccountName = tostring(split(PayloadAuthenticationinfoPrincipalemail, "@")[0]), AccountUPNSuffix = tostring(split(PayloadAuthenticationinfoPrincipalemail, "@")[1])
entityMappings:
  - entityType: Account
    fieldMappings:
      - identifier: FullName
        columnName: PayloadAuthenticationinfoPrincipalemail
      - identifier: Name
        columnName: AccountName
      - identifier: UPNSuffix
        columnName: AccountUPNSuffix
  - entityType: IP
    fieldMappings:
      - identifier: Address
        columnName: SrcIpAddr
version: 1.0.1
kind: Scheduled

Stages and Predicates

Let binding: privileged_roles used in Stage 6

let privileged_roles = dynamic(['roles/iam.securityAdmin', 'roles/secretmanager.admin', 'roles/secretmanager.secretAccessor', 'roles/apigateway.admin', 'roles/logging.admin', 'roles/iam.organizationRoleAdmin', 'roles/iam.roleAdmin', 'roles/iam.serviceAccountAdmin', 'roles/iam.serviceAccountCreator', 'roles/iam.serviceAccountKeyAdmin']);

Stage 1: source

GCP_IAM

Stage 2: where

| where PayloadMethodname =~ 'SetIamPolicy'

Stage 3: extend

| extend action = parse_json(todynamic(PayloadServicedataPolicydeltaBindingdeltas))[0]['action']

Stage 4: where

| where action =~ 'ADD'

Stage 5: extend

| extend role = parse_json(todynamic(PayloadServicedataPolicydeltaBindingdeltas))[0]['role']

Stage 6: where

| where role in~ (privileged_roles)

Stage 7: project-away

| project-away action

Stage 8: extend

| extend AccountName = tostring(split(PayloadAuthenticationinfoPrincipalemail, "@")[0]), AccountUPNSuffix = tostring(split(PayloadAuthenticationinfoPrincipalemail, "@")[1])

Indicators

These rows show field, operator, and value matches.

FieldKindValuesSearch
PayloadMethodnameeq
  • SetIamPolicy
field:"gcp::method_name" kind:eq value:"SetIamPolicy"
actioneq
  • ADD
field:"action" kind:eq value:"ADD"
rolein
  • roles/apigateway.admin
  • roles/iam.organizationRoleAdmin
  • roles/iam.roleAdmin
  • roles/iam.securityAdmin
  • roles/iam.serviceAccountAdmin
  • roles/iam.serviceAccountCreator
  • roles/iam.serviceAccountKeyAdmin
  • roles/logging.admin
  • roles/secretmanager.admin
  • roles/secretmanager.secretAccessor
field:"role" kind:in

Output fields

These fields are emitted when the rule matches.

FieldSource
roleextend
AccountNameextend
AccountUPNSuffixextend