T1497.002 Microsoft Sentinel · KQL

Detect User Activity Based Checks in Microsoft Sentinel

Adversaries may employ various user activity checks to detect and avoid virtualization and analysis environments. This includes checking mouse movement speed/frequency, click patterns, browser history and bookmarks, number of files on the desktop or in common directories, recently opened documents, and presence of user-created files. Some malware requires specific user interaction before activating, such as waiting for a document to close, a user to double-click an embedded image, or waiting for mouse button presses. Darkhotel checks mouse cursor position repeatedly, Okrum requires three left-clicks before executing, and FIN7 used embedded images requiring double-clicks to activate.

MITRE ATT&CK

Tactic
Defense Evasion Discovery
Technique
T1497 Virtualization/Sandbox Evasion
Sub-technique
T1497.002 User Activity Based Checks
Canonical reference
https://attack.mitre.org/techniques/T1497/002/

KQL Detection Query

Microsoft Sentinel (KQL)
kusto
let UserActivityAPIs = dynamic(["GetCursorPos", "GetLastInputInfo", "GetForegroundWindow", "GetAsyncKeyState", "GetKeyState", "mouse_event", "SetCursorPos", "GetDesktopWindow"]);
let UserActivityChecks = dynamic(["RecentDocs", "Recent", "Desktop", "Favorites", "Bookmarks", "History", "Cookies", "Downloads"]);
DeviceProcessEvents
| where Timestamp > ago(24h)
| where ProcessCommandLine has_any (UserActivityAPIs)
    or (FileName in~ ("cmd.exe", "powershell.exe") and ProcessCommandLine has_any ("dir /b", "Get-ChildItem") 
        and ProcessCommandLine has_any ("Desktop", "Recent", "Downloads", "Documents") 
        and ProcessCommandLine has_any ("count", ".Count", "find /c", "Measure-Object"))
    or (FileName =~ "reg.exe" and ProcessCommandLine has "RecentDocs")
| extend MouseCheck = ProcessCommandLine has_any ("GetCursorPos", "GetLastInputInfo", "mouse_event", "SetCursorPos")
| extend WindowCheck = ProcessCommandLine has_any ("GetForegroundWindow", "GetDesktopWindow")
| extend FileCountCheck = ProcessCommandLine has_any ("Desktop", "Recent", "Downloads") and ProcessCommandLine has_any ("count", ".Count", "find /c", "Measure-Object")
| extend RecentDocsCheck = ProcessCommandLine has "RecentDocs"
| project Timestamp, DeviceName, AccountName, FileName, ProcessCommandLine,
         InitiatingProcessFileName, InitiatingProcessCommandLine,
         MouseCheck, WindowCheck, FileCountCheck, RecentDocsCheck
| sort by Timestamp desc
medium severity low confidence

Detects user activity-based sandbox evasion techniques. Monitors for API calls checking mouse position/input activity, foreground window comparison (TONESHELL technique), file count checks in user directories (Desktop, Recent, Downloads), and registry queries for RecentDocs. Covers techniques used by Darkhotel, Okrum, FIN7, TONESHELL, and Spark.

Data Sources

Process: Process CreationCommand: Command ExecutionProcess: OS API ExecutionMicrosoft Defender for Endpoint

Required Tables

DeviceProcessEvents

False Positives & Tuning

  • Accessibility tools and automation software that track mouse position for user interface automation
  • RPA (Robotic Process Automation) tools like UiPath that monitor user input state
  • Custom IT scripts that count files in user directories for compliance or cleanup purposes
  • Screen recording or remote desktop software that tracks input events
Download portable Sigma rule (.yml)

Other platforms for T1497.002


Testing Methodology

Validate this detection against 3 adversary techniques from Atomic Red Team. Each test below lists the behaviour to exercise and the telemetry you should expect to see. Executable commands and cleanup steps are available with Pro.

  1. Test 1Check desktop file count for sandbox detection

    Expected signal: Sysmon Event ID 1: Process Create for cmd.exe with 'dir /b' + Desktop path, piped to find.exe. Two process events generated.

  2. Test 2Check RecentDocs registry for user activity

    Expected signal: Sysmon Event ID 1: Process Create for reg.exe with RecentDocs query. Sysmon Event ID 13: Registry key access event for the RecentDocs path.

  3. Test 3PowerShell mouse position check for sandbox detection

    Expected signal: Sysmon Event ID 1: PowerShell process with GetCursorPos in command line. PowerShell ScriptBlock Log Event ID 4104 with the full P/Invoke code and mouse check logic.

Unlock Pro Content

Get the full detection package for T1497.002 including response playbook, investigation guide, and atomic red team tests.

Response PlaybookInvestigation GuideHunting QueriesAtomic Red Team TestsTuning Guidance

Related Detections