-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
253 lines (232 loc) · 5.46 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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*
Copyright © 2023 Till Hoffmann <till@thetillhoff.de>
*/
package main
import (
"errors"
"fmt"
"log"
"log/slog"
"os"
"sync"
"github.com/thetillhoff/webscan/v3/pkg/logger"
"github.com/thetillhoff/webscan/v3/pkg/webscan"
"github.com/urfave/cli/v2"
)
var version = "dev" // This is just the default. The actual value is injected at compiletime
var verbosity int
func main() {
app := &cli.App{
Name: "webscan",
Usage: "Verifies web things",
Version: version,
HideVersion: true, // Disable `-v`, `--version` flags
HideHelpCommand: true, // Disable `help` subcommand
EnableBashCompletion: true,
Commands: []*cli.Command{
{
Name: "version",
Usage: "Prints the version of webscan",
Action: func(cCtx *cli.Context) error {
fmt.Printf("%s\n", cCtx.App.Version)
return nil
},
},
{
Name: "completion",
Usage: "Generate the autocompletion script for the specified shell",
HideHelpCommand: true, // Disable `help` subcommand
Subcommands: []*cli.Command{
{
Name: "bash",
Usage: "Generate the autocompletion script for bash",
Action: func(ctx *cli.Context) error {
autocomplete_bash()
return nil
},
},
{
Name: "powershell",
Usage: "Generate the autocompletion script for powershell",
Action: func(ctx *cli.Context) error {
autocomplete_powershell()
return nil
},
},
{
Name: "zsh",
Usage: "Generate the autocompletion script for zsh",
Action: func(ctx *cli.Context) error {
autocomplete_zsh()
return nil
},
},
},
},
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "ns",
Value: "",
Usage: "set custom dns server (default uses system dns)",
},
&cli.StringFlag{
Name: "dkim-selector",
Value: "",
Usage: "set dkim-selector as in <dkim-selector>._domainkey.<your-domain>.<tld>",
},
&cli.BoolFlag{
Name: "follow",
Value: false,
Usage: "follow redirects and CNAME checks",
},
&cli.BoolFlag{
Name: "verbose",
Aliases: []string{"v"},
Value: false,
Usage: "increase verbosity to Debug level",
Count: &verbosity,
},
&cli.BoolFlag{
Name: "instant",
Value: false,
Usage: "print results immediately after each scan instead of after all scans completed",
},
&cli.BoolFlag{
Name: "no-color",
Value: false,
Usage: "disable coloring of results and logs",
},
&cli.BoolFlag{
Name: "quiet",
Value: false,
Usage: "disable status updates and only prints results",
},
&cli.BoolFlag{
Name: "all",
Value: true,
Usage: "enable all checks",
},
&cli.BoolFlag{
Name: "dns",
Value: false,
Usage: "enable detailed DNS scan",
},
&cli.BoolFlag{
Name: "ip",
Value: false,
Usage: "enable IP analysis",
},
&cli.BoolFlag{
Name: "port",
Value: false,
Usage: "enable detailed port scanning",
},
&cli.BoolFlag{
Name: "tls",
Value: false,
Usage: "enable TLS scan",
},
&cli.BoolFlag{
Name: "protocol",
Value: false,
Usage: "enable HTTP protocol scan",
},
&cli.BoolFlag{
Name: "header",
Value: false,
Usage: "enable HTTP header scan",
},
&cli.BoolFlag{
Name: "content",
Value: false,
Usage: "enable HTTP content scan",
},
&cli.BoolFlag{
Name: "web",
Value: false,
Usage: "enable all HTTP scans except content scan",
},
&cli.BoolFlag{
Name: "mail",
Value: false,
Usage: "enable mail config scan",
},
&cli.BoolFlag{
Name: "subdomains",
Value: false,
Usage: "enable subdomains search",
},
},
Action: func(cCtx *cli.Context) error {
var (
err error
level slog.Level
engine webscan.Engine
writeMutex sync.Mutex
)
if cCtx.Args().Len() != 1 {
log.Fatalln(errors.New("exactly one argument expected"))
}
// Logging
switch verbosity {
case -1: // If it's not set at all, the number is -1, not 0
level = slog.LevelWarn
case 1:
level = slog.LevelInfo
case 3:
level = slog.LevelDebug
default:
log.Fatalln(errors.New("invalid verbosity amount"))
}
w := os.Stderr
// set global logger with custom options
slog.SetDefault(slog.New(
logger.NewHandler(
w,
&writeMutex,
&slog.HandlerOptions{
Level: level,
},
cCtx.Bool("no-color"),
),
))
engine, err = webscan.NewEngine(
cCtx.Bool("quiet"),
cCtx.Bool("noColor"),
cCtx.String("dnsServer"),
cCtx.Bool("follow"),
cCtx.Bool("instant"),
cCtx.Bool("advancedDnsScan"),
cCtx.Bool("ipScan"),
cCtx.Bool("advancedPortScan"),
cCtx.Bool("tlsScan"),
cCtx.Bool("httpProtocolScan"),
cCtx.Bool("httpHeaderScan"),
cCtx.Bool("htmlContentScan"),
cCtx.Bool("mailConfigScan"),
cCtx.Bool("subDomainScan"),
&writeMutex,
)
if err != nil {
slog.Error("could not create webscan engine with provided parameters", "error", err)
os.Exit(1)
}
if cCtx.Bool("web") { // Enable webscans only
engine.EnableWebScans()
}
engine.EnableAllScansIfNoneAreExplicitlySet()
err = engine.Scan(cCtx.Args().First())
if err != nil {
slog.Error("could not scan selected target", "error", err.Error())
os.Exit(2)
}
engine.PrintResults()
return nil
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
// cmd.Execute()
}