Rule : Azure CLI Permission and Storage Testing Burst
Discovery Azure CLI Permission Probing
Query
DeviceProcessEvents
| where Timestamp > ago(7d)
| where FileName in~ ("az","az.exe","powershell.exe","pwsh.exe","curl.exe") or (FileName in~ ("python.exe","python3","python") and ProcessCommandLine has "azure.cli")
| where ProcessCommandLine has_any ("deployments validate","deployment group validate","account keys list","storage blob","role assignment list","listKeys","what-if","--auth-mode","--sas-token")
| 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 descAbout this query
Explanation
This query is designed to detect unusual bursts of Azure CLI or PowerShell command activity that might indicate unauthorized or aggressive probing of cloud permissions and storage. It specifically looks for certain command patterns that are often used to validate deployments, list storage keys, or test authentication methods. Here's a simplified breakdown:
-
Purpose: The query aims to identify potential security threats by detecting bursts of specific Azure CLI or PowerShell commands that could indicate malicious activity once cloud credentials are compromised.
-
Detection Criteria:
- It monitors processes like
az,PowerShell,curl, andpythonthat interact with Azure CLI. - It looks for specific command keywords related to deployments, storage, and role assignments.
- It triggers an alert if there are 4 or more commands with at least 3 different command lines executed within a 5-minute window.
- It monitors processes like
-
Data Source: The query analyzes data from the
DeviceProcessEventstable, which logs process events on devices. -
Exclusions: To reduce false positives, it suggests excluding known infrastructure deployment pipelines and cloud operations hosts from the analysis.
-
Actionable Steps:
- If an alert is triggered, identify the user account associated with the suspicious activity.
- Check the
AzureActivitylogs for the same user to understand the context and outcome of the API calls.
-
Limitations: The query only captures local command-line activity and not direct Azure API interactions. The thresholds for alerts are initial suggestions and should be adjusted based on the environment.
Overall, this query helps security teams monitor and respond to potential unauthorized access or probing activities in their Azure environments.