forked from zmap/zgrab2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.go
98 lines (77 loc) · 3.46 KB
/
module.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
package zgrab2
import "time"
// Scanner is an interface that represents all functions necessary to run a scan
type Scanner interface {
// Init runs once for this module at library init time
Init(flags ScanFlags) error
// InitPerSender runs once per Goroutine. A single Goroutine will scan some non-deterministic
// subset of the input scan targets
InitPerSender(senderID int) error
// Returns the name passed at init
GetName() string
// Returns the trigger passed at init
GetTrigger() string
// Protocol returns the protocol identifier for the scan.
Protocol() string
// Scan connects to a host. The result should be JSON-serializable
Scan(t ScanTarget) (ScanStatus, interface{}, error)
}
// ScanResponse is the result of a scan on a single host
type ScanResponse struct {
// Status is required for all responses.
Status ScanStatus `json:"status"`
// Protocol is the identifier if the protocol that did the scan. In the case of a complex scan, this may differ from
// the scan name.
Protocol string `json:"protocol"`
Result interface{} `json:"result,omitempty"`
Timestamp string `json:"timestamp,omitempty"`
Error *string `json:"error,omitempty"`
}
// ScanModule is an interface which represents a module that the framework can
// manipulate
type ScanModule interface {
// NewFlags is called by the framework to pass to the argument parser. The parsed flags will be passed
// to the scanner created by NewScanner().
NewFlags() interface{}
// NewScanner is called by the framework for each time an individual scan is specified in the config or on
// the command-line. The framework will then call scanner.Init(name, flags).
NewScanner() Scanner
// Description returns a string suitable for use as an overview of this
// module within usage text.
Description() string
}
// ScanFlags is an interface which must be implemented by all types sent to
// the flag parser
type ScanFlags interface {
// Help optionally returns any additional help text, e.g. specifying what empty defaults
// are interpreted as.
Help() string
// Validate enforces all command-line flags and positional arguments have valid values.
Validate(args []string) error
}
// BaseFlags contains the options that every flags type must embed
type BaseFlags struct {
Port uint `short:"p" long:"port" description:"Specify port to grab on"`
Name string `short:"n" long:"name" description:"Specify name for output json, only necessary if scanning multiple modules"`
Timeout time.Duration `short:"t" long:"timeout" description:"Set connection timeout (0 = no timeout)" default:"10s"`
Trigger string `short:"g" long:"trigger" description:"Invoke only on targets with specified tag"`
BytesReadLimit int `short:"m" long:"maxbytes" description:"Maximum byte read limit per scan (0 = defaults)"`
}
// UDPFlags contains the common options used for all UDP scans
type UDPFlags struct {
LocalPort uint `long:"local-port" description:"Set an explicit local port for UDP traffic"`
LocalAddress string `long:"local-addr" description:"Set an explicit local address for UDP traffic"`
}
// GetName returns the name of the respective scanner
func (b *BaseFlags) GetName() string {
return b.Name
}
// GetModule returns the registered module that corresponds to the given name
// or nil otherwise
func GetModule(name string) ScanModule {
return modules[name]
}
var modules map[string]ScanModule
func init() {
modules = make(map[string]ScanModule)
}