From e4682168dfb1e0569166e0d580ecfc6c56dc5fe7 Mon Sep 17 00:00:00 2001 From: buffermet <29265684+buffermet@users.noreply.github.com> Date: Thu, 5 Mar 2020 08:34:45 +1000 Subject: [PATCH] add dns.spoof.ttl env variable --- modules/dns_spoof/dns_spoof.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/modules/dns_spoof/dns_spoof.go b/modules/dns_spoof/dns_spoof.go index 0db15410..8a74344d 100644 --- a/modules/dns_spoof/dns_spoof.go +++ b/modules/dns_spoof/dns_spoof.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "net" + "strconv" "sync" "github.com/bettercap/bettercap/packets" @@ -20,6 +21,7 @@ type DNSSpoofer struct { session.SessionModule Handle *pcap.Handle Hosts Hosts + TTL uint32 All bool waitGroup *sync.WaitGroup pktSourceChan chan gopacket.Packet @@ -31,6 +33,7 @@ func NewDNSSpoofer(s *session.Session) *DNSSpoofer { Handle: nil, All: false, Hosts: Hosts{}, + TTL: 1024, waitGroup: &sync.WaitGroup{}, } @@ -55,6 +58,11 @@ func NewDNSSpoofer(s *session.Session) *DNSSpoofer { "false", "If true the module will reply to every DNS request, otherwise it will only reply to the one targeting the local pc.")) + mod.AddParam(session.NewStringParameter("dns.spoof.ttl", + "1024", + "^[0-9]+$", + "TTL of spoofed DNS replies in seconds.")) + mod.AddHandler(session.NewModuleHandler("dns.spoof on", "", "Start the DNS spoofer in the background.", func(args []string) error { @@ -84,6 +92,7 @@ func (mod DNSSpoofer) Author() string { func (mod *DNSSpoofer) Configure() error { var err error + var ttl string var hostsFile string var domains []string var address net.IP @@ -102,6 +111,8 @@ func (mod *DNSSpoofer) Configure() error { return err } else if err, hostsFile = mod.StringParam("dns.spoof.hosts"); err != nil { return err + } else if err, ttl = mod.StringParam("dns.spoof.ttl"); err != nil { + return err } mod.Hosts = Hosts{} @@ -131,6 +142,12 @@ func (mod *DNSSpoofer) Configure() error { mod.Session.Firewall.EnableForwarding(true) } + ttl_, err := strconv.ParseUint(ttl, 10, 32) + if err != nil { + return fmt.Errorf("dns.spoof.ttl value must be an integer") + } + mod.TTL = uint32(ttl_) + return nil } @@ -184,7 +201,7 @@ func (mod *DNSSpoofer) dnsReply(pkt gopacket.Packet, peth *layers.Ethernet, pudp Name: []byte(q.Name), Type: q.Type, Class: q.Class, - TTL: 1024, + TTL: mod.TTL, IP: address, }) }