Query Details

08 Aws Incident Snapshots

Query

// REVIEW ONLY workbook query: 3.3 Sentinel Incidents Linked to AWS Alerts
let Start = {TimeRange:start};
let End = {TimeRange:end};
let AlertScope = base64_decode_tostring("{AlertScope:base64}");
let KnownAwsNames = dynamic(["AWSCloudTrail - Successful API executed from a Tor exit node","AWSCloudTrail - Changes to internet facing AWS RDS Database instances","AWSCloudTrail - Changes to Amazon VPC settings","AWSCloudTrail - Failed Attempts to Change AWS CloudTrail Logs","AWSCloudTrail - Login to AWS Management Console without MFA","AWSCloudTrail - CloudFormation policy created then used for privilege escalation","AWSCloudTrail - Creation of CRUD DynamoDB policy and then privilege escalation","AWSCloudTrail - Creation of new CRUD IAM policy and then privilege escalation","AWSCloudTrail - Creation of CRUD KMS policy and then privilege escalation","AWSCloudTrail - Creation of CRUD Lambda policy and then privilege escalation","AWSCloudTrail - Created CRUD S3 policy and then privilege escalation","AWSCloudTrail - Creation of DataPipeline policy and then privilege escalation","AWSCloudTrail - Creation of EC2 policy and then privilege escalation","AWSCloudTrail - Creation of Glue policy and then privilege escalation","AWSCloudTrail - Creation of Lambda policy and then privilege escalation","AWSCloudTrail - Creation of SSM policy and then privilege escalation","AWSCloudTrail - Creating keys with encrypt policy without MFA","AWSCloudTrail - Monitor AWS Credential abuse or hijacking","AWSCloudTrail - EC2 Startup Shell Script Changed","AWSCloudTrail - ECR image scan findings high or critical","AWSCloudTrail - Amazon ECR image scanning disabled","AWSCloudTrail - Full Admin policy created and then attached to Roles, Users or Groups","AWSCloudTrail - AWS GuardDuty detector disabled or suspended","AWSGuardDuty - GuardDuty Alert","AWSCloudTrail - Changes to AWS Security Group ingress and egress settings","AWSCloudTrail - Changes to AWS Elastic Load Balancer security groups","AWSCloudTrail - Successful Tampering with AWS CloudTrail Logs","AWSCloudTrail - Network ACL with all the open ports to a specified CIDR","AWSCloudTrail - Suspicious overly permissive KMS key policy created","AWSCloudTrail - Privilege escalation with AdministratorAccess managed policy","AWSCloudTrail - Privilege escalation with admin managed policy","AWSCloudTrail - Privilege escalation with FullAccess managed policy","AWSCloudTrail - Privilege escalation via CloudFormation policy","AWSCloudTrail - Privilege escalation via CRUD DynamoDB policy","AWSCloudTrail - Privilege escalation via CRUD IAM policy","AWSCloudTrail - Privilege escalation via CRUD KMS policy","AWSCloudTrail - Privilege escalation via CRUD Lambda policy","AWSCloudTrail - Privilege escalation via CRUD S3 policy","AWSCloudTrail - Privilege escalation via DataPipeline policy","AWSCloudTrail - Privilege escalation via EC2 policy","AWSCloudTrail - Privilege escalation via Glue policy","AWSCloudTrail - Privilege escalation via Lambda policy","AWSCloudTrail - Privilege escalation via SSM policy","AWSCloudTrail - RDS instance publicly exposed","AWSCloudTrail - Successful brute force attack on S3 Bucket","AWSCloudTrail - S3 bucket access point publicly exposed","AWSCloudTrail - S3 bucket exposed via ACL","AWSCloudTrail - S3 bucket exposed via policy","AWSCloudTrail - S3 Object Exfiltration from Anonymous User","AWSCloudTrail - S3 object publicly exposed","AWSCloudTrail - S3 bucket suspicious ransomware activity","AWSCloudTrail - SAML update identity provider","AWSCloudTrail - Policy version set to default","AWSCloudTrail - SSM document is publicly exposed","AWSCloudTrail - Suspicious command sent to EC2","AWSCloudTrail - Unauthorized EC2 Instance Setup Attempt","AWSCloudTrail - Creation of Access Key for IAM User","AWSCloudTrail - User IAM Enumeration","AWSCloudTrail - NRT Login to AWS Management Console without MFA","AWSCloudTrail - Suspicious AWS CLI Command Execution","AWSCloudTrail - Suspicious AWS EC2 Compute Resource Deployments","AWS Security Hub - Detect CloudTrail trails lacking KMS encryption","AWS Security Hub - Detect EC2 Security groups allowing unrestricted high-risk ports","AWS Security Hub - Detect IAM Policies allowing full administrative privileges","AWS Security Hub - Detect root user lacking MFA","AWS Security Hub - Detect IAM root user Access Key existence","AWS Security Hub - Detect SQS Queue lacking encryption at rest","AWS Security Hub - Detect SQS Queue policy allowing public access","AWS Security Hub - Detect SSM documents public sharing enabled","AWS cross-cloud - Risky Entra identity pivots from log searches to secrets","AWS cross-cloud - ScreenConnect-launched AWS secret retrieval","AWS cross-cloud - Python startup artifacts and metadata access precede secrets use","AWS cross-cloud - PHP descendant contacts metadata before EC2 role secrets use","AWS cross-cloud - New Entra workload source also retrieves AWS secrets","AWS cross-cloud - AWS secrets use precedes Entra application credential change","AWS SecOps P0-01 - Root or Break-Glass Runtime Activity and Escalation","AWS SecOps P0-02 - Coordinated IAM Credential Persistence and Cross-Principal Backdooring","AWS SecOps P0-03 - Trust Policy Backdoor, Inline Escalation and Sensitive PassRole Abuse","AWS SecOps P0-04 - Autonomous Cross-Account or Sensitive STS AssumeRole Chain","AWS SecOps P0-05 - CloudTrail Selector Downgrade and Logging Delivery Tampering","AWS SecOps P0-06a - GuardDuty High Severity Prioritized Baseline (Single-Source)","AWS SecOps P0-06b - GuardDuty Correlated with CloudTrail Mutations, VPC Egress and Entra Bridge","AWS SecOps P0-07a - S3 PublicAccessBlock Weakening and Sensitive Bucket Burst Read (Single-Source)","AWS SecOps P0-07b - S3 Exfiltration GuardDuty Finding Correlated with Permission Change or VPC Egress","AWS SecOps P0-08 - AWS Connector Failure, Ingestion Lag and Per-Source Blind Spot","AWS SecOps P1-01a - Route 53 DNS Tunneling, Subdomain Fan-Out and High NXDOMAIN Ratio (Single-Source)","AWS SecOps P1-01b - Route 53 Queries Matching Threat Intel and Correlated VPC Egress","AWS SecOps P1-02 - AWS WAF Attack Campaign and Block-to-Allow Bypass Candidate","AWS SecOps P1-03a - VPC Flow Port/Host Scan and High-Byte Rare-Port Egress (Single-Source)","AWS SecOps P1-03b - VPC Flow Threat-Intel IP Egress and Low-Jitter Beaconing","AWS SecOps P1-04a - EKS Audit Pod Exec, Privileged Workload and Cluster-Admin Escalation (Single-Source)","AWS SecOps P1-04b - EKS Audit Risk Correlated with GuardDuty Container Findings or CloudTrail EKS Role Changes","AWS SecOps P1-05 - CloudFront Signed-URL Abuse, Path Enumeration and Automation Anomaly","AWS SecOps P2-01a - AWS Network Firewall High-Severity Alert and Allowed Threat Signature (Single-Source)","AWS SecOps P2-01b - AWS Network Firewall Correlated with VPC Flow, GuardDuty and IAM Changes"]);
let RawExtraAwsNames = todynamic(base64_decode_tostring("{AdditionalAwsAlertNames:base64}"));
let ExtraAwsNames = iff(isnotnull(array_length(RawExtraAwsNames)), RawExtraAwsNames, dynamic([]));
let AwsAlerts = union isfuzzy=true
  (datatable(TimeGenerated:datetime, SystemAlertId:string, AlertName:string, AlertSeverity:string,
    ProductName:string, ProviderName:string, Status:string, StartTime:datetime, EndTime:datetime,
    Entities:string, ExtendedProperties:string)[]),
  (SecurityAlert
   | where TimeGenerated between (Start .. End)
   | project TimeGenerated, SystemAlertId, AlertName, AlertSeverity, ProductName, ProviderName,
       Status, StartTime, EndTime, Entities, ExtendedProperties)
