forked from bettercap/bettercap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
net_sniff_ntlm.go
67 lines (57 loc) · 1.51 KB
/
net_sniff_ntlm.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
package net_sniff
import (
"regexp"
"strings"
"github.com/bettercap/bettercap/packets"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/evilsocket/islazy/tui"
)
var (
ntlmRe = regexp.MustCompile("(WWW-|Proxy-|)(Authenticate|Authorization): (NTLM|Negotiate)")
challRe = regexp.MustCompile("(WWW-|Proxy-|)(Authenticate): (NTLM|Negotiate)")
respRe = regexp.MustCompile("(WWW-|Proxy-|)(Authorization): (NTLM|Negotiate)")
ntlm = packets.NewNTLMState()
)
func isNtlm(s string) bool {
return ntlmRe.FindString(s) != ""
}
func isChallenge(s string) bool {
return challRe.FindString(s) != ""
}
func isResponse(s string) bool {
return respRe.FindString(s) != ""
}
func ntlmParser(ip *layers.IPv4, pkt gopacket.Packet, tcp *layers.TCP) bool {
data := tcp.Payload
ok := false
for _, line := range strings.Split(string(data), "\r\n") {
if isNtlm(line) {
tokens := strings.Split(line, " ")
if len(tokens) != 3 {
continue
}
if isChallenge(line) {
ok = true
ntlm.AddServerResponse(tcp.Ack, tokens[2])
} else if isResponse(line) {
ok = true
ntlm.AddClientResponse(tcp.Seq, tokens[2], func(data packets.NTLMChallengeResponseParsed) {
NewSnifferEvent(
pkt.Metadata().Timestamp,
"ntlm.response",
ip.SrcIP.String(),
ip.DstIP.String(),
nil,
"%s %s > %s | %s",
tui.Wrap(tui.BACKDARKGRAY+tui.FOREWHITE, "ntlm.response"),
vIP(ip.SrcIP),
vIP(ip.DstIP),
data.LcString(),
).Push()
})
}
}
}
return ok
}