-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmsg_basic_setup1.go
196 lines (166 loc) · 5.13 KB
/
msg_basic_setup1.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package smb
import (
"encoding/asn1"
"encoding/binary"
"errors"
"fmt"
"math/rand"
"time"
"github/izouxv/smbapi/gss"
"github/izouxv/smbapi/ntlmssp"
"github/izouxv/smbapi/smb/encoder"
)
type SessionSetup1Request struct {
Header
StructureSize uint16
Flags byte
SecurityMode byte
Capabilities uint32
Channel uint32
SecurityBufferOffset uint16 `smb:"offset:SecurityBlob"`
SecurityBufferLength uint16 `smb:"len:SecurityBlob"`
PreviousSessionID uint64
SecurityBlob *gss.NegTokenInit
}
type SessionSetup1Response struct {
Header
StructureSize uint16
Flags uint16
SecurityBufferOffset uint16 `smb:"offset:SecurityBlob"`
SecurityBufferLength uint16 `smb:"len:SecurityBlob"`
SecurityBlob *gss.NegTokenResp
}
func (r *SessionSetup1Request) challengeData() ntlmssp.Challenge {
ServerChallenge := rand.Uint64()
challenge := ntlmssp.NewChallenge(ServerChallenge)
challenge.TargetName = encoder.ToUnicode("testGoGo")
if true {
type AvPair struct {
AvID uint16
AvLen uint16 `smb:"len:Value"`
Value []byte
}
// var infos []ntlmssp.AvPair
var infos ntlmssp.AvPairSlice
ft := uint64(time.Now().UnixNano()) / 100
timestamp := make([]byte, 8)
binary.LittleEndian.PutUint64(timestamp, ft)
infos = append(infos, ntlmssp.AvPair{
AvID: ntlmssp.MsvAvTimestamp,
AvLen: 8,
Value: timestamp,
})
infos = append(infos, ntlmssp.AvPair{
AvID: ntlmssp.MsvAvEOL,
AvLen: 8,
Value: timestamp,
})
challenge.TargetInfo = &infos
}
return challenge
}
func (data *SessionSetup1Request) ServerAction(ctx *DataCtx) (interface{}, error) {
resp1 := SessionSetup1Response{
SecurityBlob: &gss.NegTokenResp{},
}
resp1.Header = data.Header
resp1.Header.Credits = 33
resp1.Header.Status = StatusLogonFailure
resp1.Header.SessionID = ctx.session.sessionID
resp1.StructureSize = 9
resp1.SecurityBufferOffset = 0x48
resp1.Header.Flags = SMB2_FLAGS_RESPONSE
var ntlmsspneg ntlmssp.Negotiate
if err := encoder.Unmarshal(data.SecurityBlob.Data.MechToken, &ntlmsspneg); err != nil {
return ERR(data.Header, STATUS_INVALID_PARAMETER)
}
// logx.Printf("domain name: %v", ntlmsspneg.DomainName)
// logx.Printf("domain name: %v", ntlmsspneg.Workstation)
if true {
negotiateFlagmltmsspmsNEGOTIATELMKEY := 1 << 7
if int(ntlmsspneg.NegotiateFlags)&negotiateFlagmltmsspmsNEGOTIATELMKEY == negotiateFlagmltmsspmsNEGOTIATELMKEY {
return &resp1, nil
// return errors.New("Only NTLM v2 is supported, but server requested v1 (mltmsspms_NEGOTIATE_LM_KEY)")
}
}
// ServerChallenge := rand.Uint64()
// ctx.session.ServerChallenge = ServerChallenge
// challenge := ntlmssp.NewChallenge(ServerChallenge)
// challenge.TargetName = encoder.ToUnicode("testGoGo")
challenge := data.challengeData()
if true {
type AvPair struct {
AvID uint16
AvLen uint16 `smb:"len:Value"`
Value []byte
}
// var infos []ntlmssp.AvPair
var infos ntlmssp.AvPairSlice
ft := uint64(time.Now().UnixNano()) / 100
timestamp := make([]byte, 8)
binary.LittleEndian.PutUint64(timestamp, ft)
infos = append(infos, ntlmssp.AvPair{
AvID: ntlmssp.MsvAvTimestamp,
AvLen: 8,
Value: timestamp,
})
infos = append(infos, ntlmssp.AvPair{
AvID: ntlmssp.MsvAvEOL,
AvLen: 0,
})
challenge.TargetInfo = &infos
}
ctx.session.ServerChallenge = challenge.ServerChallenge
challengeData, err := encoder.Marshal(&challenge)
if err != nil {
return ERR(data.Header, STATUS_INVALID_PARAMETER)
}
resp1.SecurityBlob = &gss.NegTokenResp{
NegResult: asn1.Enumerated(gss.Accept_incomplete),
ResponseToken: challengeData,
SupportedMech: myMech(),
}
resp1.Header.Status = StatusMoreProcessingRequired
return &resp1, nil
}
func (requestSetUp1 *SessionSetup1Request) ClientAction(s *SessionC, setupResponse1 *SessionSetup1Response) error {
if setupResponse1.Header.Status != StatusMoreProcessingRequired {
// https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb/115b551a-dcd7-4ff2-8c59-a334b92e01c0
status, _ := StatusMap[setupResponse1.Header.Status]
return errors.New(fmt.Sprintf("NT Status Error: %s\n", status))
}
s.sessionID = setupResponse1.Header.SessionID
challenge := ntlmssp.NewChallenge(0)
resp := setupResponse1.SecurityBlob
if err := encoder.Unmarshal(resp.ResponseToken, &challenge); err != nil {
s.Debug("", err)
return err
}
s.Challenge = challenge
return nil
}
func (s *SessionC) NewSessionSetup1Request(mechType gss.MechTypeOid) SessionSetup1Request {
header := s.newHeader(CommandSessionSetup)
ntlmsspneg := ntlmssp.NewNegotiate(s.options.Domain, s.options.Workstation)
data, err := encoder.Marshal(ntlmsspneg)
if err != nil {
panic(-1)
}
negInit, _ := gss.NewNegTokenInit(mechType)
negInit.Data.MechToken = data
switch mechType {
case gss.NtLmSSPMechTypeOid:
}
return SessionSetup1Request{
Header: header,
StructureSize: 25,
Flags: 0x00,
SecurityMode: byte(SecurityModeSigningEnabled),
SecurityBufferOffset: 88,
SecurityBlob: negInit,
Capabilities: 0,
Channel: 0,
SecurityBufferLength: 0,
PreviousSessionID: 0,
}
}