| extend Ext=parse_json(ExtendedProperties)
| extend ClassificationBasis=case(
    tostring(Entities) matches regex @"arn:aws[a-z-]*:", "AWS ARN in alert entities",
    AlertName in (KnownAwsNames) or AlertName in (ExtraAwsNames), "Reviewed AWS alert name",
    tostring(Ext.Query) has_any ("AWSCloudTrail", "AWSGuardDuty", "AWSVPCFlow", "AWSRoute53Resolver", "AWSWAF"), "Alert query references AWS table",
    ProductName has_any ("GuardDuty", "AWS"), "AWS-related alert product",
    AlertName has "AWS", "AWS name candidate: verify affected environment",
    "Unclassified workspace alert")
| where AlertScope == "All" or ClassificationBasis != "Unclassified workspace alert"
| summarize arg_max(TimeGenerated, *) by SystemAlertId;
let AwsAlertIds = AwsAlerts | project AlertId=SystemAlertId;
union isfuzzy=true
  (datatable(TimeGenerated:datetime, IncidentName:string, IncidentNumber:int, Title:string, Severity:string, Status:string, CreatedTime:datetime, LastModifiedTime:datetime, IncidentUrl:string, AlertIds:dynamic)[]),
  (SecurityIncident
   | where TimeGenerated between (Start .. End)
   | project TimeGenerated, IncidentName, IncidentNumber, Title, Severity, Status, CreatedTime, LastModifiedTime, IncidentUrl, AlertIds=todynamic(AlertIds))
