Spooky authentication at a distance

Tamas Jos (Principal Security Consultant · SEC Consult)

TROOPERS23 · Day 1 · Attack & Research · Attack & Research

Overview

In his TROOPERS talk, "Spooky Authentication at a Distance," Tamas Jos, a Principal Security Consultant at SEC Consult and a member of the "Porchetta Industries" hacking alliance, unveiled a novel post-exploitation technique designed to remotely perform authentications over major Windows protocols. The title itself is a playful nod to Einstein's concept of "spooky action at a distance," aptly describing the remote, almost magical, impersonation capabilities of the method. This research, primarily conducted during his time with porchetta Industries, offers a significant advancement in offensive security.

Watch on YouTube · Slides

Visual summary for Spooky authentication at a distance by Tamas Jos
Visual summary for Spooky authentication at a distance by Tamas Jos

Key moments

  1. 3:45 Novel remote authentication post-exploitation technique
  2. 24:00 Introduction to Security Support Provider Interface (SSPI)
  3. 29:45 How to obtain the SSPI session key
  4. 32:00 Remote SSPI proxy: the core attack concept
  5. 38:00 Pre-recorded demo: SMB and LDAP authentication
  6. 48:00 Extending SSPI proxy with LSA Relay X
  7. 52:00 Live demo: Raspberry Pi auto-pawning a domain
  8. 59:30 Discussion on detecting SSPI proxy activity

Spooky Authentication at a Distance

Speakers: Tamas Jos, Principal Security Consultant, SEC Consult

Conference: TROOPERS

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

Overview

In his TROOPERS talk, "Spooky Authentication at a Distance," Tamas Jos, a Principal Security Consultant at SEC Consult and a member of the "Porchetta Industries" hacking alliance, unveiled a novel post-exploitation technique designed to remotely perform authentications over major Windows protocols. The title itself is a playful nod to Einstein's concept of "spooky action at a distance," aptly describing the remote, almost magical, impersonation capabilities of the method. This research, primarily conducted during his time with porchetta Industries, offers a significant advancement in offensive security.

The core of Jos's presentation revolves around leveraging the Security Support Provider Interface (SSPI), a set of Windows APIs, to proxy authentication requests from an attacker's machine through a compromised victim workstation. Crucially, this technique allows an attacker to authenticate to any server within the victim's domain without requiring elevated privileges on the victim machine, prior domain information, or the need to push additional code after the initial agent deployment. The primary benefit is a drastically reduced detection surface, as the activity largely mimics legitimate Windows authentication flows, with only network traffic monitoring potentially revealing the operation.

The talk delves into the intricacies of Windows authentication protocols, the inner workings of SSPI, and the innovative methods Jos devised to extract critical session information—specifically session keys and initialization vectors (IVs)—that SSPI is designed to keep secret. By "yoinking" these cryptographic contexts, an attacker can effectively impersonate a domain user remotely, opening doors to further exploitation like domain enumeration and Kerberoasting, all initiated from a distant attacker machine. This method represents a sophisticated approach to maintaining persistence and expanding access within a compromised network.

Background

▶ Watch: Novel remote authentication post-exploitation technique (3:45)

Understanding the "Spooky Authentication at a Distance" technique requires a foundational grasp of Windows authentication protocols and the underlying Security Support Provider Interface (SSPI). Tamas Jos begins by deconstructing common misconceptions about authentication, emphasizing that modern protocols do more than just verify credentials; they establish a shared secret that is subsequently used to encrypt all further communication. This distinction is crucial, as post-authentication encryption often operates independently of SSL/TLS, relying instead on keys derived during the authentication handshake.

Jos illustrates this with a generic protocol initialization flow: a client and server negotiate authentication methods, perform a multi-step challenge-response process (e.g., NTLM), and upon successful authentication, both parties possess a shared secret. Subsequent application-level messages are then wrapped and encrypted using this secret before being sent over the wire. The server decrypts these messages using its derived secret, processes the plaintext, and replies similarly. This wrapping and unwrapping process is a key concept throughout the talk.

