forked from hirochachacha/go-smb2
-
Notifications
You must be signed in to change notification settings - Fork 4
/
ntlmssp_initiator.go
94 lines (83 loc) · 2.49 KB
/
ntlmssp_initiator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package smb2
import (
"encoding/asn1"
"errors"
"github.com/LeakIX/go-smb2/lib/spnego"
"github.com/LeakIX/ntlmssp"
)
// NTLMInitiator implements session-setup through NTLMv2.
type NTLMSSPInitiator struct {
NTLMSSPClient *ntlmssp.Client
seqNum uint32
ntlmInfoMap *NTLMSSPInfoMap
}
type NTLMSSPInfoMap struct {
NbComputerName string
NbDomainName string
DnsComputerName string
DnsDomainName string
DnsTreeName string
// Flags uint32
// Timestamp time.Time
// SingleHost
// TargetName string
// ChannelBindings
}
func (i *NTLMSSPInitiator) oid() asn1.ObjectIdentifier {
return spnego.NlmpOid
}
func (i *NTLMSSPInitiator) GetInfoMap() *NTLMSSPInfoMap {
return i.infoMap()
}
func (i *NTLMSSPInitiator) initSecContext() (_ []byte, err error) {
if err != nil {
return nil, err
}
nmsg, err := i.NTLMSSPClient.Authenticate(nil, nil)
if err != nil {
return nil, err
}
return nmsg, nil
}
func (i *NTLMSSPInitiator) acceptSecContext(sc []byte) ([]byte, error) {
amsg, err := i.NTLMSSPClient.Authenticate(sc, nil)
if err != nil {
return nil, err
}
i.ntlmInfoMap = &NTLMSSPInfoMap{
NbComputerName: "",
NbDomainName: "",
DnsComputerName: "",
DnsDomainName: "",
DnsTreeName: "",
}
if NbComputerName, found := i.NTLMSSPClient.SessionDetails().TargetInfo.GetString(ntlmssp.MsvAvNbComputerName); found {
i.ntlmInfoMap.NbComputerName = NbComputerName
}
if NbDomainName, found := i.NTLMSSPClient.SessionDetails().TargetInfo.GetString(ntlmssp.MsvAvNbDomainName); found {
i.ntlmInfoMap.NbDomainName = NbDomainName
}
if DnsComputerName, found := i.NTLMSSPClient.SessionDetails().TargetInfo.GetString(ntlmssp.MsvAvDNSComputerName); found {
i.ntlmInfoMap.DnsComputerName = DnsComputerName
}
if DnsDomainName, found := i.NTLMSSPClient.SessionDetails().TargetInfo.GetString(ntlmssp.MsvAvDNSDomainName); found {
i.ntlmInfoMap.DnsDomainName = DnsDomainName
}
if DnsTreeName, found := i.NTLMSSPClient.SessionDetails().TargetInfo.GetString(ntlmssp.MsvAvDNSTreeName); found {
i.ntlmInfoMap.DnsTreeName = DnsTreeName
}
if i.NTLMSSPClient.SecuritySession() == nil {
return nil, errors.New("failed to establish secure session")
}
return amsg, nil
}
func (i *NTLMSSPInitiator) sum(bs []byte) []byte {
mac, _ := i.NTLMSSPClient.SecuritySession().Mac(bs)
return mac
}
func (i *NTLMSSPInitiator) sessionKey() []byte {
return i.NTLMSSPClient.SessionDetails().ExportedSessionKey
}
func (i *NTLMSSPInitiator) infoMap() *NTLMSSPInfoMap {
return i.ntlmInfoMap
}