Query Details

Rule : AWS CLI Permission Dry Runs and Metadata Probes

Discovery AWS CLI Permission Probing

Query

DeviceProcessEvents
| where Timestamp > ago(7d)
| where FileName in~ ("aws","aws.exe","bash","sh","powershell.exe","pwsh.exe")
| where ProcessCommandLine has_any ("--dry-run","get-caller-identity","describe-snapshots","describe-volumes","describe-iam-instance-profile-associations","run-instances","create-volume","describe-security-groups")
| summarize Count=count(), DistinctCommands=dcount(ProcessCommandLine), Samples=make_set(substring(ProcessCommandLine,0,220),8), FirstSeen=min(Timestamp), LastSeen=max(Timestamp) by DeviceId, DeviceName, AccountName, bin(Timestamp,5m)
| where Count >= 4 and DistinctCommands >= 3
| order by Count desc

About this query

Explanation

This query is designed to detect suspicious activity related to AWS command-line interface (CLI) usage that may indicate an attempt to test or map out permissions using stolen credentials. Here's a simplified breakdown:

  1. Purpose: The query looks for bursts of AWS CLI activity that involve testing permissions without making changes (using --dry-run) and other actions like identifying the caller, and listing snapshots, volumes, and security groups. These actions are often used by attackers to understand what they can do with compromised AWS credentials.

  2. Data Source: It analyzes events from the DeviceProcessEvents table, focusing on processes related to AWS CLI and common shell environments like bash and PowerShell.

  3. Detection Criteria:

    • The query filters for specific AWS CLI commands that are indicative of permission probing or resource enumeration.
    • It triggers an alert if there are at least four such commands with three different command lines executed within a five-minute window.
  4. Output: The query summarizes the findings by counting the number of commands, identifying distinct command lines, and capturing samples of the command lines. It also notes the first and last time these activities were seen.

  5. Exclusions: To reduce false positives, it suggests excluding devices used by cloud operations teams or infrastructure-as-code (IaC) pipelines, as these might legitimately use similar commands.

  6. Next Steps: If suspicious activity is detected, the next steps involve identifying which AWS profile or access key was used and reviewing AWS CloudTrail logs for unauthorized operations.

  7. Limitations: This query only captures local command-line activities and not events logged in AWS CloudTrail. The thresholds for detection are initial suggestions and should be adjusted based on the environment.

Overall, this query helps security teams identify potential unauthorized AWS CLI usage that could indicate an attempt to explore or exploit AWS environments using compromised credentials.