Detection of Persistent Scripts in the Startup Directory
This rule identifies script engines creating files in the Startup folder, or the creation of script files in the Startup folder, enabling adversaries to maintain persistence by placing malicious scripts or shortcuts in the Windows Startup folder, which are then executed during account logon.
Attackers may establish persistence on a system by placing malicious scripts or shortcuts in the Windows Startup folder. This folder contains programs that are executed during account logon, without user interaction. This technique allows adversaries to automatically execute malicious code each time a user logs in. The rule detects the creation of script files (e.g., .vbs, .js, .ps1) within the Startup folder, as well as script engines (wscript.exe, cscript.exe) creating files within this directory. The monitored file extensions include vbs, vbe, wsh, wsf, js, jse, sct, hta, ps1, bat, and cmd. Successful exploitation can lead to persistent malware infections, unauthorized access, and further compromise of the system.
Attack Chain
- An attacker gains initial access to the target system through various means (e.g., phishing, exploitation of a vulnerability).
- The attacker identifies the Startup folder locations:
C:\Users\*\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\andC:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\. - The attacker crafts a malicious script (e.g., PowerShell script, VBScript, JavaScript).
- The attacker uses a script engine (e.g.,
wscript.exe,cscript.exe) or another process to create or modify a file with a malicious script, within one of the Startup folders. - Alternatively, the attacker directly copies a malicious script file into the Startup folder.
- The system is rebooted, or the user logs off and logs back on.
- The malicious script is automatically executed during the logon process.
- The attacker achieves persistence, enabling them to execute arbitrary commands, install malware, or perform other malicious activities on the system.
Impact
Successful exploitation allows for persistent malware infections, unauthorized access, and further compromise of the system. Attackers can use this persistence to maintain access to a compromised system even after reboots or credential changes. This can lead to data theft, system disruption, or further propagation of the attack within the network.
Recommendation
- Deploy the Sigma rule "Detect Script Creation in Startup Folder" to your SIEM and tune for your environment based on the
file_eventandprocess_creationlog sources. - Enable Sysmon file creation and process creation logging on Windows endpoints to collect the necessary event data for the Sigma rules above.
- Investigate any alerts generated by the Sigma rules above, focusing on unusual or unexpected script activity in the Startup folder.
- Consider implementing application control policies to restrict the execution of unauthorized scripts and executables in the Startup folder.
Detection coverage 2
Detect Script Creation in Startup Folder
mediumDetects script engines (wscript.exe, cscript.exe) creating script files in the Windows Startup folder.
Detect Script File Creation in Startup Folder
mediumDetects the creation of script files (vbs, vbe, wsh, wsf, js, jse, sct, hta, ps1, bat, cmd) within the Windows Startup folder.
Detection queries are available on the platform. Get full rules →