@@ -10,13 +10,18 @@ import (
10
10
)
11
11
12
12
type ntlmNegotiator struct {
13
- cert * x509.Certificate
13
+ cert * x509.Certificate
14
+ overrideTargetName string
14
15
}
15
16
16
17
var _ ldap.NTLMNegotiator = & ntlmNegotiator {}
17
18
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 }
20
25
}
21
26
22
27
func (n * ntlmNegotiator ) Negotiate (domain string , worktation string ) ([]byte , error ) {
@@ -48,6 +53,17 @@ func (n *ntlmNegotiator) ChallengeResponse(challenge []byte, username string, ha
48
53
cm .TargetInfo .List = cm .TargetInfo .List [:len (cm .TargetInfo .List )- 1 ]
49
54
}
50
55
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
+
51
67
// add channel bindings
52
68
cm .TargetInfo .AddAvPair (ntlm .MsvChannelBindings , ChannelBindingHash (n .cert ))
53
69
cm .TargetInfo .AddAvPair (ntlm .MsvAvEOL , nil )
0 commit comments