diff --git a/modules/dns_spoof/dns_spoof.go b/modules/dns_spoof/dns_spoof.go index 0db15410..bd865e68 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.")) + 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,9 @@ func (mod *DNSSpoofer) Configure() error { mod.Session.Firewall.EnableForwarding(true) } + _ttl, _ := strconv.Atoi(ttl) + mod.TTL = uint32(_ttl) + return nil } @@ -184,7 +198,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, }) }