forked from d3mondev/puredns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.go
71 lines (56 loc) · 1.8 KB
/
root.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
package cmd
import (
"io/ioutil"
"github.com/d3mondev/puredns/v2/internal/app/ctx"
"github.com/d3mondev/puredns/v2/internal/pkg/console"
"github.com/spf13/cobra"
)
var (
context *ctx.Ctx
)
func must(err error) {
if err != nil {
panic(err)
}
}
func newCmdRoot() *cobra.Command {
rootCmd := &cobra.Command{
Use: context.ProgramName,
Short: context.ProgramTagline,
Long: context.ProgramName + " " + context.ProgramVersion + `
A subdomain bruteforce tool that wraps around massdns to quickly resolve
a massive number of DNS queries. Using its heuristic algorithm, it can filter out
wildcard subdomains and validate that the results are free of DNS poisoning
by using trusted resolvers.`,
Example: ` puredns resolve domains.txt
puredns bruteforce wordlist.txt domain.com --resolvers public.txt
cat domains.txt | puredns resolve`,
Version: context.ProgramVersion,
}
rootCmd.CompletionOptions.DisableDefaultCmd = true
rootCmd.PersistentFlags().BoolVarP(&context.Options.Quiet, "quiet", "q", context.Options.Quiet, "quiet mode")
rootCmd.PersistentFlags().BoolVar(&context.Options.Debug, "debug", context.Options.Debug, "keep intermediate files")
rootCmd.Flags().SortFlags = false
cmdResolve := newCmdResolve()
cmdBruteforce := newCmdBruteforce()
cmdSponsors := newCmdSponsors()
rootCmd.AddCommand(cmdResolve)
rootCmd.AddCommand(cmdBruteforce)
rootCmd.AddCommand(cmdSponsors)
rootCmd.SetHelpCommand(&cobra.Command{Hidden: true})
rootCmd.SilenceErrors = true
rootCmd.PersistentPreRun = preRun
return rootCmd
}
func preRun(cmd *cobra.Command, args []string) {
cmd.SilenceUsage = true
if context.Options.Quiet {
console.Output = ioutil.Discard
}
}
// Execute executes the root command.
func Execute(ctx *ctx.Ctx) error {
context = ctx
cmdRoot := newCmdRoot()
return cmdRoot.Execute()
}