Merge pull request #705 from buffermet/master

add dns.spoof.ttl env variable
This commit is contained in:
Simone Margaritelli 2020-04-08 10:47:26 +02:00 committed by GitHub
commit 877600fec1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"net" "net"
"strconv"
"sync" "sync"
"github.com/bettercap/bettercap/packets" "github.com/bettercap/bettercap/packets"
@ -20,6 +21,7 @@ type DNSSpoofer struct {
session.SessionModule session.SessionModule
Handle *pcap.Handle Handle *pcap.Handle
Hosts Hosts Hosts Hosts
TTL uint32
All bool All bool
waitGroup *sync.WaitGroup waitGroup *sync.WaitGroup
pktSourceChan chan gopacket.Packet pktSourceChan chan gopacket.Packet
@ -31,6 +33,7 @@ func NewDNSSpoofer(s *session.Session) *DNSSpoofer {
Handle: nil, Handle: nil,
All: false, All: false,
Hosts: Hosts{}, Hosts: Hosts{},
TTL: 1024,
waitGroup: &sync.WaitGroup{}, waitGroup: &sync.WaitGroup{},
} }
@ -55,6 +58,11 @@ func NewDNSSpoofer(s *session.Session) *DNSSpoofer {
"false", "false",
"If true the module will reply to every DNS request, otherwise it will only reply to the one targeting the local pc.")) "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", "", mod.AddHandler(session.NewModuleHandler("dns.spoof on", "",
"Start the DNS spoofer in the background.", "Start the DNS spoofer in the background.",
func(args []string) error { func(args []string) error {
@ -84,6 +92,7 @@ func (mod DNSSpoofer) Author() string {
func (mod *DNSSpoofer) Configure() error { func (mod *DNSSpoofer) Configure() error {
var err error var err error
var ttl string
var hostsFile string var hostsFile string
var domains []string var domains []string
var address net.IP var address net.IP
@ -102,6 +111,8 @@ func (mod *DNSSpoofer) Configure() error {
return err return err
} else if err, hostsFile = mod.StringParam("dns.spoof.hosts"); err != nil { } else if err, hostsFile = mod.StringParam("dns.spoof.hosts"); err != nil {
return err return err
} else if err, ttl = mod.StringParam("dns.spoof.ttl"); err != nil {
return err
} }
mod.Hosts = Hosts{} mod.Hosts = Hosts{}
@ -131,6 +142,9 @@ func (mod *DNSSpoofer) Configure() error {
mod.Session.Firewall.EnableForwarding(true) mod.Session.Firewall.EnableForwarding(true)
} }
_ttl, _ := strconv.Atoi(ttl)
mod.TTL = uint32(_ttl)
return nil return nil
} }
@ -184,7 +198,7 @@ func (mod *DNSSpoofer) dnsReply(pkt gopacket.Packet, peth *layers.Ethernet, pudp
Name: []byte(q.Name), Name: []byte(q.Name),
Type: q.Type, Type: q.Type,
Class: q.Class, Class: q.Class,
TTL: 1024, TTL: mod.TTL,
IP: address, IP: address,
}) })
} }