2017-08-31 21:24:05 +00:00
|
|
|
package zgrab2
|
|
|
|
|
2017-10-04 03:57:56 +00:00
|
|
|
// Scanner is an interface that represents all functions necessary to run a scan
|
2017-09-26 18:02:27 +00:00
|
|
|
type Scanner interface {
|
2017-09-29 22:59:37 +00:00
|
|
|
// Init runs once for this module at library init time
|
|
|
|
Init(flags ScanFlags) error
|
2017-09-26 18:02:27 +00:00
|
|
|
|
|
|
|
// InitPerSender runs once per Goroutine. A single Goroutine will scan some non-deterministics
|
|
|
|
// subset of the input scan targets
|
|
|
|
InitPerSender(senderID int) error
|
|
|
|
|
|
|
|
// Returns the name passed at init
|
2017-08-31 21:24:05 +00:00
|
|
|
GetName() string
|
2017-09-26 18:02:27 +00:00
|
|
|
|
|
|
|
// Scan connects to a host. The result should be JSON-serializable
|
2017-10-14 23:52:36 +00:00
|
|
|
Scan(t ScanTarget) (interface{}, error)
|
2017-08-31 21:24:05 +00:00
|
|
|
}
|
|
|
|
|
2017-10-04 03:57:56 +00:00
|
|
|
// ScanModule is an interface which represents a module that the framework can
|
|
|
|
// manipulate
|
2017-09-26 18:02:27 +00:00
|
|
|
type ScanModule interface {
|
2017-10-04 03:57:56 +00:00
|
|
|
// NewFlags is called by the framework to pass to the argument parser. The parsed flags will be passed
|
2017-09-26 18:02:27 +00:00
|
|
|
// to the scanner created by NewScanner().
|
|
|
|
NewFlags() interface{}
|
|
|
|
|
2017-10-04 03:57:56 +00:00
|
|
|
// NewScanner is called by the framework for each time an individual scan is specified in the config or on
|
2017-09-26 18:02:27 +00:00
|
|
|
// the command-line. The framework will then call scanner.Init(name, flags).
|
2017-09-29 22:59:37 +00:00
|
|
|
NewScanner() Scanner
|
2017-08-31 21:24:05 +00:00
|
|
|
}
|
|
|
|
|
2017-10-04 03:57:56 +00:00
|
|
|
// ScanFlags is an interface which must be implemented by all types sent to
|
|
|
|
// the flag parser
|
2017-09-26 18:02:27 +00:00
|
|
|
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
|
2017-08-31 21:24:05 +00:00
|
|
|
}
|
|
|
|
|
2017-10-04 03:57:56 +00:00
|
|
|
// BaseFlags contains the options that every flags type must embed
|
2017-09-26 18:02:27 +00:00
|
|
|
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 uint `short:"t" long:"timeout" description:"Set connection timeout in seconds"`
|
2017-08-31 21:24:05 +00:00
|
|
|
}
|
|
|
|
|
2017-10-04 03:57:56 +00:00
|
|
|
// GetName returns the name of the respective scanner
|
2017-09-26 18:02:27 +00:00
|
|
|
func (b *BaseFlags) GetName() string {
|
|
|
|
return b.Name
|
2017-08-31 21:24:05 +00:00
|
|
|
}
|
|
|
|
|
2017-10-04 03:57:56 +00:00
|
|
|
// GetModule returns the registered module that corresponds to the given name
|
|
|
|
// or nil otherwise
|
2017-09-29 22:59:37 +00:00
|
|
|
func GetModule(name string) *ScanModule {
|
|
|
|
return modules[name]
|
|
|
|
}
|
|
|
|
|
|
|
|
var modules map[string]*ScanModule
|
2017-08-31 21:24:05 +00:00
|
|
|
|
|
|
|
func init() {
|
2017-09-29 22:59:37 +00:00
|
|
|
modules = make(map[string]*ScanModule)
|
2017-08-31 21:24:05 +00:00
|
|
|
}
|