T1505.005

Terminal Services DLL

Adversaries modify or replace the Terminal Services DLL (termsrv.dll) to establish persistence or enable unauthorized RDP capabilities. The ServiceDll registry value at HKLM\System\CurrentControlSet\services\TermService\Parameters\ServiceDll points to termsrv.dll. Attackers can patch termsrv.dll to enable multiple concurrent RDP sessions on non-server editions, or redirect the ServiceDll to a malicious DLL that executes arbitrary code when the Remote Desktop Service starts. RDPWrap abuses this mechanism legitimately; attackers weaponize the same technique.

Microsoft Sentinel / Defender
kusto
// T1505.005 — Terminal Services DLL persistence detection
// Monitor termsrv.dll modification and ServiceDll registry key changes
// Part 1: Detect modification of termsrv.dll
let TermsrvMod = DeviceFileEvents
| where Timestamp > ago(24h)
| where FileName =~ "termsrv.dll"
| where ActionType in ("FileModified", "FileCreated")
| where InitiatingProcessFileName !in~ ("TrustedInstaller.exe", "wusa.exe", "dism.exe",
                                         "msiexec.exe", "setup.exe", "svchost.exe")
| extend DetectionType = "TermSrv_DLL_Modified"
| project Timestamp, DeviceName, AccountName, FileName, FolderPath,
          InitiatingProcessFileName, InitiatingProcessCommandLine, DetectionType;
// Part 2: Detect TermService ServiceDll registry key modification
let TermServiceReg = DeviceRegistryEvents
| where Timestamp > ago(24h)
| where RegistryKey has_all ("TermService", "Parameters")
| where RegistryValueName =~ "ServiceDll"
| extend DetectionType = "TermService_ServiceDll_Modified"
| project Timestamp, DeviceName, AccountName, RegistryKey, RegistryValueName, RegistryValueData,
          InitiatingProcessFileName, InitiatingProcessCommandLine, DetectionType;
// Part 3: Detect suspicious DLLs loaded by svchost.exe for TermService
let TermServiceDLL = DeviceImageLoadEvents
| where Timestamp > ago(24h)
| where InitiatingProcessCommandLine has "TermService"
| where FileName =~ "termsrv.dll"
| where FolderPath !has "\\System32\\"
| extend DetectionType = "TermService_Non_Standard_DLL"
| project Timestamp, DeviceName, AccountName, FileName, FolderPath,
          InitiatingProcessFileName, InitiatingProcessCommandLine, DetectionType;
// Part 4: Detect RDPWrap-style registry indicators
let RDPWrapReg = DeviceRegistryEvents
| where Timestamp > ago(24h)
| where RegistryKey has_any ("rdpwrap", "RDPWrap", "rdpwrapper")
    or (RegistryKey has "TermService" and RegistryValueName has_any ("LogFile", "SrvcDllInitRegs"))
| extend DetectionType = "RDPWrap_Registry_Indicator"
| project Timestamp, DeviceName, AccountName, RegistryKey, RegistryValueName, RegistryValueData,
          InitiatingProcessFileName, DetectionType;
union TermsrvMod, TermServiceReg, TermServiceDLL, RDPWrapReg
| sort by Timestamp desc
high severity high confidence

Data Sources

File: File Modification Windows Registry: Registry Value Modification Module: Module Load Microsoft Defender for Endpoint

Required Tables

DeviceFileEvents DeviceRegistryEvents DeviceImageLoadEvents

False Positives

  • Windows Update patching termsrv.dll via TrustedInstaller (expected — exclude by initiating process)
  • RDPWrap legitimate deployment by IT administrators to enable concurrent RDP sessions on Windows 10 workstations for remote support
  • Third-party remote access tools that integrate with or extend Terminal Services
  • Virtual desktop infrastructure (VDI) solutions that customize Terminal Services behavior

Unlock Pro Content

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

Response PlaybookInvestigation GuideHunting QueriesAtomic Red Team TestsTuning Guidance

Related Detections