-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflags.go
More file actions
87 lines (74 loc) · 3.75 KB
/
flags.go
File metadata and controls
87 lines (74 loc) · 3.75 KB
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
package main
import (
"flag"
"fmt"
"os"
"text/tabwriter"
npmjack "github.com/root4loot/npmjack/pkg/runner"
)
func (c *CLI) banner() {
fmt.Println("\nnpmjack", version, "by", author)
}
func (c *CLI) usage() {
w := tabwriter.NewWriter(os.Stdout, 2, 0, 3, ' ', 0)
fmt.Fprintf(w, "Usage:\t%s [options] (-u <url> | -i <targets.txt>)\n\n", os.Args[0])
fmt.Fprintf(w, "\nTARGETING:\n")
fmt.Fprintf(w, "\t%s, %s\t\t\t%s\n", "-u", "--url", "target URL")
fmt.Fprintf(w, "\t%s, %s\t\t\t%s\n", "-i", "--infile", "file containing URL's (newline separated)")
fmt.Fprintf(w, "\nCONFIGURATIONS:\n")
fmt.Fprintf(w, "\t%s, %s\t%s\t(Default: %d)\n", "-c", "--concurrency", "number of concurrent requests", npmjack.DefaultOptions().Concurrency)
fmt.Fprintf(w, "\t%s, %s\t%s\t(Default: %d %s)\n", "-t", "--timeout", "max request timeout", npmjack.DefaultOptions().Timeout, "seconds")
fmt.Fprintf(w, "\t%s, %s\t%s\t(Default: %d %s)\n", "-d", "--delay", "delay between requests", npmjack.DefaultOptions().Delay, "milliseconds")
fmt.Fprintf(w, "\t%s, %s\t%s\t(Default: %v)\n", "-r", "--resolvers", "file containing list of resolvers", "System DNS")
fmt.Fprintf(w, "\t%s, %s\t%s\t(Default: %d %s)\n", "-dj", "--delay-jitter", "max jitter between requests", npmjack.DefaultOptions().DelayJitter, "milliseconds")
fmt.Fprintf(w, "\t%s, %s\t%s\t(Default: %s)\n", "-ua", "--user-agent", "set user agent", npmjack.DefaultOptions().UserAgent)
fmt.Fprintf(w, "\t%s, %s\t%s\t(Example: %s)\n", "-p", "--proxy", "proxy URL", "127.0.0.1:8080")
fmt.Fprintf(w, "\nOUTPUT:\n")
fmt.Fprintf(w, "\t%s, %s\t%s\n", "-o", "--outfile", "output results to given file")
fmt.Fprintf(w, "\t%s, %s\t%s\n", "-hc", "--hide-claimed", "hide packages that are claimed")
fmt.Fprintf(w, "\t%s, %s\t%s\n", "-s", "--silence", "silence everything")
fmt.Fprintf(w, "\t%s, %s\t%s\n", "-v", "--verbose", "verbose output")
fmt.Fprintf(w, "\t%s %s\t%s\n", " ", "--version", "display version")
w.Flush()
fmt.Println("")
}
// parseAndSetOptions parses the command line options and sets the options
func (c *CLI) parseFlags() {
// TARGET
flag.StringVar(&c.TargetURL, "url", "", "")
flag.StringVar(&c.TargetURL, "u", "", "")
flag.StringVar(&c.Infile, "i", "", "")
flag.StringVar(&c.Infile, "infile", "", "")
// CONFIGURATIONS
flag.IntVar(&c.Concurrency, "concurrency", npmjack.DefaultOptions().Concurrency, "")
flag.IntVar(&c.Concurrency, "c", npmjack.DefaultOptions().Concurrency, "")
flag.IntVar(&c.Timeout, "timeout", npmjack.DefaultOptions().Timeout, "")
flag.IntVar(&c.Timeout, "t", npmjack.DefaultOptions().Timeout, "")
flag.IntVar(&c.Delay, "delay", npmjack.DefaultOptions().Delay, "")
flag.IntVar(&c.Delay, "d", npmjack.DefaultOptions().Delay, "")
flag.IntVar(&c.DelayJitter, "delay-jitter", npmjack.DefaultOptions().DelayJitter, "")
flag.IntVar(&c.DelayJitter, "dj", npmjack.DefaultOptions().DelayJitter, "")
flag.StringVar(&c.UserAgent, "user-agent", npmjack.DefaultOptions().UserAgent, "")
flag.StringVar(&c.UserAgent, "ua", npmjack.DefaultOptions().UserAgent, "")
flag.StringVar(&c.Proxy, "proxy", "", "")
flag.StringVar(&c.Proxy, "p", "", "")
flag.StringVar(&c.ResolversFile, "resolvers", "", "")
flag.StringVar(&c.ResolversFile, "r", "", "")
// OUTPUT
flag.BoolVar(&c.Silence, "s", false, "")
flag.BoolVar(&c.Silence, "silence", false, "")
flag.StringVar(&c.Outfile, "o", "", "")
flag.StringVar(&c.Outfile, "outfile", "", "")
flag.BoolVar(&c.HideClaimed, "hc", false, "")
flag.BoolVar(&c.HideClaimed, "hide-claimed", false, "")
flag.BoolVar(&c.Verbose, "v", false, "")
flag.BoolVar(&c.Verbose, "verbose", false, "")
flag.BoolVar(&c.Help, "help", false, "")
flag.BoolVar(&c.Help, "h", false, "")
flag.BoolVar(&c.Version, "version", false, "")
flag.Usage = func() {
c.banner()
c.usage()
}
flag.Parse()
}