LDAP serves as a primary example, showcasing its evolution in supporting various authentication methods. Initially, simple plaintext username/password authentication was prevalent. This was followed by Sicily, a raw NTLM implementation, and later SASL (Simple Authentication and Security Layer), which acts as a protocol selector for more robust methods like SPNEGO (Simple and Protected GSSAPI Negotiation Mechanism). SPNEGO, primarily a Microsoft implementation, further negotiates between NTLM and Kerberos. Jos highlights the complexity, particularly in mutual authentication scenarios where session keys and initialization vectors are exchanged. A critical observation for LDAP is that while NTLM itself provides encryption capabilities (RC4), explicit server configuration is often required for LDAP traffic to be encrypted after authentication, especially when not using LDAPS (LDAP over SSL/TLS).

SMB protocols, however, diverge significantly. While they also establish a shared secret during authentication, the encryption and decryption context is handled by the SMB protocol itself, rather than relying on the authentication protocol's (Kerberos or NTLM) native encryption. SMB clients "yoink" the shared secret from the authentication context and build their own encryption/decryption methods. This distinction becomes vital when an attacker aims to fully control the communication channel.

At the heart of Windows authentication lies SSPI. This set of Windows APIs provides a standardized way for applications to perform authentication without directly handling sensitive credentials. The analogy of a smart card is used: SSPI holds the "key" (user credentials or derived secrets) and can perform cryptographic operations (like authentication steps) upon request, but it does not release the raw key itself. This prevents applications from gaining direct access to sensitive material like plaintext passwords or NTLM hashes. SSPI supports a wide array of authentication packages, including Kerberos, NTLM, CredSSP, and SPNEGO.

The fundamental SSPI API calls involved are:

  • AcquireCredentialsHandle: Initiates an authentication context.
  • InitializeSecurityContext: Performed repeatedly to exchange authentication data between client and server until authentication is complete.
  • EncryptMessage and DecryptMessage: Used to encrypt and decrypt application data using the established authentication context.

While SSPI provides these functions, a significant challenge arises for custom client implementations, especially those needing to handle SMB's self-managed encryption or complex Kerberos mutual authentication. To fully control the post-authentication communication, an attacker needs not just the ability to proxy SSPI calls, but to extract the cryptographic context—specifically the session key and, in certain Kerberos scenarios, the initialization vector (IV)—from the SSPI context. This is where Jos's novel findings come into play, addressing the problem of SSPI's designed secrecy.

Key Findings

▶ Watch: How to obtain the SSPI session key (29:45)

Tamas Jos's talk unveils several critical findings that collectively enable the "Spooky Authentication at a Distance" technique:

  1. Discovery of QueryContextAttributes for Session Key Extraction: Jos identified and leveraged the QueryContextAttributes SSPI function to extract the session key from an established authentication context. While documented, this specific functionality for session key retrieval (using the SECPKG_ATTR_SESSION_KEY flag) was obscure and difficult to locate in Microsoft's extensive documentation, eventually being found through a Rust implementation. This ability to "nicely request" the session key from SSPI is fundamental, as SSPI is explicitly designed not to release sensitive cryptographic material.
  1. Novel Technique for Initialization Vector (IV) Extraction in Mutual Kerberos Authentication: A significant hurdle for mutual Kerberos authentication was the initialization vector (IV). In non-mutual Kerberos, the IV is included in the ticket. However, in mutual authentication, the IV is sent encrypted with a key that SSPI/LSASS does not release to the user. Jos's innovative solution involves invoking EncryptMessage with arbitrary "gibberish" data. The resulting wrap token contains the IV in plaintext (or public form), as it needs to be known by the receiving party for decryption. By unwrapping this token, the attacker can successfully extract the IV, thus completing the necessary cryptographic context for mutual Kerberos.
  1. Development of a Remote SSPI Proxy Agent: The culmination of these findings is the creation of a custom SSPI proxy agent. This agent, deployed as a single binary on a victim's Windows machine, establishes an RPC wrapper for the core SSPI functions. It allows an attacker, from a remote machine, to trigger SSPI calls on the victim's machine, effectively creating ad hoc authentication contexts that leverage the victim's existing credentials and privileges.
  1. Enabling Remote Impersonation without Credentials or Elevated Privileges: By proxying SSPI calls and extracting the full cryptographic context (session key and IV), the attacker can develop custom clients (e.g., SMB, LDAP, RDP clients) on their own machine. These clients, when instructed, will utilize the remote SSPI proxy to perform authentication as the victim user to any server within the corporate domain. This is achieved without the attacker knowing the victim's password, without requiring administrative privileges on the victim machine, and without deploying additional code beyond the initial agent.
  1. "Yoinking" the Encryption/Decryption Context for Efficiency: Jos's technique not only proxies authentication but also enables the attacker to transfer the entire encryption/decryption context (session key + IV) from the remote victim machine to their own attacking machine. This allows subsequent communication for that specific connection to be handled directly by the attacker's client, significantly reducing network bandwidth and the number of RPC calls to the victim for each message. The alternative "wrong way" would require three extra RPC calls per message for encryption/decryption, making it highly inefficient.

