restructure to make sense
This commit is contained in:
parent
e7535b764d
commit
d3490ddddd
42
module.go
42
module.go
@ -1,11 +1,5 @@
|
||||
package zgrab2
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"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
|
||||
@ -64,43 +58,7 @@ func GetModule(name string) *ScanModule {
|
||||
}
|
||||
|
||||
var modules map[string]*ScanModule
|
||||
var scanners map[string]*Scanner
|
||||
var orderedScanners []string
|
||||
|
||||
func init() {
|
||||
scanners = make(map[string]*Scanner)
|
||||
modules = make(map[string]*ScanModule)
|
||||
}
|
||||
|
||||
// RegisterScan registers each individual scanner to be ran by the framework
|
||||
func RegisterScan(name string, s Scanner) {
|
||||
//add to list and map
|
||||
if scanners[name] != nil {
|
||||
log.Fatalf("name: %s already used", name)
|
||||
}
|
||||
orderedScanners = append(orderedScanners, name)
|
||||
scanners[name] = &s
|
||||
}
|
||||
|
||||
// PrintScanners prints all registered scanners
|
||||
func PrintScanners() {
|
||||
for k, v := range scanners {
|
||||
fmt.Println(k, v)
|
||||
}
|
||||
}
|
||||
|
||||
// this should be renamed?
|
||||
func RunModule(s Scanner, mon *Monitor, target ScanTarget) (string, ScanResponse) {
|
||||
t := time.Now()
|
||||
res, e := s.Scan(target, uint(22))
|
||||
var err *error //nil pointers are null in golang, which is not nil and not empty
|
||||
if e == nil {
|
||||
mon.statusesChan <- moduleStatus{name: s.GetName(), st: statusSuccess}
|
||||
err = nil
|
||||
} else {
|
||||
mon.statusesChan <- moduleStatus{name: s.GetName(), st: statusFailure}
|
||||
err = &e
|
||||
}
|
||||
resp := ScanResponse{Result: res, Error: err, Time: t.Format(time.RFC3339)}
|
||||
return s.GetName(), resp
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ func grabTarget(input ScanTarget, m *Monitor) []byte {
|
||||
|
||||
for _, scannerName := range orderedScanners {
|
||||
scanner := scanners[scannerName]
|
||||
name, res := RunModule(*scanner, m, input)
|
||||
name, res := RunScanner(*scanner, m, input)
|
||||
moduleResult[name] = res
|
||||
if res.Error != nil && !config.Multiple.ContinueOnError {
|
||||
break
|
||||
|
47
scanner.go
Normal file
47
scanner.go
Normal file
@ -0,0 +1,47 @@
|
||||
package zgrab2
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
var scanners map[string]*Scanner
|
||||
var orderedScanners []string
|
||||
|
||||
// RegisterScan registers each individual scanner to be ran by the framework
|
||||
func RegisterScan(name string, s Scanner) {
|
||||
//add to list and map
|
||||
if scanners[name] != nil {
|
||||
log.Fatalf("name: %s already used", name)
|
||||
}
|
||||
orderedScanners = append(orderedScanners, name)
|
||||
scanners[name] = &s
|
||||
}
|
||||
|
||||
// PrintScanners prints all registered scanners
|
||||
func PrintScanners() {
|
||||
for k, v := range scanners {
|
||||
fmt.Println(k, v)
|
||||
}
|
||||
}
|
||||
|
||||
// RunScanner runs a single scan on a target and returns the resulting data
|
||||
func RunScanner(s Scanner, mon *Monitor, target ScanTarget) (string, ScanResponse) {
|
||||
t := time.Now()
|
||||
res, e := s.Scan(target, uint(22))
|
||||
var err *error //nil pointers are null in golang, which is not nil and not empty
|
||||
if e == nil {
|
||||
mon.statusesChan <- moduleStatus{name: s.GetName(), st: statusSuccess}
|
||||
err = nil
|
||||
} else {
|
||||
mon.statusesChan <- moduleStatus{name: s.GetName(), st: statusFailure}
|
||||
err = &e
|
||||
}
|
||||
resp := ScanResponse{Result: res, Error: err, Time: t.Format(time.RFC3339)}
|
||||
return s.GetName(), resp
|
||||
}
|
||||
|
||||
func init() {
|
||||
scanners = make(map[string]*Scanner)
|
||||
}
|
Loading…
Reference in New Issue
Block a user