fix: fixed a bug in DNS sniffer which prevented it to report all query responses

This commit is contained in:
evilsocket 2019-01-29 14:40:32 +01:00
commit 0d7eb43ee5
No known key found for this signature in database
GPG key ID: 1564D7F30393A456

View file

@ -1,10 +1,9 @@
package modules package modules
import ( import (
"strings"
"github.com/google/gopacket" "github.com/google/gopacket"
"github.com/google/gopacket/layers" "github.com/google/gopacket/layers"
"strings"
"github.com/evilsocket/islazy/tui" "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) m := make(map[string][]string)
for _, a := range dns.Answers { answers := [][]layers.DNSResourceRecord{
if a.IP == nil { dns.Answers,
continue dns.Authorities,
} dns.Additionals,
}
hostname := string(a.Name) for _, list := range answers {
if _, found := m[hostname]; !found { for _, a := range list {
m[hostname] = make([]string, 0) 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 { for hostname, ips := range m {