-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
99 lines (86 loc) · 2.89 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"fmt"
"log"
"os"
"regexp"
"strings"
"github.com/hupe1980/fakedns"
"github.com/hupe1980/golog"
"github.com/spf13/cobra"
)
const (
version = "dev"
defaultTTL = 60
)
func main() {
var opts struct {
addr string
net string
upstream string
ttl uint32
ipsV4 []string
rebindV4 string
ipsV6 []string
rebindV6 string
rebindThreshold int
text []string
mx string
verbose bool
}
rootCmd := &cobra.Command{
Use: "fakedns [domains]",
Version: version,
Short: "Tiny DNS proxy for Penetration Testers and Malware Analysts",
Args: cobra.MaximumNArgs(1),
Example: `- IPV4: fakedns example.org --ipv4 127.0.0.1
- Wildcards: fakedns example.* --ipv4 127.0.0.1
- RoundRobin: fakedns example.org --ipv4 127.0.0.1,10.10.10.10
- Rebind: fakedns example.org --ipv4 127.0.0.1 --rebind-v4 10.10.10.10
- Upstream: fakedns example.org --ipv4 127.0.0.1 --upstream 8.8.8.8`,
RunE: func(cmd *cobra.Command, args []string) error {
rebind, err := fakedns.NewRebind(opts.rebindV4, opts.rebindV6, opts.rebindThreshold)
if err != nil {
return err
}
options := &fakedns.Options{
TTL: opts.ttl,
IPsV4: opts.ipsV4,
IPsV6: opts.ipsV6,
Rebind: rebind,
Text: opts.text,
MX: opts.mx,
}
if opts.upstream != "" {
options.FallbackDNSResolver = opts.upstream
}
lvl := golog.ERROR
if opts.verbose {
lvl = golog.INFO
}
options.Logger = golog.NewGoLogger(lvl, log.Default())
domain, err := regexp.Compile(strings.Join(args, "|"))
if err != nil {
return err
}
fakeDNS := fakedns.New(domain, options)
return fakeDNS.ListenAndServe(opts.addr, opts.net)
},
}
rootCmd.Flags().StringVarP(&opts.addr, "addr", "a", "0.0.0.0:53", "fakeDNS address")
rootCmd.Flags().StringVarP(&opts.net, "net", "n", "udp", "fakeDNS network protocol")
rootCmd.Flags().StringVarP(&opts.upstream, "upstream", "", "", "upstream dns server")
rootCmd.Flags().StringSliceVarP(&opts.ipsV4, "ipv4", "", nil, "IPV4 address to return")
rootCmd.Flags().StringSliceVarP(&opts.ipsV6, "ipv6", "", nil, "IPV6 address to return")
rootCmd.Flags().Uint32VarP(&opts.ttl, "ttl", "", defaultTTL, "time to live")
rootCmd.Flags().StringVarP(&opts.rebindV4, "rebind-v4", "", "", "IPV4 rebind address")
rootCmd.Flags().StringVarP(&opts.rebindV6, "rebind-v6", "", "", "IPV6 rebind address")
rootCmd.Flags().IntVarP(&opts.rebindThreshold, "rebind-threshold", "", 1, "rebind threshold")
rootCmd.Flags().StringSliceVarP(&opts.text, "text", "", nil, "TXT text value")
rootCmd.Flags().StringVarP(&opts.mx, "mx", "", "", "host name of mail exchange server")
rootCmd.Flags().BoolVarP(&opts.verbose, "verbose", "v", false, "print detailed logging messages")
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}