repositories

daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR

clonegit clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
service-triggers.mdMarkdown180 lines10.4 KiBrendered raw download
---
title: "Windows Service Triggers: Enumeration and Abuse"
section: "Windows"
sectionSlug: "windows-hardening"
sourcePath: "src/windows-hardening/windows-local-privilege-escalation/service-triggers.md"
sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/windows-hardening/windows-local-privilege-escalation/service-triggers.md"
sha: "188de82beb54e70956b2952367a0af91d26758b8"
isIndex: false
modified: true
license: "CC-BY-NC-4.0"
---

# Windows Service Triggers: Enumeration and Abuse

Windows Service Triggers allow the Service Control Manager (SCM) to start/stop a service when a condition occurs (e.g., an IP address becomes available, a named pipe connection is attempted, an ETW event is published). Even when you lack SERVICE_START rights on a target service, you may still be able to start it by causing its trigger to fire.<sup>[[1]](#references)</sup>

This page focuses on attacker-friendly enumeration and low-friction ways to activate common triggers.

> Tip: Starting a privileged built-in service (e.g., RemoteRegistry, WebClient/WebDAV, EFS) can expose new RPC/named-pipe listeners and unlock further abuse chains.

## Enumerating Service Triggers

- sc.exe (local)
  - List a service's triggers: `sc.exe qtriggerinfo <ServiceName>`
- Registry (local)
  - Triggers live under: `HKLM\SYSTEM\CurrentControlSet\Services\<ServiceName>\TriggerInfo`
  - Dump recursively: `reg query HKLM\SYSTEM\CurrentControlSet\Services\<ServiceName>\TriggerInfo /s`
- Win32 API (local)
  - Call QueryServiceConfig2 with SERVICE_CONFIG_TRIGGER_INFO (8) to retrieve SERVICE_TRIGGER_INFO.
    - Docs: QueryServiceConfig2[W/A] and SERVICE_TRIGGER/SERVICE_TRIGGER_SPECIFIC_DATA<sup>[[2]](#references)</sup>
- RPC over MS‑SCMR (remote)
  - The SCM can be queried remotely to fetch trigger info using MS‑SCMR. TrustedSec’s Titanis exposes this: `Scm.exe qtriggers`.
  - Impacket defines the structures in msrpc MS-SCMR; you can implement a remote query using those.<sup>[[1]](#references)[[3]](#references)[[4]](#references)</sup>
- PowerShell (bulk enumeration)
  - Quickly list every service exposing a `TriggerInfo` key:
    ```powershell
    Get-ChildItem 'HKLM:\SYSTEM\CurrentControlSet\Services' |
      Where-Object { Test-Path "$($_.PSPath)\TriggerInfo" } |
      ForEach-Object { sc.exe qtriggerinfo $_.PSChildName }
    ```
- PowerShell (programmatic)
  - James Forshaw's `NtObjectManager` module exposes `Get-Win32ServiceTrigger` for parsing trigger metadata without scraping `sc.exe` output.

## High-Value Trigger Types and How to Activate Them

### Network Endpoint Triggers

These start a service when a client attempts to talk to an IPC endpoint. Useful to low-priv users because the SCM will auto-start the service before your client can actually connect.<sup>[[1]](#references)</sup>

- Named pipe trigger
  - Behavior: A client connection attempt to \\.\pipe\<PipeName> causes the SCM to start the service so it can begin listening.
  - Activation (PowerShell):
    ```powershell
    $pipe = new-object System.IO.Pipes.NamedPipeClientStream('.', 'PipeNameFromTrigger', [System.IO.Pipes.PipeDirection]::InOut)
    try { $pipe.Connect(1000) } catch {}
    $pipe.Dispose()
    ```
  - Internals note: named-pipe triggers are backed by `npsvctrig.sys`, a filesystem minifilter that watches for opens against registered trigger pipe names. This is why the open attempt can start the service even before the service itself has created/listened on the pipe.<sup>[[5]](#references)</sup>
  - See also: Named Pipe Client Impersonation for post-start abuse.

- RPC endpoint trigger (Endpoint Mapper)
  - Behavior: Querying the Endpoint Mapper (EPM, TCP/135) for an interface UUID associated with a service causes the SCM to start it so it can register its endpoint.
  - Activation (Impacket):
    ```bash
    # Queries local EPM; replace UUID with the service interface GUID
    python3 rpcdump.py @127.0.0.1 -uuid <INTERFACE-UUID>
    ```

### Custom (ETW) Triggers

A service can register a trigger bound to an ETW provider/event. If no additional filters (keyword/level/binary/string) are configured, any event from that provider will start the service.<sup>[[1]](#references)</sup>

- Example (WebClient/WebDAV): provider {22B6D684-FA63-4578-87C9-EFFCBE6643C7}<sup>[[6]](#references)</sup>
  - List trigger: `sc.exe qtriggerinfo webclient`
  - Verify provider is registered: `logman query providers | findstr /I 22b6d684-fa63-4578-87c9-effcbe6643c7`
  - Emitting matching events typically requires code that logs to that provider; if no filters are present, any event suffices.
  - Minimal C shape for firing the provider (when no additional ETW filters are configured):
    ```c
    GUID g = {0x22B6D684,0xFA63,0x4578,{0x87,0xC9,0xEF,0xFC,0xBE,0x66,0x43,0xC7}};
    REGHANDLE h; EVENT_DESCRIPTOR d;
    EventRegister(&g, NULL, NULL, &h);
    EventDescCreate(&d, 1, 0, 0, 4, 0, 0, 0);
    EventWrite(h, &d, 0, NULL);
    EventUnregister(h);
    ```

### Group Policy Triggers

Subtypes: Machine/User. On domain-joined hosts where the corresponding policy exists, the trigger runs at boot. `gpupdate` alone won’t trigger without changes, but:<sup>[[1]](#references)</sup>

- Activation: `gpupdate /force`
  - If the relevant policy type exists, this reliably causes the trigger to fire and start the service.

### IP Address Available

Fires when the first IP is obtained (or last is lost). Often triggers at boot.<sup>[[1]](#references)</sup>

- Activation: Toggle connectivity to retrigger, e.g.:
  ```cmd
  netsh interface set interface name="Ethernet" admin=disabled
  netsh interface set interface name="Ethernet" admin=enabled
  ```

### Device Interface Arrival

Starts a service when a matching device interface arrives. If no data item is specified, any device matching the trigger subtype GUID will fire the trigger. Evaluated at boot and upon hot‑plug.<sup>[[1]](#references)</sup>

- Activation: Attach/insert a device (physical or virtual) that matches the class/hardware ID specified by the trigger subtype.

### Domain Join State

Despite confusing MSDN wording, this evaluates domain state at boot:<sup>[[1]](#references)</sup>
- DOMAIN_JOIN_GUID → start the service if domain-joined
- DOMAIN_LEAVE_GUID → start the service only if NOT domain-joined

### System State Change – WNF (undocumented)

Some services use undocumented WNF-based triggers (SERVICE_TRIGGER_TYPE 0x7). Activation requires publishing the relevant WNF state; specifics depend on the state name. Research background: Windows Notification Facility internals.

### Aggregate Service Triggers (undocumented)

Observed on Windows 11 for some services (e.g., CDPSvc). The aggregated configuration is stored in:

- HKLM\SYSTEM\CurrentControlSet\Control\ServiceAggregatedEvents

A service’s Trigger value is a GUID; the subkey with that GUID defines the aggregated event. Triggering any constituent event starts the service.<sup>[[1]](#references)</sup>

### Firewall Port Event (quirks and DoS risk)

A trigger scoped to a specific port/protocol has been observed to start on any firewall rule change (disable/delete/add), not just the specified port. Worse, configuring a port without a protocol can corrupt BFE startup across reboots, cascading into many service failures and breaking firewall management. Treat with extreme caution.<sup>[[1]](#references)</sup>

## Practical Workflow

1) Enumerate triggers on interesting services (RemoteRegistry, WebClient, EFS, …):
- `sc.exe qtriggerinfo <Service>`
- `reg query HKLM\SYSTEM\CurrentControlSet\Services\<Service>\TriggerInfo /s`

2) If a Network Endpoint trigger exists:
- Named pipe → attempt a client open to \\.\pipe\<PipeName>
- RPC endpoint → perform an Endpoint Mapper lookup for the interface UUID

3) If an ETW trigger exists:
- Check provider and filters with `sc.exe qtriggerinfo`; if no filters, any event from that provider will start the service

4) For Group Policy/IP/Device/Domain triggers:
- Use environmental levers: `gpupdate /force`, toggle NICs, hot-plug devices, etc.

## Related

- After starting a privileged service via a Named Pipe trigger, you may be able to impersonate it:

[Named Pipe Client Impersonation](/hacktricks/windows-hardening/windows-local-privilege-escalation/named-pipe-client-impersonation)

## Quick command recap

- List triggers (local): `sc.exe qtriggerinfo <Service>`
- Registry view: `reg query HKLM\SYSTEM\CurrentControlSet\Services\<Service>\TriggerInfo /s`
- Win32 API: `QueryServiceConfig2(..., SERVICE_CONFIG_TRIGGER_INFO, ...)`
- RPC remote (Titanis): `Scm.exe qtriggers`
- ETW provider check (WebClient): `logman query providers | findstr /I 22b6d684-fa63-4578-87c9-effcbe6643c7`

## Gotchas / Operator Notes

- Check the service start type first with `sc.exe qc <Service>`. If it is `DISABLED`, firing the trigger is not enough; you must first find a way to change the configuration.
- Trigger-start services may stop again after they become idle. If your follow-on action depends on a short-lived listener (RPC/named pipe/WebDAV), trigger and consume it immediately.
- `sc.exe qtriggerinfo` does not fully understand every undocumented trigger type. For aggregate triggers on newer Windows builds, confirm the backing GUID and constituent events in `HKLM\SYSTEM\CurrentControlSet\Control\ServiceAggregatedEvents`.

## Detection and Hardening Notes

- Baseline and audit TriggerInfo across services. Also review HKLM\SYSTEM\CurrentControlSet\Control\ServiceAggregatedEvents for aggregate triggers.
- Monitor for suspicious EPM lookups for privileged service UUIDs and named-pipe connection attempts that precede service starts.
- Restrict who can modify service triggers; treat unexpected BFE failures after trigger changes as suspicious.

## References
- [1] [There’s More than One Way to Trigger a Windows Service (TrustedSec)](https://trustedsec.com/blog/theres-more-than-one-way-to-trigger-a-windows-service)
- [2] [QueryServiceConfig2 function (Win32 API)](https://learn.microsoft.com/en-us/windows/win32/api/winsvc/nf-winsvc-queryserviceconfig2a)
- [3] [MS-SCMR: Service Control Manager Remote Protocol – QueryServiceConfig2](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-scmr/705b624a-13de-43cc-b8a2-99573da3635f)
- [4] [TrustedSec Titanis (SCM trigger enumeration)](https://github.com/trustedsec/Titanis)
- [5] [Reversing npsvctrig.sys - Named Pipe Service Triggers (Inbits)](https://inbits-sec.com/posts/npsvctrig-notes/)
- [6] [Starting WebClient Service Programmatically (Tyranid)](https://www.tiraniddo.dev/2015/03/starting-webclient-service.html)