Scanner modules return the protocol ID, scan returns the protocol in the results.

This commit is contained in:
Justin Bastress 2018-03-12 13:36:11 -04:00
parent 7eb3536b19
commit 17a5c0e85c
13 changed files with 62 additions and 3 deletions

@ -85,6 +85,11 @@ func (scanner *Scanner) GetName() string {
return scanner.config.Name return scanner.config.Name
} }
// Protocol returns the protocol identifier of the scan.
func (scanner *Scanner) Protocol() string {
return "#{MODULE_NAME}"
}
// GetPort returns the port being scanned. // GetPort returns the port being scanned.
func (scanner *Scanner) GetPort() uint { func (scanner *Scanner) GetPort() uint {
return scanner.config.Port return scanner.config.Port

@ -12,14 +12,22 @@ type Scanner interface {
// Returns the name passed at init // Returns the name passed at init
GetName() string GetName() string
// Protocol returns the protocol identifier for the scan.
Protocol() string
// Scan connects to a host. The result should be JSON-serializable // Scan connects to a host. The result should be JSON-serializable
Scan(t ScanTarget) (ScanStatus, interface{}, error) Scan(t ScanTarget) (ScanStatus, interface{}, error)
} }
// ScanResponse is the result of a scan on a single host // ScanResponse is the result of a scan on a single host
type ScanResponse struct { type ScanResponse struct {
// Status is required for all responses. Other fields are optional. // Status is required for all responses.
Status ScanStatus `json:"status"` 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"` Result interface{} `json:"result,omitempty"`
Timestamp string `json:"timestamp,omitempty"` Timestamp string `json:"timestamp,omitempty"`
Error *string `json:"error,omitempty"` Error *string `json:"error,omitempty"`

@ -98,6 +98,11 @@ func (f *Flags) Help() string {
return "" return ""
} }
// Protocol returns the protocol identifer for the scanner.
func (s *Scanner) Protocol() string {
return "ftp"
}
// Init initializes the Scanner instance with the flags from the command // Init initializes the Scanner instance with the flags from the command
// line. // line.
func (s *Scanner) Init(flags zgrab2.ScanFlags) error { func (s *Scanner) Init(flags zgrab2.ScanFlags) error {

@ -104,6 +104,11 @@ func (flags *Flags) Help() string {
return "" return ""
} }
// Protocol returns the protocol identifer for the scanner.
func (s *Scanner) Protocol() string {
return "http"
}
// Init initializes the scanner with the given flags // Init initializes the scanner with the given flags
func (scanner *Scanner) Init(flags zgrab2.ScanFlags) error { func (scanner *Scanner) Init(flags zgrab2.ScanFlags) error {
fl, _ := flags.(*Flags) fl, _ := flags.(*Flags)

@ -85,6 +85,11 @@ func (scanner *Scanner) InitPerSender(senderID int) error {
return nil return nil
} }
// Protocol returns the protocol identifer for the scanner.
func (s *Scanner) Protocol() string {
return "mssql"
}
// GetName returns the configured scanner name. // GetName returns the configured scanner name.
func (scanner *Scanner) GetName() string { func (scanner *Scanner) GetName() string {
return scanner.config.Name return scanner.config.Name

@ -176,6 +176,11 @@ func (s *Scanner) InitPerSender(senderID int) error {
return nil return nil
} }
// Protocol returns the protocol identifer for the scanner.
func (s *Scanner) Protocol() string {
return "mysql"
}
// GetName returns the name from the command line flags. // GetName returns the name from the command line flags.
func (s *Scanner) GetName() string { func (s *Scanner) GetName() string {
return s.config.Name return s.config.Name

@ -853,6 +853,11 @@ func (scanner *Scanner) InitPerSender(senderID int) error {
return nil return nil
} }
// Protocol returns the protocol identifer for the scanner.
func (s *Scanner) Protocol() string {
return "ntp"
}
// GetName returns the module's name // GetName returns the module's name
func (scanner *Scanner) GetName() string { func (scanner *Scanner) GetName() string {
return scanner.config.Name return scanner.config.Name

@ -288,6 +288,11 @@ func (s *Scanner) InitPerSender(senderID int) error {
return nil return nil
} }
// Protocol returns the protocol identifer for the scanner.
func (s *Scanner) Protocol() string {
return "postgres"
}
// GetName returns the name from the parameters. // GetName returns the name from the parameters.
func (s *Scanner) GetName() string { func (s *Scanner) GetName() string {
return s.Config.Name return s.Config.Name

@ -195,6 +195,11 @@ func forceToString(val RedisValue) string {
} }
} }
// Protocol returns the protocol identifer for the scanner.
func (s *Scanner) Protocol() string {
return "redis"
}
// Scan executes the following commands: // Scan executes the following commands:
// 1. PING // 1. PING
// 2. (only if --password is provided) AUTH <password> // 2. (only if --password is provided) AUTH <password>

@ -102,3 +102,8 @@ func (s *SSHScanner) Scan(t zgrab2.ScanTarget) (zgrab2.ScanStatus, interface{},
status := zgrab2.TryGetScanStatus(err) status := zgrab2.TryGetScanStatus(err)
return status, data, err return status, data, err
} }
// Protocol returns the protocol identifer for the scanner.
func (s *SSHScanner) Protocol() string {
return "ssh"
}

@ -73,3 +73,8 @@ func (s *TLSScanner) Scan(t zgrab2.ScanTarget) (zgrab2.ScanStatus, interface{},
} }
return zgrab2.SCAN_SUCCESS, result, nil return zgrab2.SCAN_SUCCESS, result, nil
} }
// Protocol returns the protocol identifer for the scanner.
func (s *TLSScanner) Protocol() string {
return "tls"
}

@ -39,7 +39,7 @@ func RunScanner(s Scanner, mon *Monitor, target ScanTarget) (string, ScanRespons
errString := e.Error() errString := e.Error()
err = &errString err = &errString
} }
resp := ScanResponse{Result: res, Error: err, Timestamp: t.Format(time.RFC3339), Status: status} resp := ScanResponse{Result: res, Protocol: s.Protocol(), Error: err, Timestamp: t.Format(time.RFC3339), Status: status}
return s.GetName(), resp return s.GetName(), resp
} }

@ -40,6 +40,7 @@ STATUS_VALUES = [
# zgrab2/module.go: ScanResponse # zgrab2/module.go: ScanResponse
base_scan_response = SubRecord({ base_scan_response = SubRecord({
"status": Enum(values = STATUS_VALUES, required = True), "status": Enum(values = STATUS_VALUES, required = True),
"protocol": String(required = True),
"timestamp": DateTime(required = True), "timestamp": DateTime(required = True),
"result": SubRecord({}, required = False), # This is overridden by the protocols' implementations "result": SubRecord({}, required = False), # This is overridden by the protocols' implementations
"error": String(required = False) "error": String(required = False)