mirror of
https://github.com/bettercap/bettercap
synced 2025-08-21 14:03:17 -07:00
Refactoring modules
This commit is contained in:
parent
c0d3c314fc
commit
ed652622e2
89 changed files with 186 additions and 138 deletions
66
modules/net_sniff/net_sniff_dns.go
Normal file
66
modules/net_sniff/net_sniff_dns.go
Normal file
|
@ -0,0 +1,66 @@
|
|||
package net_sniff
|
||||
|
||||
import (
|
||||
"github.com/google/gopacket"
|
||||
"github.com/google/gopacket/layers"
|
||||
"strings"
|
||||
|
||||
"github.com/evilsocket/islazy/tui"
|
||||
)
|
||||
|
||||
func dnsParser(ip *layers.IPv4, pkt gopacket.Packet, udp *layers.UDP) bool {
|
||||
dns, parsed := pkt.Layer(layers.LayerTypeDNS).(*layers.DNS)
|
||||
if !parsed {
|
||||
return false
|
||||
}
|
||||
|
||||
if dns.OpCode != layers.DNSOpCodeQuery {
|
||||
return false
|
||||
}
|
||||
|
||||
m := make(map[string][]string)
|
||||
answers := [][]layers.DNSResourceRecord{
|
||||
dns.Answers,
|
||||
dns.Authorities,
|
||||
dns.Additionals,
|
||||
}
|
||||
|
||||
for _, list := range answers {
|
||||
for _, a := range list {
|
||||
if a.IP == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
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 {
|
||||
NewSnifferEvent(
|
||||
pkt.Metadata().Timestamp,
|
||||
"dns",
|
||||
ip.SrcIP.String(),
|
||||
ip.DstIP.String(),
|
||||
nil,
|
||||
"%s %s > %s : %s is %s",
|
||||
tui.Wrap(tui.BACKDARKGRAY+tui.FOREWHITE, "dns"),
|
||||
vIP(ip.SrcIP),
|
||||
vIP(ip.DstIP),
|
||||
tui.Yellow(hostname),
|
||||
tui.Dim(strings.Join(ips, ", ")),
|
||||
).Push()
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue