Desired state: compromised

Ryan Kazanciyan (Chief Security Architect · Tanium), Matt Hastings

BruCON 0x07 · Day 2

Overview

In their BruCON talk, "Desired state: compromised," Ryan Kazanciyan and Matt Hastings unveil a novel and stealthy method for achieving post-compromise persistence on Windows systems using Desired State Configuration (DSC). This presentation delves into how a legitimate, built-in Windows management feature, primarily designed for DevOps and system administration, can be repurposed by attackers to maintain unauthorized access, re-establish compromised states, and evade traditional detection mechanisms. The speakers, both seasoned incident response and forensics experts, highlight the obscurity and inherent "self-healing" capabilities of DSC as key attributes making it an attractive, yet currently underutilized, tool for adversaries.

Watch on YouTube

Visual summary for Desired state: compromised by Ryan Kazanciyan, Matt Hastings
Visual summary for Desired state: compromised by Ryan Kazanciyan, Matt Hastings

Key moments

  1. 0:00 Introduction: What is Desired State Configuration (DSC)?
  2. 2:30 DSC's capabilities: A self-fixing backdoor mechanism.
  3. 8:00 Introducing the DSCompromise Framework for weaponizing DSC.
  4. 10:00 Demo: Persisting malware and automatic reinfection.
  5. 21:00 Demo: Persisting unauthorized local administrator accounts.
  6. 24:00 Blue Team: Detecting DSC use via network and disk evidence.
  7. 28:00 Blue Team: Detecting DSC use via event logs and PowerShell.
  8. 32:00 Cleanup, future of DSC, and DSCompromise framework plans.

Desired state: compromised

Speakers: Ryan Kazanciyan (Chief Security Architect, Tanium); Matt Hastings

Conference: BruCON

YouTube: https://www.youtube.com/watch?v=9zbNgcaf1Aw

Overview

In their BruCON talk, "Desired state: compromised," Ryan Kazanciyan and Matt Hastings unveil a novel and stealthy method for achieving post-compromise persistence on Windows systems using Desired State Configuration (DSC). This presentation delves into how a legitimate, built-in Windows management feature, primarily designed for DevOps and system administration, can be repurposed by attackers to maintain unauthorized access, re-establish compromised states, and evade traditional detection mechanisms. The speakers, both seasoned incident response and forensics experts, highlight the obscurity and inherent "self-healing" capabilities of DSC as key attributes making it an attractive, yet currently underutilized, tool for adversaries.

The core of their research demonstrates that once an attacker gains administrative privileges on a target system, DSC can be leveraged to continuously enforce a malicious configuration. This includes ensuring the presence and execution of malware, or the persistence of unauthorized user accounts, even after remediation attempts. Kazanciyan and Hastings introduce the DSCompromise framework, a set of PowerShell scripts designed to simplify the weaponization of DSC for red teams, making an otherwise complex process accessible. Critically, their work also provides blue teams with essential knowledge and practical techniques to detect and mitigate such advanced persistence methods, aiming to proactively address a threat before it becomes widespread in the wild.

This talk is significant because it sheds light on an emerging threat vector that exploits trusted system components rather than zero-day vulnerabilities. By demonstrating both the offensive and defensive aspects of DSC abuse, Kazanciyan and Hastings empower security practitioners to anticipate and defend against sophisticated attacks that exploit the very tools designed for system stability and management. Their proactive disclosure serves as a crucial step in narrowing the gap between attacker innovation and defender awareness.

Background

▶ Watch: Introduction: What is Desired State Configuration (DSC)? (0:00)

Desired State Configuration (DSC) is a configuration management platform introduced by Microsoft with PowerShell 4 as part of the Windows Management Framework 4.0 (WMF 4.0). It's installed by default on Windows 8.1 and Server 2012 R2 and later operating systems. At its core, DSC is designed to enforce a specific configuration state on a system over time. Unlike traditional management tools such as SCCM or Group Policy, DSC does not inherently require Active Directory, offering a more flexible and decoupled approach to system configuration. Many in the DevOps community liken it to "Puppet or Chef for Windows," though the speakers clarify that DSC primarily handles the configuration layer, not the full stack management and tooling of those broader solutions. In fact, Microsoft has released open-source components to enable interoperability between DSC and tools like Chef and Puppet.

