mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 21:43:18 -07:00
new: implemented dns packet parser
This commit is contained in:
parent
9cdf365b13
commit
27b1f48584
5 changed files with 79 additions and 37 deletions
36
modules/net_sniff_dns.go
Normal file
36
modules/net_sniff_dns.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package modules
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/evilsocket/bettercap-ng/core"
|
||||
|
||||
"github.com/google/gopacket"
|
||||
"github.com/google/gopacket/layers"
|
||||
)
|
||||
|
||||
func dnsParser(ip *layers.IPv4, pkt gopacket.Packet, udp *layers.UDP) bool {
|
||||
dns, parsed := pkt.Layer(layers.LayerTypeDNS).(*layers.DNS)
|
||||
if parsed == false {
|
||||
return false
|
||||
}
|
||||
|
||||
if dns.OpCode != layers.DNSOpCodeQuery || len(dns.Answers) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, a := range dns.Answers {
|
||||
if a.IP == nil {
|
||||
continue
|
||||
}
|
||||
fmt.Printf("[%s] %s %s > %s : %s is %s\n",
|
||||
vTime(pkt.Metadata().Timestamp),
|
||||
core.W(core.BG_DGRAY+core.FG_WHITE, "dns"),
|
||||
vIP(ip.SrcIP),
|
||||
vIP(ip.DstIP),
|
||||
core.Yellow(string(a.Name)),
|
||||
vIP(a.IP))
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue