Detection rules › Kusto
Detect executable drops via Azure custom script extension
This detection rule flags when the Custom Script extension service on a machine is dropping executable files. This might indicate that an actor is trying to drop malware or beacons via a compromised cloud admin account. In the most legitimate cases administrators are pushing only PowerShell or Shell scripts, although these can also contain malicious content. Be aware of this gap in the below detection rule.
MITRE ATT&CK coverage
| Tactic | Techniques |
|---|---|
| Execution | |
| Lateral Movement |
References
Telemetry coverage
Rule body
// Executable extensions we want to flag (you can also add .ps1 and .sh)
let win_executable_extensions = dynamic([".dll", ".exe", ".msi", ".bat", ".cmd", ".com", ".vbs", ".wsf", ".scr", ".cpl"]);
DeviceFileEvents
| where TimeGenerated > ago(1h)
// Search for file created events by Arc Custom Script Handler
| where ActionType == "FileCreated"
| where InitiatingProcessFileName =~ "customscripthandler.exe"
// Get the file type
| extend FileType = tostring(parse_json(AdditionalFields).FileType)
// Flag on extension or executable file type
| where FileName has_any (win_executable_extensions) or
FileType contains "Executable"
Stages and Predicates
Parameters
let win_executable_extensions = dynamic([".dll", ".exe", ".msi", ".bat", ".cmd", ".com", ".vbs", ".wsf", ".scr", ".cpl"]);
Stage 1: source
DeviceFileEvents
Stage 2: where
| where TimeGenerated > ago(1h)
Stage 3: where
| where ActionType == "FileCreated"
Stage 4: where
| where InitiatingProcessFileName =~ "customscripthandler.exe"
Stage 5: extend
| extend FileType = tostring(parse_json(AdditionalFields).FileType)
Stage 6: where
| where FileName has_any (win_executable_extensions) or
FileType contains "Executable"
Indicators
These rows show field, operator, and value matches.
| Field | Kind | Values | Search |
|---|---|---|---|
ActionType | eq |
| field:"ActionType" kind:eq value:"FileCreated" |
FileName | match |
| field:"file_name" kind:match |
FileType | contains |
| field:"FileType" kind:contains value:"Executable" |
InitiatingProcessFileName | eq |
| field:"parent_process_name" kind:eq value:"customscripthandler.exe" |
Output fields
These fields are emitted when the rule matches.
| Field | Source |
|---|---|
FileType | extend |