-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflags.go
154 lines (133 loc) · 5.8 KB
/
flags.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package main
import (
"flag"
"fmt"
"html/template"
"os"
"strings"
"github.com/root4loot/recrawl/pkg/options"
)
type UsageData struct {
AppName string
DefaultConcurrency int
DefaultTimeout int
DefaultDelay int
DefaultDelayJitter int
DefaultFollowRedirects bool
}
const usageTemplate = `
Usage:
{{.AppName}} [options] (-t <target> | -I <targets.txt>)
TARGETING:
-i, --infile file containing targets (one per line)
-t, --target target domain/url (comma-separated)
-ih, --include-host also crawls this host (if found) (comma-separated)
-eh, --exclude-host do not crawl this host (if found) (comma-separated)
CONFIGURATIONS:
-c, --concurrency number of concurrent requests (Default: {{.DefaultConcurrency}})
-to, --timeout max request timeout (Default: {{.DefaultTimeout}} seconds)
-d, --delay delay between requests (Default: {{.DefaultDelay}} milliseconds)
-dj, --delay-jitter max jitter between requests (Default: {{.DefaultDelayJitter}} milliseconds)
-ua, --user-agent set user agent (Default: Mozilla/5.0)
-fr, --follow-redirects follow redirects (Default: {{.DefaultFollowRedirects}})
-p, --proxy set proxy (Default: none)
-r, --resolvers file containing list of resolvers (Default: System DNS)
-H, --header set custom header (Default: none)
OUTPUT:
-fs, --filter-status filter by status code (comma-separated)
-fe, --filter-ext filter by extension (comma-separated)
-v, --verbose verbose output (use -vv for added verbosity)
-o, --outfile output results to given file
-hs, --hide-status hide status code from output
-hw, --hide-warning hide warnings from output
-hm, --hide-media hide media from output (images, fonts, etc.)
-s, --silence silence results from output
-h, --help display help
--version display version
`
func (c *CLI) banner() {
fmt.Println("\nrecrawl", version, "by", author)
}
func (c *CLI) usage() {
data := UsageData{
AppName: os.Args[0],
DefaultConcurrency: options.Default().Concurrency,
DefaultTimeout: options.Default().Timeout,
DefaultDelay: options.Default().Delay,
DefaultDelayJitter: options.Default().DelayJitter,
DefaultFollowRedirects: options.Default().FollowRedirects,
}
tmpl, err := template.New("usage").Parse(usageTemplate)
if err != nil {
panic(err)
}
err = tmpl.Execute(os.Stdout, data)
if err != nil {
panic(err)
}
}
func (c *CLI) parseFlags() {
opts := new(options.Options)
var verbose bool
// TARGET
flag.StringVar(&opts.CLI.Target, "target", "", "")
flag.StringVar(&opts.CLI.Target, "t", "", "")
flag.StringVar(&opts.CLI.Infile, "i", "", "")
flag.StringVar(&opts.CLI.Infile, "infile", "", "")
// FILTERING
flag.StringVar(&opts.CLI.Include, "include-host", "", "")
flag.StringVar(&opts.CLI.Include, "ih", "", "")
flag.StringVar(&opts.CLI.Exclude, "exclude-host", "", "")
flag.StringVar(&opts.CLI.Exclude, "eh", "", "")
// CONFIGURATIONS
flag.IntVar(&opts.Concurrency, "concurrency", options.Default().Concurrency, "")
flag.IntVar(&opts.Concurrency, "c", options.Default().Concurrency, "")
flag.IntVar(&opts.Timeout, "timeout", options.Default().Timeout, "")
flag.IntVar(&opts.Timeout, "to", options.Default().Timeout, "")
flag.IntVar(&opts.Delay, "delay", options.Default().Delay, "")
flag.IntVar(&opts.Delay, "d", options.Default().Delay, "")
flag.IntVar(&opts.DelayJitter, "delay-jitter", options.Default().DelayJitter, "")
flag.IntVar(&opts.DelayJitter, "dj", options.Default().DelayJitter, "")
flag.StringVar(&opts.UserAgent, "user-agent", options.Default().UserAgent, "")
flag.StringVar(&opts.UserAgent, "ua", options.Default().UserAgent, "")
flag.BoolVar(&opts.FollowRedirects, "follow-redirects", options.Default().FollowRedirects, "")
flag.BoolVar(&opts.FollowRedirects, "fr", options.Default().FollowRedirects, "")
flag.StringVar(&opts.Proxy, "proxy", options.Default().Proxy, "")
flag.StringVar(&opts.Proxy, "p", options.Default().Proxy, "")
flag.StringVar(&opts.CLI.ResolversFile, "resolvers", "", "")
flag.StringVar(&opts.CLI.ResolversFile, "r", "", "")
flag.Var(&opts.Headers, "header", "")
flag.Var(&opts.Headers, "H", "")
// OUTPUT
flag.BoolVar(&opts.Silence, "s", false, "")
flag.BoolVar(&opts.Silence, "silence", false, "")
flag.BoolVar(&verbose, "v", false, "")
flag.BoolVar(&verbose, "vv", false, "")
flag.IntVar(&opts.Verbose, "verbose", 0, "")
flag.StringVar(&opts.CLI.Outfile, "o", "", "")
flag.StringVar(&opts.CLI.Outfile, "outfile", "", "")
flag.StringVar(&opts.CLI.FilterStatusCode, "filter-status", "", "")
flag.StringVar(&opts.CLI.FilterStatusCode, "fs", "", "")
flag.StringVar(&opts.CLI.FilterExtensions, "filter-ext", "", "")
flag.StringVar(&opts.CLI.FilterExtensions, "fe", "", "")
flag.BoolVar(&opts.CLI.HideWarning, "hw", false, "")
flag.BoolVar(&opts.CLI.HideWarning, "hide-warning", false, "")
flag.BoolVar(&opts.CLI.HideStatusCodes, "hs", false, "")
flag.BoolVar(&opts.CLI.HideStatusCodes, "hide-status", false, "")
flag.BoolVar(&opts.CLI.HideMedia, "hm", false, "")
flag.BoolVar(&opts.CLI.HideMedia, "hide-media", false, "")
flag.BoolVar(&opts.CLI.Help, "help", false, "")
flag.BoolVar(&opts.CLI.Help, "h", false, "")
flag.BoolVar(&opts.CLI.Version, "version", false, "")
flag.Usage = func() {
c.banner()
c.usage()
}
flag.Parse()
c.opts = *opts
for _, arg := range os.Args {
if strings.HasPrefix(arg, "-v") {
c.opts.Verbose = len(strings.TrimPrefix(arg, "-"))
}
}
}