17 H04 Ip Candidates
Query
// REVIEW ONLY workbook query: 5.3 H04 — Unmapped Public IP Overlap Between AWS CloudTrail & Entra Sign-Ins (Low-Confidence Pivot)
let Start = {TimeRange:start};
let End = {TimeRange:end};
let AccountFilter = trim(" ", base64_decode_tostring("{AwsAccount:base64}"));
let UseAllAccounts = AccountFilter in ("", "*");
let SeedKey = trim(" ", base64_decode_tostring("{AccessKeyId:base64}"));
let SafeCloudTrail = union isfuzzy=true
(datatable(TimeGenerated:datetime, AwsEventId:string, EventSource:string, EventName:string, AWSRegion:string,
RecipientAccountId:string, UserIdentityAccountId:string, UserIdentityType:string, UserIdentityArn:string,
UserIdentityAccessKeyId:string, SourceIpAddress:string, UserAgent:string,
ErrorCode:string, ErrorMessage:string, RequestParameters:string, ResponseElements:string, Resources:string,
ManagementEvent:bool, ReadOnly:bool, SessionMfaAuthenticated:string)[]),
(AWSCloudTrail
| where TimeGenerated between (Start .. End)
| project TimeGenerated, AwsEventId, EventSource, EventName, AWSRegion, RecipientAccountId,
UserIdentityAccountId, UserIdentityType, UserIdentityArn,
UserIdentityAccessKeyId, SourceIpAddress, UserAgent, ErrorCode, ErrorMessage,
RequestParameters, ResponseElements, Resources, ManagementEvent, ReadOnly, SessionMfaAuthenticated);
let IdentityMap = union isfuzzy=true
(datatable(SearchKey:string)[]),
(_GetWatchlist('AWS_EntraIdentityMap'))
| where isnotempty(tostring(column_ifexists("SearchKey", "")))
| extend VerifiedVal = tolower(tostring(column_ifexists("Verified", ""))),
MappingEvidenceVal = tostring(column_ifexists("MappingEvidence", ""))
| where VerifiedVal == "true" and isnotempty(MappingEvidenceVal)
| project AwsAccessKeyId=tostring(column_ifexists("AwsAccessKeyId", "")),
AwsPrincipalArn=tostring(column_ifexists("AwsPrincipalArn", "")),
AWSAccountId=tostring(column_ifexists("AWSAccountId", "")),
EntraTenantId=tolower(tostring(column_ifexists("EntraTenantId", ""))),
EntraObjectId=tolower(tostring(column_ifexists("EntraObjectId", ""))),
IdentityType=tostring(column_ifexists("IdentityType", "")),
AppClientId=tolower(tostring(column_ifexists("AppClientId", ""))),
ValidFrom=todatetime(column_ifexists("ValidFromUtc", "")),
ValidTo=todatetime(column_ifexists("ValidToUtc", ""))
| summarize MappingRows=count(), take_any(*) by AwsAccessKeyId, AwsPrincipalArn, AWSAccountId
| where MappingRows == 1 and isnotempty(EntraTenantId) and isnotempty(EntraObjectId);
let UnmappedAwsIps = SafeCloudTrail
| where UseAllAccounts or UserIdentityAccountId == AccountFilter or RecipientAccountId == AccountFilter
| where isempty(SeedKey) or UserIdentityAccessKeyId == SeedKey
| where isnotempty(SourceIpAddress) and not(SourceIpAddress matches regex @"^[a-z0-9.-]+\.amazonaws\.com$")
and not(ipv4_is_private(SourceIpAddress))
| extend AWSAccountId=UserIdentityAccountId, AwsAccessKeyId=UserIdentityAccessKeyId, AwsPrincipalArn=UserIdentityArn
| join kind=leftanti IdentityMap on AWSAccountId, AwsAccessKeyId, AwsPrincipalArn
| summarize AwsEvents=count(), FirstAws=min(TimeGenerated), LastAws=max(TimeGenerated),
AwsActions=make_set(EventName, 15), AwsPrincipals=make_set(AwsPrincipalArn, 10), AwsAccounts=make_set(RecipientAccountId, 10)
by SourceIp=SourceIpAddress;
let EntraIps = union isfuzzy=true
(datatable(EntraTime:datetime, SourceTable:string, Principal:string, IPAddress:string, AppName:string, ResultType:string)[]),
(SigninLogs | where TimeGenerated between (Start .. End) | project EntraTime=TimeGenerated, SourceTable="SigninLogs", Principal=UserPrincipalName, IPAddress, AppName=AppDisplayName, ResultType),
(AADNonInteractiveUserSignInLogs | where TimeGenerated between (Start .. End) | project EntraTime=TimeGenerated, SourceTable="AADNonInteractive", Principal=UserPrincipalName, IPAddress, AppName=AppDisplayName, ResultType),
(AADServicePrincipalSignInLogs | where TimeGenerated between (Start .. End) | project EntraTime=TimeGenerated, SourceTable="AADServicePrincipal", Principal=ServicePrincipalName, IPAddress, AppName=ServicePrincipalName, ResultType)
| where isnotempty(IPAddress) and not(ipv4_is_private(IPAddress))
| summarize EntraSignIns=count(), FirstEntra=min(EntraTime), LastEntra=max(EntraTime),
EntraPrincipals=make_set(Principal, 10), EntraApps=make_set(AppName, 10), SourceTables=make_set(SourceTable, 4)
by SourceIp=IPAddress;
UnmappedAwsIps
| join kind=inner EntraIps on SourceIp
| extend ConfidenceNote="🟡 LOW CONFIDENCE (IP-ONLY): Shared NAT/VPN/proxy can produce coincidental overlap; verify token/device provenance"
| project SourceIp, ConfidenceNote, AwsEvents, FirstAws, LastAws, AwsAccounts, AwsPrincipals, AwsActions,
EntraSignIns, FirstEntra, LastEntra, EntraPrincipals, EntraApps, SourceTables
| order by AwsEvents desc
| take 5000Explanation
This query is designed to identify overlaps between public IP addresses used in AWS CloudTrail events and Microsoft Entra (formerly Azure Active Directory) sign-ins. Here's a simplified breakdown of what the query does:
-
Time Range and Filters: It sets a time range for the analysis and decodes filters for AWS account and access key ID.
-
AWS CloudTrail Data: It retrieves AWS CloudTrail logs within the specified time range, focusing on events that are not associated with AWS internal IP addresses and are not private IPs.
-
Identity Mapping: It checks for any existing mappings between AWS access keys and Entra identities to filter out known associations.
-
Unmapped AWS IPs: It identifies AWS events with public IPs that do not have a known mapping to Entra identities.
-
Entra Sign-In Data: It collects sign-in logs from Entra, including interactive and non-interactive user sign-ins, as well as service principal sign-ins, within the same time range.
-
IP Overlap: It finds overlaps between the unmapped AWS IPs and the Entra sign-in IPs, indicating potential shared use of IPs (e.g., through NAT, VPN, or proxy).
-
Confidence Note: It adds a note indicating low confidence in the overlap due to the possibility of shared infrastructure causing coincidental matches.
-
Output: The query outputs a list of overlapping IPs, along with details about the AWS events and Entra sign-ins associated with each IP, sorted by the number of AWS events.
This analysis helps identify potential security concerns where the same public IP is used in both AWS and Entra activities, but it advises caution due to the low confidence of IP-only matches.