The capabilities of DSC are extensive and, from an attacker's perspective, eerily similar to those of a robust command and control (C2) framework or a fully featured Remote Access Trojan (RAT). Out-of-the-box, DSC can download and create files, execute processes and scripts, create users and assign group memberships, control services, modify registry keys, and install software. This broad administrative power, coupled with its native integration into Windows, sparked the speakers' research into its potential for nefarious use.

The problem DSC inadvertently creates for defenders is its ability to act as a self-fixing backdoor. DSC clients are designed to continuously monitor their configuration for "drift" – any deviation from the enforced desired state. If drift is detected, the system automatically corrects itself, reverting to the specified configuration. This "consistency checker" mechanism means that if an attacker configures DSC to maintain a malicious file or user, and a defender removes it, DSC will automatically re-establish the malicious state on a predefined interval (e.g., every 15 minutes). This automatic reinfection, combined with DSC's relative obscurity and lack of enumeration by common security tools like Sysinternals Autoruns, makes it a potent and persistent mechanism for post-compromise activity. The speakers emphasize that their research does not identify zero-day vulnerabilities or privilege escalation flaws; rather, it focuses on the abuse of legitimate functionality in the post-compromise phase where an attacker already possesses administrative rights.

Key Findings

▶ Watch: Introducing the DSCompromise Framework for weaponizing DSC. (8:00)

The central discovery of this research is the potent and underappreciated potential of Desired State Configuration (DSC) as a post-compromise persistence and evasion mechanism. Ryan Kazanciyan and Matt Hastings identified several key findings that highlight why DSC is a compelling tool for attackers and a critical blind spot for many defenders:

  1. Built-in Persistence with Self-Healing Capabilities: DSC's core function is to continuously enforce a desired state. This means that if an attacker configures a system with a malicious payload (e.g., a backdoor executable, an unauthorized user account), DSC's consistency checker will automatically detect any deviation from this state (e.g., deletion of the file, removal of the user) and reapply the malicious configuration. This automatic reinfection capability is a significant differentiator from many other persistence methods, making remediation particularly challenging if the underlying DSC configuration is not addressed.
  2. Obscurity and Evasion: Despite being a powerful, built-in Windows component since PowerShell 4, DSC is relatively obscure among both administrators and security practitioners. The speakers noted that existing security tools, such as the Sysinternals Autoruns utility, do not enumerate DSC configurations, allowing malicious DSC implants to operate below the radar of common forensic analysis techniques. This obscurity provides a significant advantage for attackers seeking to maintain covert presence.
  3. Flexibility in Malicious Actions: DSC offers a wide array of capabilities natively, including file creation, process execution, user and group management, service control, and registry modification. This flexibility allows attackers to implement diverse persistence strategies, from dropping and running custom malware to maintaining a persistent local administrator account. The configuration definition, stored in a Managed Object Format (MOF) file, can embed binary payloads or script commands, offering extensive control.
  4. Simplified Weaponization with DSCompromise: Recognizing the inherent complexity and "brittleness" of manually setting up DSC for malicious purposes, the speakers developed the DSCompromise framework. This set of PowerShell scripts streamlines the entire process, from setting up a malicious DSC pull server to generating and deploying payloads on victim machines. This framework significantly lowers the bar for red teams to adopt DSC abuse, underscoring the immediate need for defensive awareness.
  5. Not a Vulnerability, but Abuse of Functionality: The research explicitly states that DSC itself is not intrinsically vulnerable, nor does it present a zero-day exploit or a privilege escalation vector. Instead, it demonstrates the abuse of legitimate administrative functionality for post-compromise persistence. This distinction is crucial, as it highlights the challenge of defending against attacks that leverage trusted system components rather than exploiting software flaws.
  6. Proactive Disclosure: A key finding and contribution of this talk is the proactive disclosure of both the attack methodology and the corresponding detection techniques. The speakers emphasized that they had not observed DSC being used in the wild at the time of their presentation, aiming to provide defenders with a head start before adversaries widely adopt this technique.

Technical Deep Dive

▶ Watch: Demo: Persisting unauthorized local administrator accounts. (21:00)

The technical implementation of DSC abuse, as demonstrated by the speakers, revolves around understanding DSC's operational workflow and leveraging its pull mode for remote control. DSC's workflow is typically broken into three stages: author, stage, and implement. In the author stage, a configuration is created using PowerShell, defining the desired state. This configuration is then compiled into a Managed Object Format (MOF) file. The stage involves hosting this MOF file, and implementation is where the client system ingests and applies the configuration.

