Detect User Activity Based Checks in Elastic Security
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/
Elastic Detection Query
process where event.type == "start" and (
process.command_line regex~ "(?i)(getcursorpos|getlastinputinfo|mouse_event|setcursorpos|getasynckeystate|getforegroundwindow|getdesktopwindow)"
or (
process.name in~ ("cmd.exe", "powershell.exe") and
process.command_line regex~ "(?i)(desktop|recent|downloads|documents)" and
process.command_line regex~ "(?i)(count|\\.count|find /c|measure-object)"
)
or (
process.name like~ "reg.exe" and
process.command_line like~ "*recentdocs*"
)
or (
process.command_line regex~ "(?i)(history|bookmarks|cookies|places\\.sqlite)" and
not process.name regex~ "(?i)(chrome|firefox|msedge|brave|opera)\\.exe"
)
) Detects process execution patterns consistent with user activity enumeration used by malware to identify sandbox or analysis environments (T1497.002). Covers mouse Win32 API calls (GetCursorPos, GetLastInputInfo, mouse_event, SetCursorPos, GetAsyncKeyState), window handle queries (GetForegroundWindow, GetDesktopWindow), file count enumeration on user profile directories via cmd.exe or PowerShell, RecentDocs registry path access via reg.exe, and browser history or bookmarks path access by non-browser executables.
Data Sources
Required Tables
False Positives & Tuning
- Legitimate GUI automation frameworks such as AutoHotkey, AutoIt, PyAutoGUI, or Sikuli that invoke GetCursorPos or mouse_event Win32 APIs for UI testing pipelines
- IT administrator PowerShell scripts that count files in Desktop, Recent, or Downloads folders for storage quota audits or user profile cleanup routines
- Endpoint DLP or UEBA agents that inspect browser history and bookmark paths to enforce data governance or insider threat detection policies
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.
- 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.
- 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.
- 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.
References (6)
- https://attack.mitre.org/techniques/T1497/002/
- https://www.fireeye.com/blog/threat-research/2017/04/fin7-phishing-lnk.html
- https://unit42.paloaltonetworks.com/unit42-sofacy-continues-global-attacks-wheels-new-cannon-trojan/
- https://www.sans.org/reading-room/whitepapers/forensics/detecting-malware-sandbox-evasion-techniques-36667
- https://drive.google.com/file/d/1t0jn3xr4ff2fR30oQAUn_RsWSnMpOAQc/edit
- https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/T1497.002/T1497.002.md
Unlock Pro Content
Get the full detection package for T1497.002 including response playbook, investigation guide, and atomic red team tests.