mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 02:36:57 -07:00
add dns.spoof.ttl env variable
This commit is contained in:
parent
8ae28f4b3d
commit
e4682168df
1 changed files with 18 additions and 1 deletions
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue