mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 18:57:17 -07:00
new: ntlm parser
This commit is contained in:
parent
2c7a8d8fa7
commit
68b05ac469
2 changed files with 66 additions and 3 deletions
63
modules/net_sniff_ntlm.go
Normal file
63
modules/net_sniff_ntlm.go
Normal file
|
@ -0,0 +1,63 @@
|
|||
package modules
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/evilsocket/bettercap-ng/core"
|
||||
|
||||
"github.com/google/gopacket"
|
||||
"github.com/google/gopacket/layers"
|
||||
)
|
||||
|
||||
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)")
|
||||
)
|
||||
|
||||
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
|
||||
for _, line := range strings.Split(string(data), "\r\n") {
|
||||
if isNtlm(line) {
|
||||
tokens := strings.Split(line, " ")
|
||||
if len(tokens) != 3 {
|
||||
continue
|
||||
}
|
||||
what := "?"
|
||||
if isChallenge(line) {
|
||||
what = "challenge"
|
||||
} else if isResponse(line) {
|
||||
what = "response"
|
||||
}
|
||||
|
||||
NewSnifferEvent(
|
||||
pkt.Metadata().Timestamp,
|
||||
"ntlm."+what,
|
||||
ip.SrcIP.String(),
|
||||
ip.DstIP.String(),
|
||||
SniffData{
|
||||
what: tokens[2],
|
||||
},
|
||||
"%s %s > %s | %s",
|
||||
core.W(core.BG_DGRAY+core.FG_WHITE, "ntlm."+what),
|
||||
vIP(ip.SrcIP),
|
||||
vIP(ip.DstIP),
|
||||
tokens[2],
|
||||
).Push()
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
|
@ -15,11 +15,11 @@ func tcpParser(ip *layers.IPv4, pkt gopacket.Packet, verbose bool) {
|
|||
|
||||
if sniParser(ip, pkt, tcp) {
|
||||
return
|
||||
} else if ntlmParser(ip, pkt, tcp) {
|
||||
return
|
||||
} else if httpParser(ip, pkt, tcp) {
|
||||
return
|
||||
}
|
||||
|
||||
if verbose == true {
|
||||
} else if verbose == true {
|
||||
NewSnifferEvent(
|
||||
pkt.Metadata().Timestamp,
|
||||
"tcp",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue