Query Details

06 Aws Alert Counts

Query

// REVIEW ONLY workbook query: 3.1 AWS Alert Volume by Severity & Classification Basis
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;
AwsAlerts
| summarize Alerts=count(), LastObserved=max(TimeGenerated) by AlertSeverity, ClassificationBasis
| order by Alerts desc
| take 100

Explanation

This query is designed to analyze AWS security alerts within a specified time range. Here's a simplified breakdown of what it does:

  1. Time Range and Scope: It sets a start and end time for the analysis and decodes the alert scope from a base64 string.

  2. Known AWS Alert Names: It defines a list of known AWS alert names that are considered significant for this analysis.

  3. Additional AWS Alert Names: It decodes any additional AWS alert names provided in a base64 string and includes them in the analysis if they exist.

  4. Data Collection: It collects security alerts from a data source, filtering them to only include alerts generated within the specified time range.

  5. Classification: Each alert is classified based on certain criteria:

    • If the alert entities contain an AWS ARN, it's classified as "AWS ARN in alert entities."
    • If the alert name matches known or additional AWS alert names, it's classified as "Reviewed AWS alert name."
    • If the alert query references AWS-related tables or products, it's classified accordingly.
    • If the alert name contains "AWS," it's flagged as a candidate for further verification.
    • Alerts that don't match any criteria are labeled as "Unclassified workspace alert."
  6. Filtering: Alerts are filtered based on the specified alert scope, excluding those classified as "Unclassified workspace alert" unless the scope is set to "All."

  7. Summarization: The query summarizes the alerts by counting them and identifying the last time they were observed, grouped by alert severity and classification basis.

  8. Ordering and Limiting: The results are ordered by the number of alerts in descending order, and only the top 100 results are displayed.

In essence, this query helps to categorize and prioritize AWS security alerts based on their severity and classification, providing insights into the volume and nature of alerts over a given period.