mirror of
https://github.com/bettercap/bettercap
synced 2025-07-16 10:03:39 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
44fddfa455
commit
5eecd0bcce
4 changed files with 96 additions and 68 deletions
45
modules/net_sniff_tcp.go
Normal file
45
modules/net_sniff_tcp.go
Normal file
|
@ -0,0 +1,45 @@
|
|||
package modules
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/gopacket"
|
||||
"github.com/google/gopacket/layers"
|
||||
|
||||
"github.com/evilsocket/islazy/tui"
|
||||
)
|
||||
|
||||
var tcpParsers = []func(*layers.IPv4, gopacket.Packet, *layers.TCP) bool{
|
||||
sniParser,
|
||||
ntlmParser,
|
||||
httpParser,
|
||||
ftpParser,
|
||||
}
|
||||
|
||||
func onTCP(ip *layers.IPv4, pkt gopacket.Packet, verbose bool) {
|
||||
tcp := pkt.Layer(layers.LayerTypeTCP).(*layers.TCP)
|
||||
for _, parser := range tcpParsers {
|
||||
if parser(ip, pkt, tcp) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if verbose {
|
||||
NewSnifferEvent(
|
||||
pkt.Metadata().Timestamp,
|
||||
"tcp",
|
||||
fmt.Sprintf("%s:%s", ip.SrcIP, vPort(tcp.SrcPort)),
|
||||
fmt.Sprintf("%s:%s", ip.DstIP, vPort(tcp.DstPort)),
|
||||
SniffData{
|
||||
"Size": len(ip.Payload),
|
||||
},
|
||||
"%s %s:%s > %s:%s %s",
|
||||
tui.Wrap(tui.BACKLIGHTBLUE+tui.FOREBLACK, "tcp"),
|
||||
vIP(ip.SrcIP),
|
||||
vPort(tcp.SrcPort),
|
||||
vIP(ip.DstIP),
|
||||
vPort(tcp.DstPort),
|
||||
tui.Dim(fmt.Sprintf("%d bytes", len(ip.Payload))),
|
||||
).Push()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue