-
Notifications
You must be signed in to change notification settings - Fork 1
/
smb.go
221 lines (203 loc) · 5.9 KB
/
smb.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
* MIT License
*
* Copyright (c) 2017 stacktitan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package smb
import (
"github.com/zmap/zgrab/ztools/smb/gss"
)
const ProtocolSmb = "\xFFSMB"
const ProtocolSmb2 = "\xFESMB"
const StatusOk = 0x00000000
const StatusMoreProcessingRequired = 0xc0000016
const StatusInvalidParameter = 0xc000000d
const StatusLogonFailure = 0xc000006d
const StatusUserSessionDeleted = 0xc0000203
var StatusMap = map[uint32]string{
StatusOk: "OK",
StatusMoreProcessingRequired: "More Processing Required",
StatusInvalidParameter: "Invalid Parameter",
StatusLogonFailure: "Logon failed",
StatusUserSessionDeleted: "User session deleted",
}
const DialectSmb_2_0_2 = 0x0202
const DialectSmb_2_1 = 0x0210
const DialectSmb_3_0 = 0x0300
const DialectSmb_3_0_2 = 0x0302
const DialectSmb_3_1_1 = 0x0311
const DialectSmb2_ALL = 0x02FF
const (
CommandNegotiate uint16 = iota
CommandSessionSetup
CommandLogoff
CommandTreeConnect
CommandTreeDisconnect
CommandCreate
CommandClose
CommandFlush
CommandRead
CommandWrite
CommandLock
CommandIOCtl
CommandCancel
CommandEcho
CommandQueryDirectory
CommandChangeNotify
CommandQueryInfo
CommandSetInfo
CommandOplockBreak
)
const (
_ uint16 = iota
SecurityModeSigningEnabled
SecurityModeSigningRequired
)
const (
_ byte = iota
ShareTypeDisk
ShareTypePipe
ShareTypePrint
)
const (
ShareFlagManualCaching uint32 = 0x00000000
ShareFlagAutoCaching uint32 = 0x00000010
ShareFlagVDOCaching uint32 = 0x00000020
ShareFlagNoCaching uint32 = 0x00000030
ShareFlagDFS uint32 = 0x00000001
ShareFlagDFSRoot uint32 = 0x00000002
ShareFlagRestriceExclusiveOpens uint32 = 0x00000100
ShareFlagForceSharedDelete uint32 = 0x00000200
ShareFlagAllowNamespaceCaching uint32 = 0x00000400
ShareFlagAccessBasedDirectoryEnum uint32 = 0x00000800
ShareFlagForceLevelIIOplock uint32 = 0x00001000
ShareFlagEnableHashV1 uint32 = 0x00002000
ShareFlagEnableHashV2 uint32 = 0x00004000
ShareFlagEncryptData uint32 = 0x00008000
)
const (
ShareCapDFS uint32 = 0x00000008
ShareCapContinuousAvailability uint32 = 0x00000010
ShareCapScaleout uint32 = 0x00000020
ShareCapCluster uint32 = 0x00000040
ShareCapAsymmetric uint32 = 0x00000080
)
type Header struct {
ProtocolID []byte `smb:"fixed:4"`
StructureSize uint16
CreditCharge uint16
Status uint32
Command uint16
Credits uint16
Flags uint32
NextCommand uint32
MessageID uint64
Reserved uint32
TreeID uint32
SessionID uint64
Signature []byte `smb:"fixed:16"`
}
type NegotiateReq struct {
Header
StructureSize uint16
DialectCount uint16 `smb:"count:Dialects"`
SecurityMode uint16
Reserved uint16
Capabilities uint32
ClientGuid []byte `smb:"fixed:16"`
ClientStartTime uint64
Dialects []uint16
}
type NegotiateRes struct {
Header
StructureSize uint16
SecurityMode uint16
DialectRevision uint16
Reserved uint16
ServerGuid []byte `smb:"fixed:16"`
Capabilities uint32
MaxTransactSize uint32
MaxReadSize uint32
MaxWriteSize uint32
SystemTime uint64
ServerStartTime uint64
SecurityBufferOffset uint16 `smb:"offset:SecurityBlob"`
SecurityBufferLength uint16 `smb:"len:SecurityBlob"`
Reserved2 uint32
SecurityBlob *gss.NegTokenInit
}
func newHeader() Header {
return Header{
ProtocolID: []byte(ProtocolSmb),
StructureSize: 64,
CreditCharge: 0,
Status: 0,
Command: 0,
Credits: 0,
Flags: 0,
NextCommand: 0,
MessageID: 0,
Reserved: 0,
TreeID: 0,
SessionID: 0,
Signature: make([]byte, 16),
}
}
func (s *Session) NewNegotiateReq() NegotiateReq {
header := newHeader()
header.Command = CommandNegotiate
header.CreditCharge = 1
header.MessageID = s.messageID
dialects := []uint16{
uint16(DialectSmb_2_1),
}
return NegotiateReq{
Header: header,
StructureSize: 36,
DialectCount: uint16(len(dialects)),
SecurityMode: SecurityModeSigningEnabled,
Reserved: 0,
Capabilities: 0,
ClientGuid: make([]byte, 16),
ClientStartTime: 0,
Dialects: dialects,
}
}
func NewNegotiateRes() NegotiateRes {
return NegotiateRes{
Header: newHeader(),
StructureSize: 0,
SecurityMode: 0,
DialectRevision: 0,
Reserved: 0,
ServerGuid: make([]byte, 16),
Capabilities: 0,
MaxTransactSize: 0,
MaxReadSize: 0,
MaxWriteSize: 0,
SystemTime: 0,
ServerStartTime: 0,
SecurityBufferOffset: 0,
SecurityBufferLength: 0,
Reserved2: 0,
SecurityBlob: &gss.NegTokenInit{},
}
}