09 Identity Control Plane Root And Unauthenticated Mfa Actions
Query
// REVIEW ONLY - AWS Security Operations Workbook Visual Query
// Tab: IdentityControlPlane | Panel: root-and-unauthenticated-mfa-actions | Visualization: table | Mode: All
// Security Question: Did Root execute any interactive/API commands, or did a principal mutate IAM/logging without MFA?
// Drill-Through: Click a row to populate SelectedPrincipal, then review Panel 3.3 or Tab 10 Entra/XDR Pivot.
// Empty/No-Data Contract: Zero Root runtime events or non-MFA IAM/logging mutations observed (verify AWSCloudTrail status in Tab 2).
let Start = {TimeRange:start};
let End = {TimeRange:end};
let OrgFilter = base64_decode_tostring("{Organization:base64}");
let AccountFilter = base64_decode_tostring("{AwsAccount:base64}");
let RegionFilter = base64_decode_tostring("{AwsRegion:base64}");
let EnvFilter = base64_decode_tostring("{Environment:base64}");
let WorkloadFilter = base64_decode_tostring("{Workload:base64}");
let SeverityFilter = base64_decode_tostring("{Severity:base64}");
let SourceFilter = base64_decode_tostring("{SourceTable:base64}");
let SummaryPref = base64_decode_tostring("{SummaryMode:base64}");
let SelectedPrincipalFilter = base64_decode_tostring("{SelectedPrincipal:base64}");
let SelectedIpFilter = base64_decode_tostring("{SelectedIp:base64}");
union isfuzzy=true
(datatable(TimeGenerated:datetime, RecipientAccountId:string, AWSRegion:string, UserIdentityInvokedBy:string, EventTypeName:string, SessionMfaAuthenticated:string, AdditionalEventData:string, UserIdentityArn:string, UserIdentityType:string, ReadOnly:bool, EventSource:string, EventName:string, SourceIpAddress:string, ErrorCode:string)[]),
(AWSCloudTrail | where TimeGenerated between (Start .. End)
| project TimeGenerated, RecipientAccountId, AWSRegion, UserIdentityInvokedBy, EventTypeName, SessionMfaAuthenticated=tostring(SessionMfaAuthenticated), AdditionalEventData, UserIdentityArn, UserIdentityType, ReadOnly, EventSource, EventName, SourceIpAddress, ErrorCode)
| where (AccountFilter == "*" or RecipientAccountId == AccountFilter) and (RegionFilter == "*" or AWSRegion == RegionFilter)
| where isempty(UserIdentityInvokedBy) and EventTypeName != "AwsServiceEvent"
| extend MfaOk = (tolower(SessionMfaAuthenticated) == "true" or tostring(parse_json(AdditionalEventData).MFAUsed) =~ "Yes"),
ActorArn = coalesce(iff(isnotempty(UserIdentityArn), UserIdentityArn, ""), "root")
| where UserIdentityType =~ "Root" or (MfaOk == false and ReadOnly == false and EventSource in ("iam.amazonaws.com", "sts.amazonaws.com", "cloudtrail.amazonaws.com", "kms.amazonaws.com", "organizations.amazonaws.com"))
| summarize FirstSeen=min(TimeGenerated), LastSeen=max(TimeGenerated), Events=count(),
Operations=make_set(EventName, 20), SourceIps=make_set(SourceIpAddress, 10), Errors=make_set(ErrorCode, 5)
by RecipientAccountId, AWSRegion, UserIdentityType, ActorArn, MfaOk
| order by UserIdentityType desc, Events desc
| take 5000Explanation
This query is designed to analyze AWS security operations, specifically focusing on actions performed by the root user or any actions that modify IAM or logging settings without using Multi-Factor Authentication (MFA). Here's a simplified breakdown of what the query does:
-
Time Range and Filters: It sets a time range and applies various filters based on organization, account, region, environment, workload, severity, source, selected principal, and IP address. These filters are decoded from base64 strings.
-
Data Collection: It gathers data from AWS CloudTrail logs within the specified time range.
-
Filtering Events:
- It looks for events where no service invoked the user identity and excludes AWS service events.
- It checks if the action was performed by the root user or if it involved IAM/logging changes without MFA and was not a read-only action.
-
MFA Check: It determines if MFA was used during the session by checking specific fields in the data.
-
Summarization:
- It summarizes the data by counting the number of events, listing the operations performed, source IP addresses, and any errors encountered.
- It groups the results by account ID, region, user identity type, actor ARN, and MFA status.
-
Ordering and Limiting Results: The results are ordered by user identity type and the number of events, and it displays up to 5000 records.
-
Output: The output is a table that helps identify if the root user executed any commands or if there were any IAM/logging changes without MFA. If no such events are found, it suggests verifying the AWS CloudTrail status.
This query is part of a security operations workbook and is used to monitor and review potentially risky actions in AWS environments.