@@ -10,13 +10,18 @@ import (
1010)
1111
1212type ntlmNegotiator struct {
13- cert * x509.Certificate
13+ cert * x509.Certificate
14+ overrideTargetName string
1415}
1516
1617var _ 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
2227func (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