Rule : Kudu SCM API and Remote Execution Visible in Process Command Lines
Execution Kudu SCM Remote Commands
Query
DeviceProcessEvents
| where Timestamp > ago(7d)
| where ProcessCommandLine has_any ("/api/command","/api/zipdeploy","/api/vfs/","scm.azurewebsites.net","/api/processes")
| where FileName in~ ("curl.exe","curl","powershell.exe","pwsh.exe","python.exe","python3","bash","sh","az.exe","az")
| project Timestamp, DeviceId, DeviceName, AccountName, FileName, ProcessCommandLine, InitiatingProcessFileName
| order by Timestamp descAbout this query
Explanation
This query is designed to detect potentially malicious activities involving Azure App Service's Kudu/SCM APIs, which can be used for remote command execution and file access. Here's a simplified breakdown:
-
Purpose: The query looks for command lines that interact with specific Kudu/SCM API endpoints, which might indicate unauthorized access or misuse of Azure App Service resources.
-
Data Source: It searches through the
DeviceProcessEventstable for any command lines that include paths like/api/command,/api/zipdeploy,/api/vfs/,/api/processes, or the domainscm.azurewebsites.net. -
Tools Monitored: The query focuses on command lines executed by tools commonly used for scripting and automation, such as
curl, PowerShell, Python, shell scripts, and the Azure CLI (az). -
Time Frame: It examines events from the past 7 days.
-
Output: The query returns details like the timestamp, device ID and name, account name, file name, and the full command line for each matching event, sorted by the most recent first.
-
False Positives: It suggests excluding known legitimate activities, such as authorized deployments using
zipdeploy, to reduce false alarms. -
Investigation Steps: If suspicious activity is detected, the next steps involve identifying the targeted application and reviewing logs for any commands executed through the Kudu API.
-
Limitations: The query requires visibility into process command lines and won't catch server-side API requests. It's recommended to use this query as a hunting tool initially to fine-tune thresholds and reduce false positives.