forked from vadimi/go-http-ntlm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
negotiator.go
55 lines (48 loc) · 2.42 KB
/
negotiator.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
package httpntlm
import (
"encoding/base64"
"encoding/binary"
)
const (
negotiateUnicode = 0x0001 // Text strings are in unicode
negotiateOEM = 0x0002 // Text strings are in OEM
requestTarget = 0x0004 // Server return its auth realm
negotiateSign = 0x0010 // Request signature capability
negotiateSeal = 0x0020 // Request confidentiality
negotiateLMKey = 0x0080 // Generate session key
negotiateNTLM = 0x0200 // NTLM authentication
negotiateLocalCall = 0x4000 // client/server on same machine
negotiateAlwaysSign = 0x8000 // Sign for all security levels
negotiateExtendedSessionSecurity = 0x80000 // Extended session security
negotiateVersion = 0x02000000 // negotiate version flag
negotiate128 = 0x20000000 // 128-bit session key negotiation
negotiateKeyExch = 0x40000000 // Key exchange
negotiate56 = 0x80000000 // 56-bit encryption
negotiateFlags uint32 = negotiateAlwaysSign | negotiateExtendedSessionSecurity | negotiateKeyExch |
negotiate128 | negotiate56 | negotiateNTLM | requestTarget | negotiateOEM |
negotiateUnicode | negotiateVersion
)
var (
put32 = binary.LittleEndian.PutUint32
put16 = binary.LittleEndian.PutUint16
encBase64 = base64.StdEncoding.EncodeToString
decBase64 = base64.StdEncoding.DecodeString
)
// generates NTLM Negotiate type-1 message
// for details see https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-nlmp/b34032e5-3aae-4bc6-84c3-c6d80eadf7f2
func negotiate() []byte {
ret := make([]byte, 40)
copy(ret, []byte("NTLMSSP\x00")) // protocol
put32(ret[8:], 1) // type
put32(ret[12:], negotiateFlags) // flags
put16(ret[16:], 0) // NT domain name length
put16(ret[18:], 0) // NT domain name max length
put32(ret[20:], 0) // NT domain name offset
put16(ret[24:], 0) // local workstation name length
put16(ret[26:], 0) // local workstation name max length
put32(ret[28:], 40) // local workstation name offset
put16(ret[32:], 0x0106) // ProductMajorVersion - 6, ProductMinorVersion - 1
put16(ret[34:], 7601) // ProductBuild - 7601
put16(ret[38:], 0x0f00) // NTLM revision - 15
return ret
}