[net.sniff] Add net.sniff.truncate param (default bool true) in order to toggle shortening / truncating (...) of long URLs in HTTP requests on demand

This commit is contained in:
Sabin Tudor 2018-02-04 23:31:10 +02:00
commit 839d5da9f2
4 changed files with 40 additions and 8 deletions

View file

@ -2,9 +2,9 @@ package modules
import (
"fmt"
"regexp"
"github.com/evilsocket/bettercap-ng/core"
"regexp"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
@ -13,7 +13,12 @@ import (
var httpRe = regexp.MustCompile("(?s).*(GET|HEAD|POST|PUT|DELETE|CONNECT|OPTIONS|TRACE|PATCH) (.+) HTTP/\\d\\.\\d.+Host: ([^\\s]+)")
var uaRe = regexp.MustCompile("(?s).*User-Agent: ([^\\n]+).+")
func httpParser(ip *layers.IPv4, pkt gopacket.Packet, tcp *layers.TCP) bool {
func httpParser(
ip *layers.IPv4,
pkt gopacket.Packet,
tcp *layers.TCP,
truncateURLs bool,
) bool {
data := tcp.Payload
dataSize := len(data)
@ -41,6 +46,12 @@ func httpParser(ip *layers.IPv4, pkt gopacket.Packet, tcp *layers.TCP) bool {
}
url += fmt.Sprintf("%s", path)
// shorten / truncate long URLs if needed
formattedURL := string(url)
if truncateURLs {
formattedURL = vURL(url)
}
NewSnifferEvent(
pkt.Metadata().Timestamp,
"http",
@ -57,7 +68,7 @@ func httpParser(ip *layers.IPv4, pkt gopacket.Packet, tcp *layers.TCP) bool {
core.W(core.BG_RED+core.FG_BLACK, "http"),
vIP(ip.SrcIP),
core.W(core.BG_LBLUE+core.FG_BLACK, method),
vURL(url),
formattedURL,
core.Dim(ua),
).Push()