From 0d7eb43ee589eeaf3286eb4612eaf0ae2a294cfe Mon Sep 17 00:00:00 2001 From: evilsocket Date: Tue, 29 Jan 2019 14:40:32 +0100 Subject: [PATCH] fix: fixed a bug in DNS sniffer which prevented it to report all query responses --- modules/net_sniff_dns.go | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/modules/net_sniff_dns.go b/modules/net_sniff_dns.go index 7e251b9e..013b846c 100644 --- a/modules/net_sniff_dns.go +++ b/modules/net_sniff_dns.go @@ -1,10 +1,9 @@ package modules import ( - "strings" - "github.com/google/gopacket" "github.com/google/gopacket/layers" + "strings" "github.com/evilsocket/islazy/tui" ) @@ -20,17 +19,31 @@ func dnsParser(ip *layers.IPv4, pkt gopacket.Packet, udp *layers.UDP) bool { } m := make(map[string][]string) - for _, a := range dns.Answers { - if a.IP == nil { - continue - } + answers := [][]layers.DNSResourceRecord{ + dns.Answers, + dns.Authorities, + dns.Additionals, + } - hostname := string(a.Name) - if _, found := m[hostname]; !found { - m[hostname] = make([]string, 0) - } + for _, list := range answers { + for _, a := range list { + if a.IP == nil { + continue + } - m[hostname] = append(m[hostname], vIP(a.IP)) + hostname := string(a.Name) + if _, found := m[hostname]; !found { + m[hostname] = make([]string, 0) + } + + m[hostname] = append(m[hostname], vIP(a.IP)) + } + } + + if len(m) == 0 && dns.ResponseCode != layers.DNSResponseCodeNoErr { + for _, a := range dns.Questions { + m[string(a.Name)] = []string{tui.Red(dns.ResponseCode.String())} + } } for hostname, ips := range m {