Query Details
# *ValleyRAT Exploiting BYOVD*
## Query Information
#### MITRE ATT&CK Technique(s)
| Technique ID | Title | Link |
| --- | --- | --- |
| T1543.003 | Create or Modify System Process: Windows Service | https://attack.mitre.org/techniques/T1543/003/ |
| T1574.002 | Hijack Execution Flow: DLL Side-Loading | https://attack.mitre.org/techniques/T1574/002/ |
| T1547.001 | Boot/Logon Autostart Execution: Registry Run Keys / Startup Folder | https://attack.mitre.org/techniques/T1547/001/ |
| M1047 | Audit | https://attack.mitre.org/mitigations/M1047/ |
#### Description
This KQL query is designed to detect a key technique used in the Valley RAT campaign, as detailed in the HexaStrike blog post. The rule focuses on a classic "Bring Your Own Vulnerable Driver" (BYOVD) attack method where an attacker installs a malicious driver or executable as a new service to achieve persistence and high-level privileges.
Detection Logic
The query analyzes DeviceRegistryEvents to identify suspicious changes to Windows services:
Service Path Manipulation: It specifically looks for modifications to the ImagePath registry value. This value tells Windows which file to execute when a service starts.
Suspicious Locations: The core of the detection is a filter for services whose ImagePath points to an unusual location, such as a temporary (%TEMP%) or program data directory (C:\ProgramData). Legitimate system drivers are almost always loaded from the C:\Windows\System32\drivers folder.
Exclusions: To reduce false positives, the rule excludes known legitimate processes, like those related to Microsoft Defender, that might write to these directories.
By identifying services that are configured to load files from untypical paths, this detection rule effectively uncovers a common tactic used by attackers to bypass security controls and establish a foothold on a system.
#### Risk
Persistence and Privilege Escalation achieved through Task Scheduler abuse by untrusted or custom executables
#### Author <Optional>
- **Name: Benjamin Zulliger**
- **Github: https://github.com/benscha/KQLAdvancedHunting**
- **LinkedIn: https://www.linkedin.com/in/benjamin-zulliger/**
#### References
- https://hexastrike.com/resources/blog/threat-intelligence/valleyrat-exploiting-byovd-to-kill-endpoint-security/
## Defender XDR
```KQL
//Valley RAT Detection (https://hexastrike.com/resources/blog/threat-intelligence/valleyrat-exploiting-byovd-to-kill-endpoint-security/)
// thx Maurice Fielenbach Blog Post which served as inspiration for this detection
DeviceRegistryEvents
| where ActionType == "RegistryValueSet" and RegistryValueName == "ImagePath"
//| where
| where RegistryKey matches regex @"HKEY_LOCAL_MACHINE\\SYSTEM\\(ControlSet.*|CurrentControlSet)\\Services\\"
| where RegistryValueData has_any ("%TEMP%", @"%LOCALAPPDATA%\Temp", @"C:\Windows\Temp", @"\AppData\Local\Temp", @"C:\ProgramData")
| where not(RegistryValueData
has_any (@"C:\ProgramData\Microsoft\Windows Defender\Platform\",
@"\??\C:\ProgramData\Microsoft\Windows Defender\Definition Updates\"))
```
This KQL query is designed to detect a specific attack technique used in the Valley RAT campaign, which involves exploiting a "Bring Your Own Vulnerable Driver" (BYOVD) method. Here's a simplified summary of what the query does:
Purpose: The query aims to identify suspicious modifications to Windows services that could indicate an attacker is trying to gain persistence and high-level privileges on a system.
Detection Focus:
ImagePath registry value, which specifies the file to execute when a service starts.ImagePath points to unusual directories, such as temporary folders or the C:\ProgramData directory, instead of the typical C:\Windows\System32\drivers folder where legitimate drivers are usually located.Exclusions: To avoid false positives, the query excludes known legitimate processes, such as those related to Microsoft Defender, which might also write to these directories.
Risk: The query helps identify potential persistence and privilege escalation attempts by detecting untrusted or custom executables being used inappropriately.
Author and References: The query was authored by Benjamin Zulliger, and it references a blog post from HexaStrike that details the Valley RAT campaign.
Overall, this query is a security measure to detect and prevent attackers from using vulnerable drivers to bypass security controls and maintain unauthorized access to a system.

Benjamin Zulliger
Released: October 9, 2025
Tables
Keywords
Operators