/
crypto.go
42 lines (34 loc) · 1.04 KB
/
crypto.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
package ntlmssp
import (
"crypto/hmac"
"crypto/md5"
"strings"
"github.com/tralahm/blackhat-go/chapter6_SMB_and_NTLM_A_Peek_Down_the_Rabbit_Hole/smb/smb/encoder"
"golang.org/x/crypto/md4"
)
func Ntowfv1(pass string) []byte {
hash := md4.New()
hash.Write(encoder.ToUnicode(pass))
return hash.Sum(nil)
}
func Ntowfv2(pass, user, domain string) []byte {
h := hmac.New(md5.New, Ntowfv1(pass))
h.Write(encoder.ToUnicode(strings.ToUpper(user) + domain))
return h.Sum(nil)
}
func Lmowfv2(pass, user, domain string) []byte {
return Ntowfv2(pass, user, domain)
}
func ComputeResponseNTLMv2(nthash, lmhash, clientChallenge, serverChallenge, timestamp, serverName []byte) []byte {
temp := []byte{1, 1}
temp = append(temp, 0, 0, 0, 0, 0, 0)
temp = append(temp, timestamp...)
temp = append(temp, clientChallenge...)
temp = append(temp, 0, 0, 0, 0)
temp = append(temp, serverName...)
temp = append(temp, 0, 0, 0, 0)
h := hmac.New(md5.New, nthash)
h.Write(append(serverChallenge, temp...))
ntproof := h.Sum(nil)
return append(ntproof, temp...)
}