For offensive purposes, the pull mode is preferred over push mode. In pull mode, the victim system (client) actively retrieves its configuration from a remote pull server over HTTP or HTTPS, much like a traditional C2 server. This negates the need for a direct route from the attacker's server to internal victim hosts, making it more flexible for external C2 operations. The client then consumes and implements the configuration, entering a continuous cycle where it periodically checks for configuration drift and automatically corrects itself if deviations are found.

The DSCompromise framework simplifies this process, consisting of four PowerShell scripts designed for different stages:

  1. Configuring the DSC Pull Server: The Configure-Server.ps1 script automates the setup of a DSC pull server. This involves installing the necessary DSC service and PowerShell modules. The script initializes the server, specifying ports for compliance reporting and configuration retrieval (defaulting to standard HTTP/HTTPS ports). The server then hosts the malicious MOF files and their corresponding checksums.
  2. Creating Malicious Payloads: The Create-Payload.ps1 script is used to generate the malicious configuration MOF files. For persisting malware, an executable (e.g., evil.exe) is copied to the pull server. The script then embeds this binary as a byte array directly into the PowerShell configuration that will be compiled into the MOF. This MOF specifies the destination path on the victim, the arguments for execution, and ensures the file's presence and process's running state. For user persistence, a separate script Create-User.ps1 takes a username, password (stored in cleartext in the MOF for simplicity, though certificates could be used for encryption), and an optional group (defaulting to "Administrators") to create and persist a local admin account. Both scripts generate a unique GUID for the configuration and place the MOF and its checksum file in the correct directory structure for the pull server.
  3. Infecting Victims: The Configure-Victim.ps1 script is executed on the target system (requiring local administrative rights). This script performs several critical actions:
  • It ensures the Windows Remote Management (WinRM) service is running, as it's a prerequisite for DSC.
  • It temporarily drops a configuration MOF file (pullconfig.mof) to disk, which contains instructions for the Local Configuration Manager (LCM) on how to connect to the remote pull server.
  • It configures the LCM with parameters such as the pull server's IP address/URL, the configuration GUID to retrieve, the ConfigurationModeFrequencyMins (defaulting to 15 minutes for consistency checks), and sets ConfigurationMode to ApplyAndAutoCorrect to ensure active enforcement. It also sets RefreshMode to Pull.
  • Once configured, the victim automatically downloads the specified MOF, drops the embedded malware (if applicable) to disk, executes it, and ensures its continuous presence.

The LCM settings are crucial. AllowModuleOverwrite enables dynamic updates, allowing the attacker to replace the payload associated with a GUID without changing the GUID itself. The 15-minute ConfigurationModeFrequencyMins dictates how often the system checks for drift, and ApplyAndAutoCorrect ensures the desired state is enforced, not just logged. The speakers note that the payload will execute every 15 minutes, which means attackers would need to implement logic within their malware to prevent continuous re-execution if they're not careful.

The MOF files, which are the core of DSC configurations, are essentially compiled PowerShell configurations and follow a standard format. The metaconfig.mof file on the client stores critical information about the pull server URI and refresh intervals. This technical architecture allows for a highly persistent and resilient backdoor, as the system itself is configured to self-heal back to the compromised state.

Demo / Proof of Concept

▶ Watch: Blue Team: Detecting DSC use via network and disk evidence. (24:00)

The talk featured two primary demonstrations of the DSCompromise framework in action, showcasing its ability to persist malware and unauthorized user accounts, complete with the self-healing capability of Desired State Configuration (DSC). Both demos followed a similar setup: a C2 server (attacker) on the right and a victim machine on the left.

Scenario 1: Persisting Malware

