-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnegotiate_request.go
117 lines (95 loc) · 2.81 KB
/
negotiate_request.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
package simba
import (
"encoding/binary"
"log"
)
type NegotiateRequest []byte
func (p NegotiateRequest) IsInvalid() bool {
// MS-SMB2, MUST be set to 36
if len(p) < 36 {
return true
}
return false
}
func (p NegotiateRequest) StructureSize() uint16 {
return binary.LittleEndian.Uint16(p[0:2])
}
func (p NegotiateRequest) SetStructureSize() {
binary.LittleEndian.PutUint16(p[0:2], 36)
}
func (p NegotiateRequest) DialectCount() uint16 {
return binary.LittleEndian.Uint16(p[2:4])
}
func (p NegotiateRequest) SetDialectCount(v uint16) {
binary.LittleEndian.PutUint16(p[2:4], v)
}
func (p NegotiateRequest) SecurityMode() NegotiateSigning {
return NegotiateSigning(binary.LittleEndian.Uint16(p[4:6]))
}
func (p NegotiateRequest) SetSecurityMode(v NegotiateSigning) {
binary.LittleEndian.PutUint16(p[4:6], uint16(v))
}
func (p NegotiateRequest) Capabilities() uint32 {
return binary.LittleEndian.Uint32(p[8:12])
}
func (p NegotiateRequest) SetCapabilities(v uint32) {
binary.LittleEndian.PutUint32(p[8:12], v)
}
func (p NegotiateRequest) ClientGuid() []byte {
return p[12:28]
}
func (p NegotiateRequest) SetClientGuid(v []byte) {
copy(p[12:28], v)
}
func (p NegotiateRequest) NegotiateContextOffset() uint32 {
return binary.LittleEndian.Uint32(p[28:32])
}
func (p NegotiateRequest) SetNegotiateContextOffset(v uint32) {
binary.LittleEndian.PutUint32(p[28:32], v)
}
func (p NegotiateRequest) NegotiateContextCount() uint16 {
return binary.LittleEndian.Uint16(p[32:34])
}
func (p NegotiateRequest) SetNegotiateContextCount(v uint16) {
binary.LittleEndian.PutUint16(p[32:34], v)
}
func (p NegotiateRequest) Dialects() []Dialect {
if p.DialectCount() > 5 {
log.Fatal("DialectCount > 5")
return nil
}
dialects := make([]Dialect, p.DialectCount())
for i := 0; i < int(p.DialectCount()); i++ {
dialects[i] = Dialect(binary.LittleEndian.Uint16(p[36+i*2 : 36+i*2+2]))
}
return dialects
}
func (p NegotiateRequest) SetDialects(v []Dialect) {
for i := 0; i < len(v); i++ {
binary.LittleEndian.PutUint16(p[36+i*2:36+i*2+2], uint16(v[i]))
}
}
func (p NegotiateRequest) NegotiateContextList() []NegotiateContext {
offset := p.NegotiateContextOffset() - 64
if offset > uint32(len(p)) {
log.Fatalf("NegotiateContextOffset > len(p) %d > %d", offset, len(p))
return nil
}
count := p.NegotiateContextCount()
if count == 0 {
return nil
}
contexts := make([]NegotiateContext, count)
for i := 0; i < int(count); i++ {
if offset > uint32(len(p)) {
log.Fatalf("num:%d, NegotiateContextOffset > len(p) %d > %d", i, offset, len(p))
return nil
}
contexts[i] = NegotiateContext(p[offset:])
offset += uint32(contexts[i].DataLength()) + 8
if offset%8 != 0 {
offset += 8 - offset%8
}
}
return contexts
}