These findings represent a sophisticated bypass of SSPI's security mechanisms, transforming a local Windows authentication service into a powerful remote exploitation primitive.

Technical Deep Dive

▶ Watch: Pre-recorded demo: SMB and LDAP authentication (38:00)

The "Spooky Authentication at a Distance" technique hinges on a sophisticated architecture that bridges the attacker's remote machine with the victim's domain-enrolled Windows workstation. The core components are the SSPI Proxy Agent and a Socks Proxy, both running on the victim machine, orchestrated by the attacker's custom client-side tools.

Architecture Breakdown:

  1. Attacker Machine: Hosts custom client implementations (e.g., Python-based SMB, LDAP, RDP clients) that are designed to interface with the remote SSPI proxy.
  2. Victim Machine: A domain-enrolled Windows workstation.
  • SSPI Proxy Agent: A single, custom binary dropped onto the victim. This agent exposes an RPC wrapper around the critical SSPI API calls: AcquireCredentialsHandle, InitializeSecurityContext, QueryContextAttributes, EncryptMessage, and DecryptMessage.
  • Socks Proxy: Also part of the agent, this provides a network tunnel for the attacker's traffic.

The Attack Workflow (Simplified):

  1. Initial Compromise: The attacker gains initial access to the victim machine, typically by having the victim execute the SSPI Proxy Agent (e.g., via a phishing email, drive-by download, or physical access like the Raspberry Pi demo). The agent runs with the victim user's privileges.
  1. Network Tunnel Establishment: The attacker's client (e.g., an SMB client) on their remote machine initiates a connection to a target server within the victim's domain (e.g., a Domain Controller). This TCP connection is routed through the Socks Proxy on the victim machine. From the target server's perspective, the connection originates from the victim.
  1. Authentication Proxying:
  • When the attacker's client needs to authenticate, it doesn't send credentials directly. Instead, it makes an RPC call to the SSPI Proxy Agent on the victim.
  • The SSPI Proxy Agent then invokes AcquireCredentialsHandle on the victim's local LSASS (Local Security Authority Subsystem Service), requesting an authentication context for the currently logged-in user.
  • The subsequent challenge-response steps of the authentication protocol (e.g., NTLM negotiation, Kerberos ticket exchange) are handled by repeated calls to InitializeSecurityContext on the victim. The raw authentication data (negotiate, challenge, authenticate tokens) is ferried back and forth between the target server, the victim's SSPI, and the attacker's client via the Socks and RPC proxies.
  1. Cryptographic Context Extraction:
  • Upon successful authentication, a shared secret (the session key) is established within the victim's SSPI context. The attacker's client then makes an RPC call to the SSPI Proxy Agent to invoke QueryContextAttributes (specifically with SECPKG_ATTR_SESSION_KEY). The agent retrieves the session key from LSASS and sends it back to the attacker.
  • For mutual Kerberos authentication, the Initialization Vector (IV) is also needed. As LSASS encrypts and does not release the IV directly, Jos employs an ingenious trick: the attacker's client sends an RPC request to the agent to invoke EncryptMessage with some arbitrary data. The resulting wrap token is then parsed by the attacker's client to extract the IV, which is publicly available within the token as it's required for decryption on the other side.
  1. "Yoinking" the Context and Efficient Communication:
  • With both the session key and the IV (if applicable) extracted, the attacker's client now possesses the complete cryptographic context. This is the "right way" to handle post-authentication communication.
  • Instead of constantly making RPC calls to the victim's EncryptMessage and DecryptMessage functions for every single application message (the "wrong way," which would be highly inefficient due to three extra RPC calls per message), the attacker's client can now perform all encryption and decryption operations locally. This significantly reduces network overhead and interaction with the victim agent, making the attack stealthier and more scalable.
  • The attacker's client can then proceed to interact with the target server (e.g., listing SMB shares, querying LDAP, initiating RDP sessions) as if it were the victim user, without requiring further authentication steps or direct access to the victim's credentials.

