Detection rules › Kusto

Certified Pre-Owned - backup of CA private key - rule 1

Status
available
Severity
medium
Time window
1h
Source
github.com/Azure/Azure-Sentinel

This query identifies someone that performs a read operation of they CA key from the file.

MITRE ATT&CK coverage

TacticTechniques
StealthT1036 Masquerading

Event coverage

ProviderEventTitle
Security-AuditingEvent ID 5058Key file operation.

Rule body kusto

id: aa5eaac7-1264-4833-b620-8f062be75541
name: Certified Pre-Owned - backup of CA private key - rule 1
description: |
  This query identifies someone that performs a read operation of they CA key from the file.
severity: Medium
status: Available
requiredDataConnectors:
  - connectorId: SecurityEvents
    dataTypes:
      - SecurityEvent
  - connectorId: WindowsSecurityEvents
    dataTypes:
      - SecurityEvent
queryFrequency: 1h
queryPeriod: 1h
triggerOperator: gt
triggerThreshold: 0
tactics:
  - DefenseEvasion
relevantTechniques:
  - T1036
query: |
  SecurityEvent
  // Fill in the machine name of your CA.
  | where EventID == 5058 and Computer contains "<YOUR CA MACHINE NAME>"
  | where EventData contains "%%2499" // Machine key.
  | extend EventData=parse_xml(EventData)
  | mv-apply d=EventData.EventData.Data on
  (
      where d["@Name"]=="KeyName"
      | project KeyName=tostring(d["#text"])
  )
  | mv-apply d=EventData.EventData.Data on
  (
      where d["@Name"]=="SubjectUserName"
      | project SubjectUserName=tostring(d["#text"])
  )
  | mv-apply d=EventData.EventData.Data on
  (
      where d["@Name"]=="Operation"
      | project Operation=tostring(d["#text"])
  )
  | extend Operation=iff(Operation == "%%2458", "Read persisted key from file", Operation)
  // This one is a guess and very poorly documented :(
  | extend Operation=iff(Operation == "%%2459", "Write persisted key to file", Operation)
  // Fill in the keyname of the CA key.
  | where KeyName == "<INSERT ISSUING CA KEY HERE>" // Or any other key you want to monitor.
entityMappings:
  - entityType: Host
    fieldMappings:
      - identifier: FullName
        columnName: Computer
version: 1.0.1
kind: Scheduled

Stages and Predicates

Stage 1: source

SecurityEvent

Stage 2: where

| where EventID == 5058 and Computer contains "<YOUR CA MACHINE NAME>"

Stage 3: where

| where EventData contains "%%2499"

Stage 4: extend

| extend EventData=parse_xml(EventData)

Stage 5: kusto:mv-apply

| mv-apply d=EventData.EventData.Data on
(
    where d["@Name"]=="KeyName"
    | project KeyName=tostring(d["#text"])
)

Stage 6: kusto:mv-apply

| mv-apply d=EventData.EventData.Data on
(
    where d["@Name"]=="SubjectUserName"
    | project SubjectUserName=tostring(d["#text"])
)

Stage 7: kusto:mv-apply

| mv-apply d=EventData.EventData.Data on
(
    where d["@Name"]=="Operation"
    | project Operation=tostring(d["#text"])
)

Stage 8: extend

| extend Operation=iff(Operation == "%%2458", "Read persisted key from file", Operation)
Operation =
ifOperation == "%%2458""Read persisted key from file"
elseOperation

Stage 9: extend

| extend Operation=iff(Operation == "%%2459", "Write persisted key to file", Operation)
Operation =
ifOperation == "%%2459""Write persisted key to file"
elseOperation

Stage 10: where

| where KeyName == "<INSERT ISSUING CA KEY HERE>"

Indicators

Each row is a field, operator, and value that the rule matches. The corpus column counts how many other rules in the catalog look for the same combination: high numbers point to widely-used, community-vetted indicators. Blank or 1 shows that the indicator is specific to this rule.

FieldKindValues
@Nameeq
  • KeyName transforms: cased corpus 2 (kusto 2)
  • Operation transforms: cased
  • SubjectUserName transforms: cased corpus 2 (kusto 2)
Computercontains
  • <YOUR CA MACHINE NAME> corpus 2 (kusto 2)
EventDatacontains
  • %%2499 corpus 2 (kusto 2)
EventIDeq
  • 5058 transforms: cased
KeyNameeq
  • <INSERT ISSUING CA KEY HERE> transforms: cased

Output fields

Fields the rule emits when it matches. Chronicle authors list these in the outcome block; they appear on the detection and $risk_score drives alerting. Sentinel / Defender XDR rules build them up through project / summarize / extend stages. Sentinel maps these into alert fields via entityMappings and customDetails; Defender XDR custom detections surface them as alert fields directly.

FieldSource
EventDataextend
Operationextend