Query Details

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 desc

About 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:

  1. 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.

  2. Data Source: It searches through the DeviceProcessEvents table for any command lines that include paths like /api/command, /api/zipdeploy, /api/vfs/, /api/processes, or the domain scm.azurewebsites.net.

  3. 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).

  4. Time Frame: It examines events from the past 7 days.

  5. 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.

  6. False Positives: It suggests excluding known legitimate activities, such as authorized deployments using zipdeploy, to reduce false alarms.

  7. 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.

  8. 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.