Implementation Details:

  • Language & Framework: Jos's implementations are primarily in Python 3 using the asyncio framework.
  • Libraries:
  • wsnet: The Python library that implements the client-side SSPI proxy logic.
  • asyauth: The underlying authentication library used by Jos's tools for various protocol implementations.
  • Agent Status: The agent is custom-built and will be open-sourced under an MIT license after further conference obligations. The Python libraries are already mostly open-source.

Future Extensions and Interoperability:

Jos highlights several avenues for future development:

  • LSA Relay X Integration: Ethical Chaos's LSA Relay X tool, which hooks low-level LSASS functions for NTLM relaying, could be extended to hook Kerberos and interface with this SSPI proxy technique. This would allow any Windows application running on the hooked machine to transparently leverage the SSPI proxy, removing the need for custom client implementations.
  • Windows Certificate Store Proxying: Extending the SSPI proxy functionality to Windows certificate store APIs would enable proxying of certificate-based authentication protocols like Kerberos PKINIT, Windows Hello, and Azure-related authentication, further broadening the attack surface.

This intricate technical design allows an attacker to effectively remote-control the authentication capabilities of a compromised workstation, turning it into a powerful pivot point within a domain.

Demo / Proof of Concept

▶ Watch: Extending SSPI proxy with LSA Relay X (48:00)

Tamas Jos presented two compelling demonstrations to illustrate the efficacy of his SSPI proxy technique: a pre-recorded video showcasing the core functionality with SMB and LDAP, and a live demonstration of a "Pawn All" Raspberry Pi device.

Pre-recorded Demo: Remote Authentication with SMB and LDAP/Kerberos

The first demo, presented via a pre-recorded video, set up a scenario with the attacker on the top screen and the victim (a domain-enrolled Windows machine) on the bottom screen, initially in the same network for simplicity, though the Socks proxy functionality allows remote operation.

  1. Victim Status: The whoami /all command on the victim machine confirmed that the user was a standard domain user without administrative privileges.
  2. Agent Deployment: The sspi_proxy_agent binary was executed on the victim machine. This agent provides both Socks proxying and SSPI proxying capabilities.
  3. SMB Authentication:
  • From the attacker's machine, a custom SMB client was launched. Crucially, this client was not provided with any user credentials (password or hash).
  • The SMB client was configured to connect to a Domain Controller (DC) via the victim's Socks proxy and leverage the victim's SSPI context for authentication.
  • The demo's debug logs visually traced the NTLM authentication flow: the attacker's client initiated the SMB connection, which was proxied to the victim. The victim's SSPI then handled the NTLM negotiate, challenge, and authenticate steps with the DC.
  • Upon successful authentication, the session key was explicitly fetched from the SSPI context on the victim and transferred to the attacker's client.
  • The attacker's client then proceeded to list shares on the DC and successfully downloaded the activities.log file from the DC, all while impersonating the victim user, without ever knowing the victim's password.
  1. LDAP/Kerberos Authentication:
  • Following the SMB demonstration, the attacker used a custom LDAP client to perform Kerberos authentication to the DC, again leveraging the victim's SSPI context.
  • This successfully enumerated kerberoastable users from the DC, demonstrating the ability to perform domain reconnaissance via the compromised host.
  • A whoami command, proxied through the victim, confirmed that the attacker was operating under the victim's domain identity.
  • Jos emphasized that the technique provides a "fully working" authentication context with "no limitations" for post-authentication actions, including potential Certify attacks.

