17 Network Geo Top Threat Source Ips
Query
// REVIEW ONLY - AWS Security Operations Workbook Visual Query
// Tab: Network | Panel: geo-top-threat-source-ips | Visualization: table | Mode: All
// Security Question: Which external IPs have the highest combined AWS mutation/recon score or unmapped multi-cloud presence?
// Drill-Through: Click a row to set SelectedIp and inspect Panel 5.4 raw VPC flows or Tab 10 Entra/XDR Pivot.
// Empty/No-Data Contract: No external public IPv4 addresses observed in AWSCloudTrail during the selected window.
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}");
let IdentityMap = union isfuzzy=true (datatable(SearchKey:string)[]), (_GetWatchlist('AWS_EntraIdentityMap'))
| where isnotempty(tostring(column_ifexists("SearchKey", ""))) and tolower(tostring(column_ifexists("Verified", ""))) == "true"
| project AWSAccountId=tostring(column_ifexists("AWSAccountId", "")), AwsAccessKeyId=tostring(column_ifexists("AwsAccessKeyId", "")), AwsPrincipalArn=tostring(column_ifexists("AwsPrincipalArn", "")), EntraObjectId=tostring(column_ifexists("EntraObjectId", ""));
let AwsByIp = union isfuzzy=true
(datatable(TimeGenerated:datetime, RecipientAccountId:string, UserIdentityAccountId:string, UserIdentityAccessKeyId:string, UserIdentityArn:string, UserIdentityType:string, SourceIpAddress:string, EventSource:string, EventName:string, ReadOnly:bool, ErrorCode:string)[]),
(AWSCloudTrail | where TimeGenerated between (Start .. End)
| project TimeGenerated, RecipientAccountId, UserIdentityAccountId, UserIdentityAccessKeyId, UserIdentityArn, UserIdentityType, SourceIpAddress, EventSource, EventName, ReadOnly, ErrorCode)
| where (AccountFilter == "*" or RecipientAccountId == AccountFilter or UserIdentityAccountId == AccountFilter)
| where isnotempty(SourceIpAddress) and isnotnull(parse_ipv4(SourceIpAddress)) and not(ipv4_is_private(SourceIpAddress))
| extend AWSAccountId = UserIdentityAccountId, AwsAccessKeyId = UserIdentityAccessKeyId, AwsPrincipalArn = UserIdentityArn
| join kind=leftouter IdentityMap on AWSAccountId, AwsAccessKeyId, AwsPrincipalArn
| summarize AwsEvents = count(),
DeniedCalls = countif(isnotempty(ErrorCode)),
MutatingCalls = countif(ReadOnly == false),
SecretOrIamCalls = countif(EventName == "GetSecretValue" or (EventSource == "iam.amazonaws.com" and ReadOnly == false) or UserIdentityType =~ "Root"),
MappedEvents = countif(isnotempty(EntraObjectId)),
TargetAwsAccounts = dcount(RecipientAccountId),
SamplePrincipals = make_set(UserIdentityArn, 5),
SampleApis = make_set(EventName, 8)
by SourceIp = SourceIpAddress;
let EntraByIp = union isfuzzy=true
(datatable(IPAddress:string, Principal:string)[]),
(SigninLogs | where TimeGenerated between (Start .. End) | project IPAddress, Principal=UserPrincipalName),
(AADNonInteractiveUserSignInLogs | where TimeGenerated between (Start .. End) | project IPAddress, Principal=UserPrincipalName),
(AADServicePrincipalSignInLogs | where TimeGenerated between (Start .. End) | project IPAddress, Principal=ServicePrincipalName)
| where isnotempty(IPAddress) and isnotnull(parse_ipv4(IPAddress)) and not(ipv4_is_private(IPAddress))
| summarize EntraSignIns = count(), EntraPrincipals = make_set(Principal, 5) by SourceIp = IPAddress;
AwsByIp
| join kind=leftouter EntraByIp on SourceIp
| extend Geo = geo_info_from_ip_address(SourceIp)
| extend Country = coalesce(iff(isnotempty(tostring(Geo.country)), tostring(Geo.country), ""), "Unknown"),
City = coalesce(iff(isnotempty(tostring(Geo.city)), tostring(Geo.city), ""), "Unknown"),
EntraSignIns = coalesce(EntraSignIns, long(0)),
ThreatScore = (SecretOrIamCalls * 15) + (DeniedCalls * 3) + (MutatingCalls * 2) + iff(MappedEvents == 0, 20, 0) + iff(coalesce(EntraSignIns, long(0)) > 0 and MappedEvents == 0, 25, 0)
| extend LocationStatus = case(
MappedEvents == 0 and DeniedCalls >= 5, "🔴 Untrusted / Unmapped Recon IP",
MappedEvents == 0, "🟠Unmapped External Location",
"🟢 Verified Identity Bridge"),
ThreatLevel = case(
ThreatScore >= 60 or (SecretOrIamCalls > 0 and MappedEvents == 0), "🔴 CRITICAL - Compromise / Secret Risk",
ThreatScore >= 30 or DeniedCalls >= 10, "🟠HIGH - Active Recon / Mutation",
MappedEvents == 0, "🟡 Medium - Unmapped External IP",
"🟢 Low - Verified Routine IP")
| project ThreatLevel, LocationStatus, SourceIp, Country, City, ThreatScore, AwsEvents, DeniedCalls, MutatingCalls, SecretOrIamCalls, EntraSignIns, TargetAwsAccounts, SamplePrincipals, EntraPrincipals, SampleApis
| order by ThreatScore desc, AwsEvents desc
| take 5000Explanation
This query is designed to identify external IP addresses that pose potential security threats to AWS environments by analyzing their activity and presence across multiple cloud platforms. Here's a simplified breakdown:
-
Time and Filters: The query uses a specific time range and various filters (organization, account, region, environment, etc.) to narrow down the data it processes.
-
Identity Mapping: It creates a map of AWS identities to Entra identities to help correlate activities across platforms.
-
AWS Activity by IP: It gathers AWS CloudTrail logs to track activities by external IP addresses, focusing on events like denied calls, mutating calls, and secret or IAM-related calls.
-
Entra Activity by IP: It collects sign-in logs from Entra (Azure Active Directory) to see if the same IPs are active there, indicating multi-cloud presence.
-
Threat Scoring: Each IP is given a threat score based on its activity, such as the number of secret or IAM calls, denied calls, and whether it has unmapped multi-cloud presence.
-
Geolocation and Threat Level: The query enriches IP data with geolocation information and assigns a threat level (Critical, High, Medium, Low) based on the threat score and activity patterns.
-
Output: The results are presented in a table, sorted by threat score, showing the top 5000 IPs with details like threat level, location, and sample activities.
-
Drill-Through: Users can click on a row to further investigate specific IPs in other panels or tabs.
-
Empty Data Handling: If no external IPs are observed in the specified time window, it indicates no data.
Overall, this query helps security teams identify and prioritize potential threats from external IPs based on their behavior and presence in AWS and other cloud environments.