The first demo illustrated how to ensure a malicious file remains on disk and continually runs, even after remediation attempts.

  1. Payload Creation: On the C2 server, the Create-Payload.ps1 script was used. The speakers chose netcat64.exe as their malicious file, specifying its path on the server, the desired destination path on the victim (e.g., C:\Windows\System32\nc.exe), and arguments to establish a reverse shell back to the C2 server. The script generated a unique GUID for this configuration and created the necessary MOF and checksum files.
  2. Victim Infection: On the victim machine, after ensuring administrative access, the Configure-Victim.ps1 script was executed, providing the C2 server's IP address and the generated configuration GUID. This configured the victim's Local Configuration Manager (LCM) to pull the malicious configuration.
  3. Initial Compromise: Almost instantaneously, a command shell (via Netcat) connected back to the attacker's listening Netcat instance on the C2 server, demonstrating successful malware deployment and execution.
  4. Automatic Re-infection: To demonstrate the persistence, the speakers manually simulated a blue team remediation. They deleted nc.exe from the victim's System32 directory and terminated the running Netcat process. They then manually triggered the DSC consistency checker (which normally runs every 15 minutes). Within moments, the victim re-established the reverse shell, showing that DSC had detected the drift, recreated nc.exe, and re-executed it.
  5. Dynamic Update: The speakers also discussed the capability to update the malware associated with the same GUID on the pull server. This means if the initial malware is burned (detected by antivirus), the attacker can replace it with a new variant, and the victim will automatically download and execute the new payload on its next check-in, maintaining persistence with updated tooling.

Scenario 2: Persisting an Unauthorized Account

The second demo focused on maintaining an unauthorized local administrator account on a system.

  1. User Creation Payload: On the C2 server, the Create-User.ps1 script was used. This script took a username (e.g., "eviluser") and a password (noted to be stored in cleartext in the MOF for simplicity) and automatically configured the user to be a member of the "Administrators" group. Again, a unique GUID, MOF, and checksum file were generated.
  2. Victim Infection: Similar to the malware demo, the Configure-Victim.ps1 script was run on the victim with the C2 server's IP and the user configuration GUID.
  3. Account Creation: After a brief delay, the "eviluser" account was successfully created on the victim system and added to the local "Administrators" group, as verified by net user commands.
  4. Automatic Re-creation/Re-promotion: The remediation attempt involved deleting the "eviluser" account from the victim. Upon manually triggering the DSC consistency check, the "eviluser" account was automatically re-created and re-added to the "Administrators" group. The speakers also confirmed that if the user were merely demoted from the admin group, DSC would detect this drift and automatically re-promote them.

These demos powerfully illustrated the "desired state: compromised" concept, highlighting the resilience and stealth of DSC-based persistence against typical manual cleanup efforts.

Defensive Implications

▶ Watch: Cleanup, future of DSC, and DSCompromise framework plans. (32:00)

Detecting and mitigating Desired State Configuration (DSC) abuse requires a multi-faceted approach, focusing on network, endpoint, and logging artifacts. Given DSC's legitimate purpose, a baseline understanding of its normal (or lack thereof) usage in an environment is crucial. As the speakers noted, legitimate DSC usage is still relatively uncommon, making its presence or activity potentially suspicious.

Network-Based Detection

  • URI Monitoring: Organizations should monitor network egress for requests to URIs containing psdscpullserver.svc. This is the specific URI scheme used by DSC clients in pull mode to retrieve configurations. Unless there's a legitimate, documented external DSC pull server in use, such requests are highly indicative of malicious activity. These requests will typically include a GUID, representing the configuration ID.
  • Protocol Analysis: While DSC can use HTTP or HTTPS, monitoring for unusual outbound HTTP/HTTPS connections to unknown or suspicious IP addresses or domains on the standard DSC ports (or non-standard ones if configured by an attacker) can be an indicator.

Endpoint-Based Detection (On Disk)

  • Configuration Directory Monitoring: The primary location for DSC configuration files is C:\Windows\System32\Configuration. The presence of any MOF files in this directory (e.g., current.mof, backup.mof, pending.mof, metaconfig.mof) on systems not legitimately managed by DSC is a strong indicator of abuse.
  • metaconfig.mof Analysis: This specific MOF file contains crucial details about how the Local Configuration Manager (LCM) is configured, including the URI of the pull server and the refresh interval. Inspecting this file will directly reveal the attacker's C2 server address and the active configuration GUID.
  • pullrun.log: While less detailed, this plain text file in the configuration directory records each time a pull operation occurs. Its presence and entries can confirm DSC activity.
  • Temporary Files: During the initial configuration, a temporary file named pullconfig.mof is dropped. While often deleted, monitoring for its creation can be an early indicator.
  • Scheduled Tasks: DSC creates scheduled tasks for the consistency check and restart boot check. These tasks will have "Desired State Configuration" in their path or name. The creation or modification of such tasks on unmanaged systems is highly suspicious.
  • Malware Presence: If DSC is used to persist malware, monitoring for the creation of new executables or scripts in unusual locations (e.g., C:\Windows\Temp\<random_number>\localhost.mof or the specified malware drop path) is essential.