| summarize arg_max(TimeGenerated, *) by IncidentName
| mv-expand AlertId=AlertIds to typeof(string)
| join kind=inner AwsAlertIds on AlertId
| summarize MatchedAwsAlerts=count_distinct(AlertId), MatchedAlertIds=make_set(AlertId, 100)
    by TimeGenerated, IncidentName, IncidentNumber, Title, Severity, Status, CreatedTime, LastModifiedTime, IncidentUrl
| project IncidentNumber, Severity, Status, Title, MatchedAwsAlerts, CreatedTime, LastModifiedTime, IncidentUrl, MatchedAlertIds
| order by LastModifiedTime desc
| take 5000

Explanation

This query is designed to review and analyze security incidents in Microsoft Sentinel that are linked to AWS alerts. Here's a simplified breakdown of what the query does:

  1. Time Range and Alert Scope: It sets a time range (Start and End) and decodes a base64 string to determine the scope of alerts to consider (AlertScope).

  2. Known AWS Alert Names: It defines a list of known AWS alert names (KnownAwsNames) that are considered significant for security monitoring.

  3. Additional AWS Alert Names: It decodes additional AWS alert names from a base64 string and checks if there are any extra names to consider (ExtraAwsNames).

  4. AWS Alerts Extraction: It retrieves AWS-related security alerts from the SecurityAlert table within the specified time range. It classifies these alerts based on certain criteria, such as the presence of AWS-related terms in alert names or queries, and filters them according to the specified alert scope.

  5. Incident Extraction: It retrieves security incidents from the SecurityIncident table within the specified time range. Each incident is expanded to list all associated alert IDs.

  6. Matching Incidents with AWS Alerts: It joins the incidents with the AWS alerts based on alert IDs to find incidents that are linked to AWS alerts.

  7. Summarization: It summarizes the matched incidents by counting distinct AWS alerts linked to each incident and compiles a list of matched alert IDs.

  8. Output: The query outputs a list of up to 5000 incidents, ordered by the last modified time, showing details such as incident number, severity, status, title, the number of matched AWS alerts, creation and modification times, incident URL, and matched alert IDs.

In summary, this query helps identify and review security incidents in Sentinel that are related to AWS alerts, providing insights into potential security issues involving AWS resources.