Skip to content
Neutral Works
Go back

Practicing Windows SSPI in Go WebSocket Connections

Tech

Windows SSPI (Security Support Provider Interface) offers a standardized mechanism for handling authentication in Windows environments. While tools like cURL have long supported SSPI for seamless proxy authentication, integrating this functionality into custom applications requires additional effort.

As part of my recent self-study, I explored how to quickly test SSPI-based proxy-aware authentication using alexbrainman’s SSPI repository, specifically for WebSocket connections.

Let’s take a quick look at the process.

Credential Acquisition

This code snippet firstly retrieves the current Windows user’s credentials using SSPI, similar to cURL’s -U : option.

creds, err := negotiate.AcquireCurrentUserCredentials()

Security Context Creation

Creating a new client-side security context for authentication, using the provided credentialscreds and the proxy’s host, generating a negotiation token for secure communication.

secContext, token, err := negotiate.NewClientContext(creds, "HTTP/"+proxyURLParsed.Host)

Proxy Authentication Header

The negotiation token is base64-encoded and added to the request headers using the “Negotiate” authentication scheme.

headers := http.Header{}
headers.Add("Proxy-Authorization", "Negotiate "+base64.StdEncoding.EncodeToString(token))

Usage Example

This Go code snippet below establishes a WebSocket connection (wss://) to a target server while routing the traffic through an HTTP proxy. Key benefits include:

conn, err := wsconnect.Connect("wss://target.example.com", "http://my-proxy.com:8080")
if err != nil {
    log.Fatal(err)
}
defer conn.Close()

For more details, you can visit my GitHub repository go-proxy-aware-sspi, which wraps a simple, ready-to-use Go module for transparent Windows proxy authentication via SSPI, similar to cURL’s -U : feature.


Related: For another use of Go in enterprise network environments, see Reverse SOCKS5 Tunnels for Red Teaming and Adversary Emulation.


Share this post:

Previous Post
Continuous Purple Teaming with CI/CD, IaC, and AI
Next Post
Building your own shellcode stager with customised functions