Event Log Monitoring

  • DSC Operational Event Log: This is a rich source of evidence. It explicitly logs events related to DSC configuration changes, including:
  • User SIDs attempting to send or apply configurations.
  • The source computer (local or remote) initiating the configuration.
  • Events indicating the system is pulling a configuration from a specific IP address or URL, along with the configuration GUID.
  • Monitoring these event IDs for unexpected server addresses or configuration IDs can provide immediate alerts.
  • Task Scheduler Log: Events related to the registration and updates of the "DSC Consistency" task are logged here. Unexpected entries can signal DSC setup.

PowerShell-Based Endpoint Analysis

  • Get-DscConfiguration: This PowerShell cmdlet returns the currently enforced configuration. If malware is embedded, this output will show the byte array of the malicious binary or the script commands being executed, appearing highly anomalous. For user persistence, it will display the configured username, group membership, and password policy settings.
  • Get-DscLocalConfigurationManager: This cmdlet provides details about the LCM's configuration, including whether it's in pull or push mode, the last configuration ID retrieved, and refresh frequencies. While it doesn't directly show the pull server's URL, its output confirming pull mode configuration is a strong indicator to then inspect metaconfig.mof for the server address.
  • Script Block Logging: With enhanced PowerShell logging, the execution of the Configure-Victim.ps1 script and the underlying DSC cmdlets would be captured, providing detailed forensic artifacts.

Cleanup and Remediation

To completely remove DSC-based persistence and prevent re-infection, defenders must:

  1. Delete MOF Files: Go to C:\Windows\System32\Configuration and delete all MOF files within this directory. This effectively removes the persistent state that DSC enforces.
  2. Remove Scheduled Tasks: Delete the "DSC Consistency" and "restart boot check" scheduled tasks related to DSC.
  3. Remediate Payloads: Delete any malicious files dropped by DSC and remove any unauthorized user accounts.

By understanding these defensive implications and implementing robust monitoring and analysis strategies, blue teams can effectively detect and disrupt DSC-based attacks, preventing adversaries from establishing resilient persistence on critical systems.

Key Takeaways

  • DSC is a Powerful Persistence Mechanism: Desired State Configuration (DSC), a built-in Windows feature since PowerShell 4, can be weaponized for highly resilient post-compromise persistence, offering capabilities akin to a full-featured backdoor.
  • Automatic Re-infection is a Core Threat: DSC's "consistency checker" automatically detects and corrects configuration drift, meaning it will re-establish malicious files or user accounts if they are removed, making traditional remediation efforts ineffective unless the underlying DSC configuration is addressed.
  • Obscurity Aids Evasion: DSC is not widely known or monitored by many security tools, allowing it to operate covertly and evade detection from common forensic utilities like Sysinternals Autoruns.
  • The DSCompromise Framework Simplifies Attacks: The open-source DSCompromise PowerShell framework significantly lowers the bar for attackers to leverage DSC, streamlining the setup of pull servers and the creation/deployment of malicious configurations.
  • Detection Relies on Specific Artifacts: Defenders can detect DSC abuse by monitoring for specific network requests (psdscpullserver.svc), unique file paths (C:\Windows\System32\Configuration\*.mof), distinct event log entries (DSC Operational log, Task Scheduler log), and PowerShell cmdlet outputs (Get-DscConfiguration, Get-DscLocalConfigurationManager).
  • Complete Remediation Requires MOF File Deletion: To truly clean a system and prevent re-infection, defenders must delete all MOF files in C:\Windows\System32\Configuration and remove associated scheduled tasks, in addition to cleaning any dropped payloads.

About the Speaker(s)

Ryan Kazanciyan is the Chief Security Architect for Tanium. With over 12 years of experience in incident response, forensics, and penetration testing, he brings a wealth of practical knowledge to the security domain. Prior to his role at Tanium, Ryan spent six years at Mandiant, primarily focusing on incident response work. He is also a contributing author to "Incident Response in Computer Forensics," with the third edition released a year prior to this talk.

Matt Hastings shares a very similar professional background and experience to Ryan Kazanciyan, specializing in incident response and security. While not a published author, his deep understanding of offensive and defensive security techniques is evident in the detailed research presented in the talk.

Reviews

→ Top-rated talks at BruCON 0x07

All talks from BruCON 0x07