Debian Codegraph @

modules/net_sniff/net_sniff_ntlm.go

raw symbols SCIP
1 package net_sniff
2
3 import (
4 "net"
5 "regexp"
6 "strings"
7
8 "github.com/bettercap/bettercap/packets"
9
10 "github.com/google/gopacket"
11 "github.com/google/gopacket/layers"
12
13 "github.com/evilsocket/islazy/tui"
14 )
15
16 var (
17 ntlmRe = regexp.MustCompile("(WWW-|Proxy-|)(Authenticate|Authorization): (NTLM|Negotiate)")
18 challRe = regexp.MustCompile("(WWW-|Proxy-|)(Authenticate): (NTLM|Negotiate)")
19 respRe = regexp.MustCompile("(WWW-|Proxy-|)(Authorization): (NTLM|Negotiate)")
20 ntlm = packets.NewNTLMState()
21 )
22
23 func isNtlm(s string) bool {
24 return ntlmRe.FindString(s) != ""
25 }
26
27 func isChallenge(s string) bool {
28 return challRe.FindString(s) != ""
29 }
30
31 func isResponse(s string) bool {
32 return respRe.FindString(s) != ""
33 }
34
35 func ntlmParser(srcIP, dstIP net.IP, payload []byte, pkt gopacket.Packet, tcp *layers.TCP) bool {
36 data := tcp.Payload
37 ok := false
38
39 for _, line := range strings.Split(string(data), "\r\n") {
40 if isNtlm(line) {
41 tokens := strings.Split(line, " ")
42 if len(tokens) != 3 {
43 continue
44 }
45 if isChallenge(line) {
46 ok = true
47 ntlm.AddServerResponse(tcp.Ack, tokens[2])
48 } else if isResponse(line) {
49 ok = true
50 ntlm.AddClientResponse(tcp.Seq, tokens[2], func(data packets.NTLMChallengeResponseParsed) {
51 NewSnifferEvent(
52 pkt.Metadata().Timestamp,
53 "ntlm.response",
54 srcIP.String(),
55 dstIP.String(),
56 nil,
57 "%s %s > %s | %s",
58 tui.Wrap(tui.BACKDARKGRAY+tui.FOREWHITE, "ntlm.response"),
59 vIP(srcIP),
60 vIP(dstIP),
61 data.LcString(),
62 ).Push()
63 })
64 }
65 }
66 }
67 return ok
68 }