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
This commit is contained in:
Moritz Wagner 2019-03-17 03:51:43 +01:00
parent 0810a1f2fe
commit 01ed35fa28
2 changed files with 3 additions and 4 deletions

View file

@ -109,7 +109,7 @@ func (mod *DNSSpoofer) Configure() error {
if hostsFile != "" { if hostsFile != "" {
mod.Info("loading hosts from file %s ...", 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) return fmt.Errorf("error reading hosts from file %s: %v", hostsFile, err)
} else { } else {
mod.Hosts = append(mod.Hosts, hosts...) mod.Hosts = append(mod.Hosts, hosts...)

View file

@ -2,7 +2,6 @@ package dns_spoof
import ( import (
"bufio" "bufio"
"fmt"
"net" "net"
"os" "os"
"regexp" "regexp"
@ -47,7 +46,7 @@ func NewHostEntry(host string, address net.IP) HostEntry {
return entry 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) input, err := os.Open(filename)
if err != nil { if err != nil {
return return
@ -66,7 +65,7 @@ func HostsFromFile(filename string) (err error, entries []HostEntry) {
domain := parts[1] domain := parts[1]
entries = append(entries, NewHostEntry(domain, address)) entries = append(entries, NewHostEntry(domain, address))
} else { } else {
return fmt.Errorf("'%s' invalid hosts line", line), nil entries = append(entries, NewHostEntry(line, defaultAddress))
} }
} }