fix: better dns logging

This commit is contained in:
evilsocket 2018-01-10 14:53:49 +01:00
commit 5bc00fb126

View file

@ -1,6 +1,8 @@
package modules package modules
import ( import (
"strings"
"github.com/evilsocket/bettercap-ng/core" "github.com/evilsocket/bettercap-ng/core"
"github.com/google/gopacket" "github.com/google/gopacket"
@ -17,17 +19,29 @@ func dnsParser(ip *layers.IPv4, pkt gopacket.Packet, udp *layers.UDP) bool {
return false return false
} }
m := make(map[string][]string, 0)
for _, a := range dns.Answers { for _, a := range dns.Answers {
if a.IP == nil { if a.IP == nil {
continue continue
} }
hostname := string(a.Name)
if _, found := m[hostname]; found == false {
m[hostname] = make([]string, 0)
}
m[hostname] = append(m[hostname], vIP(a.IP))
}
for hostname, ips := range m {
SniffPrinter("[%s] %s %s > %s : %s is %s\n", SniffPrinter("[%s] %s %s > %s : %s is %s\n",
vTime(pkt.Metadata().Timestamp), vTime(pkt.Metadata().Timestamp),
core.W(core.BG_DGRAY+core.FG_WHITE, "dns"), core.W(core.BG_DGRAY+core.FG_WHITE, "dns"),
vIP(ip.SrcIP), vIP(ip.SrcIP),
vIP(ip.DstIP), vIP(ip.DstIP),
core.Yellow(string(a.Name)), core.Yellow(hostname),
vIP(a.IP)) core.Dim(strings.Join(ips, ", ")),
)
} }
return true return true