Query Details

H04 Ip Only Crosscloud Candidates

Query

// REVIEW ONLY. LOW-CONFIDENCE infrastructure pivot. Never call these the same actor.
// AWS SourceIpAddress is a client address; MDE RemoteIP is a destination, not endpoint public egress.
let Start = ago(1d);
let End = now();
let SeedAWSAccountId = "REPLACE_WITH_12_DIGIT_ACCOUNT";
let SeedAccessKeyId = "REPLACE_WITH_ACCESS_KEY_ID";
let InputsValid = assert(SeedAWSAccountId matches regex @"^[0-9]{12}$"
    and isnotempty(SeedAccessKeyId) and SeedAccessKeyId != "REPLACE_WITH_ACCESS_KEY_ID",
    "Set the incident identity account and access key ID.");
let Sources = AWSCloudTrail
| where InputsValid and TimeGenerated between (Start .. End)
| where UserIdentityAccountId == SeedAWSAccountId and UserIdentityAccessKeyId == SeedAccessKeyId
| where isnotempty(SourceIpAddress) and SourceIpAddress !in ("127.0.0.1", "::1", "0.0.0.0")
| project IPAddress=SourceIpAddress
| distinct IPAddress;
union
    (union SigninLogs, AADNonInteractiveUserSignInLogs
    | where TimeGenerated between (Start .. End) and IPAddress in (Sources)
    | project Time=TimeGenerated, Source="Entra user sign-in", RecordId=Id, IPAddress,
        EntraTenantId=AADTenantId, ObjectId=UserId, ClientAppId=AppId, Result=ResultType),
    (AADServicePrincipalSignInLogs
    | where TimeGenerated between (Start .. End) and IPAddress in (Sources)
    | project Time=TimeGenerated, Source="Entra workload sign-in", RecordId=Id, IPAddress,
        EntraTenantId=AADTenantId, ObjectId=ServicePrincipalId, ClientAppId=AppId, Result=ResultType)
| extend Confidence="LOW: shared IP only; NAT, VPN, proxy and unrelated identities possible",
    NextStep="Validate object IDs and federation/workload mapping before attributing"
| order by Time asc
| take 5000

Explanation

This query is designed to identify potential security incidents by analyzing AWS and Azure sign-in logs. Here's a simplified breakdown of what it does:

  1. Time Frame: It looks at data from the last 24 hours.

  2. Input Validation: It checks if the AWS account ID is a 12-digit number and if the access key ID is provided and not a placeholder.

  3. Source IP Collection: It retrieves distinct source IP addresses from AWS CloudTrail logs where the specified AWS account and access key were used. It excludes common non-routable IP addresses like "127.0.0.1".

  4. Log Union: It combines data from Azure sign-in logs (both interactive and non-interactive) and Azure service principal sign-in logs, filtering for entries where the IP address matches those found in the AWS logs.

  5. Data Projection: For each matching log entry, it extracts relevant details such as time, source, record ID, IP address, tenant ID, object ID, client app ID, and result type.

  6. Confidence and Next Steps: It labels the findings with a low confidence level due to the potential for shared IP addresses (e.g., NAT, VPN, proxy) and suggests further validation of object IDs and mappings before making any attributions.

  7. Result Limitation: It orders the results by time and limits the output to 5,000 entries.

Overall, the query is a preliminary step to identify potential security issues by correlating AWS and Azure sign-in activities based on shared IP addresses, but it advises caution due to the low confidence in attribution.