From 01ed35fa2847aed5b43f896d1a77333f749db00f Mon Sep 17 00:00:00 2001 From: Moritz Wagner Date: Sun, 17 Mar 2019 03:51:43 +0100 Subject: [PATCH] dns.spoof.hosts supports both wildcard (optional) based domain lines and hosts based entries. if the ip is ommited in a line it defaults to the ip given in dns.spoof.address. example hosts file contents: *.example. google.com 127.0.0.1 *.yahoo.* 127.0.0.2 --- modules/dns_spoof/dns_spoof.go | 2 +- modules/dns_spoof/dns_spoof_hosts.go | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/dns_spoof/dns_spoof.go b/modules/dns_spoof/dns_spoof.go index 7c197274..6905ff75 100644 --- a/modules/dns_spoof/dns_spoof.go +++ b/modules/dns_spoof/dns_spoof.go @@ -109,7 +109,7 @@ func (mod *DNSSpoofer) Configure() error { if hostsFile != "" { mod.Info("loading hosts from file %s ...", hostsFile) - if err, hosts := HostsFromFile(hostsFile); err != nil { + if err, hosts := HostsFromFile(hostsFile, address); err != nil { return fmt.Errorf("error reading hosts from file %s: %v", hostsFile, err) } else { mod.Hosts = append(mod.Hosts, hosts...) diff --git a/modules/dns_spoof/dns_spoof_hosts.go b/modules/dns_spoof/dns_spoof_hosts.go index 5f4580e6..adb6c3c3 100644 --- a/modules/dns_spoof/dns_spoof_hosts.go +++ b/modules/dns_spoof/dns_spoof_hosts.go @@ -2,7 +2,6 @@ package dns_spoof import ( "bufio" - "fmt" "net" "os" "regexp" @@ -47,7 +46,7 @@ func NewHostEntry(host string, address net.IP) HostEntry { return entry } -func HostsFromFile(filename string) (err error, entries []HostEntry) { +func HostsFromFile(filename string,defaultAddress net.IP) (err error, entries []HostEntry) { input, err := os.Open(filename) if err != nil { return @@ -66,7 +65,7 @@ func HostsFromFile(filename string) (err error, entries []HostEntry) { domain := parts[1] entries = append(entries, NewHostEntry(domain, address)) } else { - return fmt.Errorf("'%s' invalid hosts line", line), nil + entries = append(entries, NewHostEntry(line, defaultAddress)) } }