Detection: Windows Node.exe Executing JS Script In Immediate Folder

Description

The following analytic identifies node.exe directly executing a single .js script located in the same directory it was launched from, where that directory is an unusual location such as a user profile, PerfLogs, ProgramData, or Temp folder. Legitimate Node.js application, module, and package manager directories are excluded. This pattern is commonly associated with malware loaders and second-stage payloads that leverage the Node.js runtime to execute JavaScript outside of a typical development or application context.

 1
 2| tstats `security_content_summariesonly`
 3  count min(_time) as firstTime
 4        max(_time) as lastTime
 5
 6FROM datamodel=Endpoint.Processes WHERE
 7
 8(
 9    Processes.process_name="node.exe"
10    OR
11    Processes.original_file_name="node.exe"
12)
13Processes.process="*js"
14Processes.process_path IN (
15    "*:\\PerfLogs\\*",
16    "*:\\ProgramData\\*",
17    "*:\\Temp\\*",
18    "*:\\Users\\*"
19)
20(
21    NOT Processes.process_path IN (
22        "*\\AppData\\Roaming\\*",
23        "*\\node\\*",
24        "*\\nodejs\\*",
25        "*\\nvm\\*"
26    )
27    AND
28    (
29        NOT Processes.process_path = "*\\AppData\\Local\\*"
30        OR
31        Processes.process_path = "*\\AppData\\Local\\Temp\\*"
32    )
33)
34
35by Processes.action Processes.dest Processes.original_file_name
36   Processes.parent_process Processes.parent_process_exec
37   Processes.parent_process_guid Processes.parent_process_id
38   Processes.parent_process_name Processes.parent_process_path
39   Processes.process Processes.process_exec Processes.process_guid
40   Processes.process_hash Processes.process_id
41   Processes.process_integrity_level Processes.process_name
42   Processes.process_path Processes.user Processes.user_id
43   Processes.process_current_directory Processes.vendor_product
44
45
46| `drop_dm_object_name(Processes)`
47
48
49| eval process_args=split(process, " ")
50
51| eval script_name=mvindex(process_args, 1)
52
53| eval process_args_count=mvcount(process_args)
54
55| regex script_name="(?i)^[^\\\/]+\.js$"
56
57| where like(process_path, process_current_directory.process_name) AND process_args_count=2
58
59
60| `security_content_ctime(firstTime)`
61
62| `security_content_ctime(lastTime)`
63
64| `windows_node_exe_executing_js_script_in_immediate_folder_filter`

Data Source

Name Platform Sourcetype Source
Sysmon EventID 1 Windows icon Windows 'XmlWinEventLog' 'XmlWinEventLog:Microsoft-Windows-Sysmon/Operational'
CrowdStrike ProcessRollup2 Other 'crowdstrike:events:sensor' 'crowdstrike'
Windows Event Log Security 4688 Windows icon Windows 'XmlWinEventLog' 'XmlWinEventLog:Security'

Macros Used

Name Value
security_content_summariesonly summariesonly=summariesonly_config allow_old_summaries=oldsummaries_config fillnull_value=fillnull_config``
windows_node_exe_executing_js_script_in_immediate_folder_filter search *
windows_node_exe_executing_js_script_in_immediate_folder_filter is an empty macro by default. It allows the user to filter out any results (false positives) without editing the SPL.

Annotations

Default Configuration

This detection is configured by default in Splunk Enterprise Security to run with the following settings:

Setting Value
Disabled true
Cron Schedule 0 * * * *
Earliest Time -70m@m
Latest Time -10m@m
Schedule Window auto
Creates Finding (Notable) Yes
Rule Title %name%
Rule Description %description%
Notable Event Fields user, dest
Creates Intermediate Finding (Risk Event) No
TTP detections generate a Finding (Notable) and may generate Intermediate Findings (Risk Events) for associated entities.

Implementation

The detection is based on data that originates from Endpoint Detection and Response (EDR) agents. These agents are designed to provide security-related telemetry from the endpoints where the agent is installed. To implement this search, you must ingest logs that contain the process GUID, process name, and parent process. Additionally, you must ingest complete command-line executions. These logs must be processed using the appropriate Splunk Technology Add-ons that are specific to the EDR product. The logs must also be mapped to the Processes node of the Endpoint data model. Use the Splunk Common Information Model (CIM) to normalize the field names and speed up the data modeling process.

Known False Positives

Legitimate custom Node.js tooling or utility scripts that are intentionally placed and executed from a user profile, PerfLogs, ProgramData, or Temp directory may trigger this analytic.

Associated Analytic Story

Finding

Title Entity Field Entity Type Risk Score
Node.exe executed script [$script_name$] from an unusual directory on [$dest$] dest system 50

Threat Objects

Field Type
script_name file_name
process process

References

Detection Testing

Test Type Status Dataset Source Sourcetype
Validation Passing N/A N/A N/A
Unit Passing Dataset XmlWinEventLog:Microsoft-Windows-Sysmon/Operational XmlWinEventLog
Integration ✅ Passing Dataset XmlWinEventLog:Microsoft-Windows-Sysmon/Operational XmlWinEventLog

Replay any dataset to Splunk Enterprise by using our replay.py tool or the UI. Alternatively you can replay a dataset into a Splunk Attack Range


Source: GitHub |

Version: 1