-
Notifications
You must be signed in to change notification settings - Fork 97
/
initiator.go
71 lines (60 loc) · 1.65 KB
/
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
package smb2
import (
"encoding/asn1"
"github.com/hirochachacha/go-smb2/internal/ntlm"
"github.com/hirochachacha/go-smb2/internal/spnego"
)
type Initiator interface {
oid() asn1.ObjectIdentifier
initSecContext() ([]byte, error) // GSS_Init_sec_context
acceptSecContext(sc []byte) ([]byte, error) // GSS_Accept_sec_context
sum(bs []byte) []byte // GSS_getMIC
sessionKey() []byte // QueryContextAttributes(ctx, SECPKG_ATTR_SESSION_KEY, &out)
}
// NTLMInitiator implements session-setup through NTLMv2.
// It doesn't support NTLMv1. You can use Hash instead of Password.
type NTLMInitiator struct {
User string
Password string
Hash []byte
Domain string
Workstation string
TargetSPN string
ntlm *ntlm.Client
seqNum uint32
}
func (i *NTLMInitiator) oid() asn1.ObjectIdentifier {
return spnego.NlmpOid
}
func (i *NTLMInitiator) initSecContext() ([]byte, error) {
i.ntlm = &ntlm.Client{
User: i.User,
Password: i.Password,
Hash: i.Hash,
Domain: i.Domain,
Workstation: i.Workstation,
TargetSPN: i.TargetSPN,
}
nmsg, err := i.ntlm.Negotiate()
if err != nil {
return nil, err
}
return nmsg, nil
}
func (i *NTLMInitiator) acceptSecContext(sc []byte) ([]byte, error) {
amsg, err := i.ntlm.Authenticate(sc)
if err != nil {
return nil, err
}
return amsg, nil
}
func (i *NTLMInitiator) sum(bs []byte) []byte {
mic, _ := i.ntlm.Session().Sum(bs, i.seqNum)
return mic
}
func (i *NTLMInitiator) sessionKey() []byte {
return i.ntlm.Session().SessionKey()
}
func (i *NTLMInitiator) infoMap() *ntlm.InfoMap {
return i.ntlm.Session().InfoMap()
}