Skip to content

Commit e17def2

Browse files
ldapauth: Use specified domain in NTLM auth msg instead of target name
1 parent 89a8718 commit e17def2

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

ldapauth/ldap.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,9 @@ func bind(
243243

244244
tlsState, ok := conn.TLSConnectionState()
245245
if ok && !opts.DisableChannelBinding {
246-
bindRequest.Negotiator = ntlmNegotiatorWithChannelBinding(tlsState.PeerCertificates[0])
246+
bindRequest.Negotiator = ntlmNegotiatorWithChannelBinding(tlsState.PeerCertificates[0], creds.Domain)
247+
} else {
248+
bindRequest.Negotiator = ntlmNegotiatorForDomain(creds.Domain)
247249
}
248250

249251
_, err = conn.NTLMChallengeBind(bindRequest)

ldapauth/ntlm.go

+19-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ import (
1010
)
1111

1212
type ntlmNegotiator struct {
13-
cert *x509.Certificate
13+
cert *x509.Certificate
14+
overrideTargetName string
1415
}
1516

1617
var _ ldap.NTLMNegotiator = &ntlmNegotiator{}
1718

18-
func ntlmNegotiatorWithChannelBinding(cert *x509.Certificate) ldap.NTLMNegotiator {
19-
return &ntlmNegotiator{cert: cert}
19+
func ntlmNegotiatorWithChannelBinding(cert *x509.Certificate, domain string) ldap.NTLMNegotiator {
20+
return &ntlmNegotiator{cert: cert, overrideTargetName: domain}
21+
}
22+
23+
func ntlmNegotiatorForDomain(domain string) ldap.NTLMNegotiator {
24+
return &ntlmNegotiator{overrideTargetName: domain}
2025
}
2126

2227
func (n *ntlmNegotiator) Negotiate(domain string, worktation string) ([]byte, error) {
@@ -48,6 +53,17 @@ func (n *ntlmNegotiator) ChallengeResponse(challenge []byte, username string, ha
4853
cm.TargetInfo.List = cm.TargetInfo.List[:len(cm.TargetInfo.List)-1]
4954
}
5055

56+
// Authenticate with the domain name that was specified, not the domain that
57+
// the server advertises. This grants compatibility with the LDAP SOCKS
58+
// feature of ntlmrelayx.py which is sensitive to the exact domain name (DNS
59+
// vs NetBIOS name).
60+
if n.overrideTargetName != "" && n.overrideTargetName != "." {
61+
cm.TargetName, err = ntlm.CreateStringPayload(n.overrideTargetName)
62+
if err != nil {
63+
return nil, fmt.Errorf("override target name: create string payload: %w", err)
64+
}
65+
}
66+
5167
// add channel bindings
5268
cm.TargetInfo.AddAvPair(ntlm.MsvChannelBindings, ChannelBindingHash(n.cert))
5369
cm.TargetInfo.AddAvPair(ntlm.MsvAvEOL, nil)

0 commit comments

Comments
 (0)