Live Demo: Raspberry Pi "Pawn All" Tool

The second, live demonstration showcased a highly automated and practical application of the SSPI proxy: a Raspberry Pi-based "Pawn All" USB device.

  1. Device Setup: The device was a Raspberry Pi with USB OTG functionality, configured to emulate both a USB network device and a rubber ducky (USB keyboard emulator).
  2. Deployment: Jos plugged the USB device into an unlocked, domain-enrolled Windows laptop (his demo machine).
  3. Automated Execution:
  • The rubber ducky feature automatically executed the initial SSPI Proxy Agent on the laptop.
  • The USB network device was detected, and the laptop received an IP address from the Raspberry Pi's internal DHCP server, establishing a network connection back to the Pi.
  • The SSPI Proxy Agent on the laptop automatically connected back to a C2 server running on the Raspberry Pi.
  1. Automated Domain Exploitation: The Raspberry Pi immediately began to:
  • Enumerate the domain, collecting Bloodhound-like data.
  • Perform Kerberoasting of the entire domain.
  • All these actions were initiated by the Pi, leveraging the victim's SSPI context without any further user interaction on the laptop.
  1. Octopone Web Interface: Jos connected to the Raspberry Pi's OctoPwn web interface (a custom penetration testing platform he developed) as an operator.
  • The interface displayed real-time data from the ongoing exploitation.
  • A "Credentials" tab showed a reference to the connected SSPI Proxy Agent, indicating the proxied user context.
  • With a single button press, Jos demonstrated Kerberoasting the entire domain, with the data being generated from a badblood script for realistic domain structures.
  • After a short delay for data processing, the jackdaw (Jos's Bloodhound implementation) tab displayed a graph showing paths to domain administrators, confirming successful and comprehensive domain enumeration.

This live demo powerfully illustrated the ease and effectiveness of the SSPI proxy for automated, generic domain compromise, highlighting its potential as a plug-and-play post-exploitation tool.

Defensive Implications

▶ Watch: Discussion on detecting SSPI proxy activity (59:30)

The "Spooky Authentication at a Distance" technique, while powerful for attackers, also presents clear defensive implications that organizations can leverage to detect and mitigate such threats.

  1. Network Traffic Monitoring:
  • Increased Bandwidth: The technique, especially in its less optimized form or when the Socks proxy is heavily utilized, generates higher network traffic from the victim workstation. Defenders should monitor for unusual spikes or sustained high bandwidth usage from individual endpoints, particularly towards internal domain services (DCs, file servers) that are not typically traffic-intensive for that user.
  • Unusual Destinations/Protocols: While the traffic originates from the legitimate user context, the destinations or protocols might be unusual for a given workstation or user. For instance, an endpoint typically used for browsing and email suddenly initiating numerous SMB or LDAP queries to multiple domain controllers could be suspicious.
  1. SSPI API Call Monitoring (Endpoint Detection & Response - EDR):
  • QueryContextAttributes for Session Key: The most direct and potentially deterministic detection method is to monitor for calls to the QueryContextAttributes API function, specifically when requesting the SECPKG_ATTR_SESSION_KEY attribute. As Jos noted, it's unclear how many legitimate applications routinely request the session key. Such calls from non-standard, unrecognized, or suspicious processes (like the sspi_proxy_agent binary) should be flagged as highly anomalous.
  • EncryptMessage with Unusual Context: While EncryptMessage is a legitimate SSPI call, its invocation with "gibberish" data specifically to extract the IV for mutual Kerberos might leave a detectable footprint. EDR solutions capable of deep API call tracing and parameter analysis could potentially identify this pattern.
  1. Process Monitoring and Application Whitelisting:
  • Agent Execution: The initial deployment requires the execution of the sspi_proxy_agent binary. Robust application whitelisting solutions (e.g., AppLocker, Windows Defender Application Control) can prevent the execution of unauthorized executables.
  • Parent Process Anomalies: Monitor for suspicious parent-child process relationships. If the sspi_proxy_agent is launched by an unusual parent process (e.g., a Microsoft Office application, a browser, or a script interpreter) or directly from a temporary directory, it could indicate compromise.
  1. User Behavior Analytics (UBA):
  • Anomalous Resource Access: Even though the authentication is legitimate, the actions performed by the proxied user might be out of character. For example, a marketing user suddenly performing extensive domain enumeration, attempting Kerberoasting, or accessing sensitive file shares they normally wouldn't, should trigger alerts.
  • Authentication Frequency/Volume: A user account showing an unusually high volume of authentication attempts or successful authentications to various services within a short period, especially if originating from a single workstation, could be indicative of the SSPI proxy in action.
  1. Physical Security:
  • The live demo with the Raspberry Pi USB device highlights the critical importance of physical security. Unlocked workstations are highly vulnerable to such "plug-and-pwn" devices. Implementing strong lock-screen policies, physical access controls, and USB device control policies (e.g., blocking unauthorized USB devices) can mitigate this vector.
  1. Principle of Least Privilege:
  • The technique leverages the victim's existing privileges. Enforcing the principle of least privilege ensures that even if an account is compromised, the attacker's lateral movement capabilities are limited by the user's restricted access.

By combining these defensive strategies, organizations can significantly enhance their ability to detect and respond to sophisticated post-exploitation techniques like "Spooky Authentication at a Distance."

Key Takeaways

  • Remote SSPI Proxying is Viable: The talk demonstrates a novel post-exploitation technique allowing remote authentication over major Windows protocols (LDAP, SMB, RDP) by proxying SSPI calls through a compromised workstation.
  • Session Keys and IVs Can Be Extracted: Critical cryptographic contexts, including the session key (via QueryContextAttributes) and the Initialization Vector for mutual Kerberos (via an EncryptMessage trick), can be extracted from SSPI, bypassing its intended secrecy.
  • Impersonation Without Credentials: Attackers can impersonate a domain user to any server in the domain without knowing the user's password, requiring elevated privileges, or pushing additional code beyond an initial agent.
  • Reduced Detection Surface: The technique significantly reduces the detection footprint by leveraging legitimate Windows authentication mechanisms, with primary detection opportunities lying in network traffic anomalies and specific SSPI API call monitoring.
  • Efficiency Through Context "Yoinking": Once the cryptographic context is extracted, subsequent communication can be handled directly by the attacker's client, vastly improving efficiency and reducing reliance on continuous remote SSPI calls.
  • High Automation Potential: The Raspberry Pi demo showcases the technique's potential for highly automated, "plug-and-pwn" domain exploitation, making it a powerful tool for initial access and lateral movement.

About the Speaker(s)

Tamas Jos is a Principal Security Consultant at SEC Consult, a well-known security firm operating primarily in German-speaking regions and parts of Asia, specializing in penetration testing, red teaming, and IT security consultancy services. Beyond his professional role, Jos leads a "double life" as a member of "Porchetta Industries," described as a freelance or free alliance of hackers with diverse skills.

Jos is a prolific open-source developer, with much of his research, including the work presented in this talk, stemming from his time with porchetta Industries. He is the creator of several security projects, most notably pypykatz. He also enjoys implementing and re-implementing various network protocols from scratch, focusing on authentication protocols. His open-source projects, built primarily in Python 3 using the asyncio framework, include re-implementations of Kerberos, LDAP, SMB, SSH, and RDP protocols. His deep understanding of these protocols and Windows' underlying authentication mechanisms was clearly evident throughout his technical presentation.

Reviews

Dr. Zero (Offensive Security Researcher) — MUST SEE

This is what offensive research is actually supposed to look like. Tamas Jos didn't just proxy SSPI; he weaponized the cryptographic context itself to bypass LSASS dumping altogether. It's a masterclass in protocol abuse that gives defenders a massive headache and gives operators a new standard for lateral movement.

Heather Calloway (CISO) — STRONG ACCEPT

This research exposes a major blind spot in how Windows handles authentication context, allowing attackers to hijack a session without local admin rights or password theft. It proves that a standard endpoint compromise can instantly become a silent, full-context domain pivot. I’d send this to my security engineering lead today to verify our EDR coverage against the specific API abuse shown here.

→ Top-rated talks at TROOPERS23

All talks from TROOPERS23