-
Notifications
You must be signed in to change notification settings - Fork 12
/
client.go
70 lines (59 loc) · 1.62 KB
/
client.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
package main
import (
"encoding/base64"
"fmt"
"ntlmssp"
"github.com/eddieivan01/nic"
)
var url = "http://127.0.0.1"
func client() {
resp, err := nic.Post(url, nil)
if err != nil || resp.StatusCode != 401 || resp.Header.Get("WWW-Authenticate") != "NTLM" {
fmt.Println("type1 error")
return
}
type1 := ntlmssp.NewNegotiateMsg(nil)
type1.NegotiateFlags |= ntlmssp.NEGOTIATE_OEM_DOMAIN_SUPPLIED |
ntlmssp.NEGOTIATE_OEM_WORKSTATION_SUPPLIED |
ntlmssp.NEGOTIATE_128BIT_SESSION_KEY |
ntlmssp.NEGOTIATE_56BIT_ENCRYPTION |
ntlmssp.NEGOTIATE_UNICODE_CHARSET |
ntlmssp.NEGOTIATE_REQUEST_TARGET_NAME
type1.SetDomainName([]byte("CC.LAB"))
type1.SetWorkstation([]byte("WIN-123456"))
type1.Display()
resp, err = nic.Post(url, nic.H{
Headers: nic.KV{
"Authorization": "NTLM " + base64.StdEncoding.EncodeToString(type1.Marshal('<')),
},
})
if err != nil {
fmt.Println(err)
return
}
// trip "NTLM "
bs, err := base64.StdEncoding.DecodeString(resp.Header.Get("WWW-Authenticate")[5:])
if err != nil {
fmt.Println("type2 error")
return
}
type2 := ntlmssp.NewChallengeMsg(bs)
type2.Display()
type3 := ntlmssp.NewAuthenticateMsg(nil)
type3.NegotiateFlags = type2.NegotiateFlags
// type3.NegotiateFlags &^= ntlmssp.NEGOTIATE_EXTENDED_SESSION_SECURITY
type3.SetUserName([]byte("admin"))
type3.SetDomainName([]byte("LAB"))
type3.SetNTLMResponse(2, type2.ServerChallenge[:], pwd)
type3.Display()
resp, err = nic.Post(url, nic.H{
Headers: nic.KV{
"Authorization": "NTLM " + base64.StdEncoding.EncodeToString(type3.Marshal('<')),
},
})
if err != nil {
fmt.Println(err)
return
}
fmt.Println(resp.Text)
}