ntlmcbt

package module
v0.0.0-...-21a2243 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 8 Imported by: 0

README

go-ntlm-cbt

A Go library that extends go-ntlmssp with Channel Binding Token (CBT) support for Extended Protection for Authentication (EPA).

Overview

When Extended Protection for Authentication (EPA) is enabled on Windows servers, NTLM authentication requires a Channel Binding Token (CBT) derived from the TLS server certificate. Without CBT, authentication fails with errors like "The token supplied to the function is invalid."

This library wraps go-ntlmssp and injects the MsvAvChannelBindings AV_PAIR into the NTLM AUTHENTICATE_MESSAGE, enabling authentication to EPA-protected servers.

Features

  • RFC 5929 Compliant: Implements tls-server-end-point channel binding.
  • Drop-in Enhancement: Works alongside go-ntlmssp without forking it.
  • Zero Additional Dependencies: Only depends on go-ntlmssp and the Go standard library.

Installation

go get github.com/smnsjas/go-ntlm-cbt

Usage

import (
    "crypto/tls"
    "crypto/x509"
    
    ntlmcbt "github.com/smnsjas/go-ntlm-cbt"
)

// After TLS handshake, get the server certificate
cert := tlsConn.ConnectionState().PeerCertificates[0]

// Compute channel bindings
cb := ntlmcbt.ComputeTLSServerEndpoint(cert)

// Create the negotiator
negotiator := ntlmcbt.NewNegotiator(cb)

// 1. Generate Negotiate Message (Type 1)
negotiateMsg, err := negotiator.Negotiate("DOMAIN", "WORKSTATION")
if err != nil {
    // handle error
}

// ... send negotiateMsg to server, receive challengeMsg ...

// 2. Generate Authenticate Message (Type 3)
authMsg, err := negotiator.ChallengeResponse(challengeMsg, "username", "password")
if err != nil {
    // handle error
}

Why Extended Protection Matters

Extended Protection for Authentication (EPA) defends against NTLM Relay Attacks (Credential Relaying).

In a typical relay attack, an attacker intercepts an NTLM handshake and forwards it to a target server. The server thinks it's talking to the legitimate client.

Channel Binding Tokens (CBT) prevent this by cryptographically binding the NTLM authentication to the underlying TLS connection.

  1. The client calculates a hash of the server's TLS certificate (the CBT).
  2. The client embeds this CBT inside the encrypted NTLM message.
  3. The server validates that the CBT in the NTLM message matches its own TLS certificate.

If an attacker relays the traffic over their own TLS connection, the CBTs won't match, and the server rejects the authentication.

How It Works

  1. Computes Channel Binding Token: Hashes the server's TLS certificate per RFC 5929.
  2. Constructs GSS Channel Bindings: Builds the RFC 2744 gss_channel_bindings_struct.
  3. Injects AV_PAIR: Adds MsvAvChannelBindings (AvId=0x000A) to the NTLM Type 3 message.
  4. Recomputes MIC: Updates the Message Integrity Code after modification.

License

MIT License - see LICENSE for details.

Acknowledgments

  • go-ntlmssp - The underlying NTLM implementation.
  • pyspnego - Reference implementation for channel bindings.
  • ntlmnego - Inspiration for the interposition pattern.

Documentation

Overview

Package ntlmcbt provides NTLM authentication with Channel Binding Token (CBT) support for Extended Protection for Authentication (EPA).

This package wraps go-ntlmssp and injects MsvAvChannelBindings into the NTLM AUTHENTICATE_MESSAGE, enabling authentication to EPA-protected servers.

Channel binding tokens are computed per RFC 5929 using the tls-server-end-point method, which hashes the server's TLS certificate.

Usage

After establishing a TLS connection, extract the server certificate and create a channel binding:

cert := tlsConn.ConnectionState().PeerCertificates[0]
cb := ntlmcbt.ComputeTLSServerEndpoint(cert)

Then use the Negotiator to perform NTLM authentication:

nego := &ntlmcbt.Negotiator{ChannelBindings: cb}
negotiateMsg, _ := nego.Negotiate("DOMAIN", "WORKSTATION")
// ... send negotiateMsg, receive challengeMsg ...
authMsg, _ := nego.ChallengeResponse(challengeMsg, "user", "password")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GSSChannelBindings

type GSSChannelBindings struct {
	// InitiatorAddrType is the address type of the initiator (typically 0/unspecified).
	InitiatorAddrType uint32
	// InitiatorAddress is the initiator's address (typically empty for TLS bindings).
	InitiatorAddress []byte
	// AcceptorAddrType is the address type of the acceptor (typically 0/unspecified).
	AcceptorAddrType uint32
	// AcceptorAddress is the acceptor's address (typically empty for TLS bindings).
	AcceptorAddress []byte
	// ApplicationData contains the channel binding data (e.g., "tls-server-end-point:<hash>").
	ApplicationData []byte
}

GSSChannelBindings represents the RFC 2744 gss_channel_bindings_struct. For TLS server endpoint channel bindings, only ApplicationData is populated.

func ComputeTLSServerEndpoint

func ComputeTLSServerEndpoint(cert *x509.Certificate) *GSSChannelBindings

ComputeTLSServerEndpoint creates channel bindings from a TLS server certificate using the tls-server-end-point method defined in RFC 5929.

The hash algorithm is determined by the certificate's signature algorithm:

  • MD5 or SHA-1 signatures → use SHA-256 (per RFC 5929 Section 4.1)
  • SHA-384 signatures → use SHA-384
  • SHA-512 signatures → use SHA-512
  • All others → use SHA-256

func (*GSSChannelBindings) MD5Hash

func (cb *GSSChannelBindings) MD5Hash() []byte

MD5Hash returns the MD5 hash of the packed channel bindings. This is the value used in NTLM's MsvAvChannelBindings AV_PAIR. Note: MD5 is mandated by the MS-NLMP specification for channel bindings.

func (*GSSChannelBindings) Pack

func (cb *GSSChannelBindings) Pack() []byte

Pack serializes the channel bindings to wire format (little-endian). This format is compatible with Windows SEC_CHANNEL_BINDINGS structure.

type Negotiator

type Negotiator struct {
	// ChannelBindings contains the computed channel binding token.
	// If nil, standard NTLM authentication is performed without CBT.
	ChannelBindings *GSSChannelBindings

	// DomainNeeded indicates whether the domain should be included in the response.
	// This is passed to go-ntlmssp's ProcessChallenge function.
	DomainNeeded bool
}

Negotiator implements NTLM authentication with optional channel binding support. It wraps go-ntlmssp and injects MsvAvChannelBindings when channel bindings are provided.

func NewNegotiator

func NewNegotiator(cb *GSSChannelBindings) *Negotiator

NewNegotiator creates a new Negotiator with the provided channel bindings. It defaults to DomainNeeded=true, which matches standard Windows behavior.

func (*Negotiator) ChallengeResponse

func (n *Negotiator) ChallengeResponse(challenge []byte, username, password string) ([]byte, error)

ChallengeResponse processes the server's CHALLENGE_MESSAGE (Type 2) and generates the AUTHENTICATE_MESSAGE (Type 3).

If channel bindings are configured, the MsvAvChannelBindings AV_PAIR is injected into the response before computing the final message.

func (*Negotiator) ChallengeResponseWithHash

func (n *Negotiator) ChallengeResponseWithHash(challenge []byte, username, hash string) ([]byte, error)

ChallengeResponseWithHash is like ChallengeResponse but uses a password hash instead of the plaintext password.

func (*Negotiator) Negotiate

func (n *Negotiator) Negotiate(domain, workstation string) ([]byte, error)

Negotiate generates the initial NTLM NEGOTIATE_MESSAGE (Type 1). This message is sent to the server to begin the NTLM handshake.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL