Skip to content

Adding new modules

justinbastress edited this page Feb 7, 2018 · 3 revisions

Modules are added by calling zgrab2.AddCommand("<module-id>", "<module-display-name>", "<module description>", <module default port>, &theModule), where theModule is an instance of the appropriate Module implementation.

A typical module will consist in the following files:

  • modules/<module-id>/scanner.go: Package documentation should describe the protocol, the input flags, what the scan does, and the output format. The body should provide the following:
    • Flags: Implements zgrab2.ScanFlags. Defines the input arguments from the command line.
      • All modules should include zgrab2.BaseFlags
      • Modules that implement TLS should include zgrab2.TLSFlags
    • Module: Implements zgrab2.ScanModule
      • Module.NewFlags() should return a pointer to a new default Flags instance
      • Module.NewScanner() should return a pointer to a new default Scanner instance
    • Scanner: Implements zgrab2.Scanner
      • Scanner.Init() receives the parsed ScanFlags (this can be cast to the module-specific *Flags)
      • Scanner.Scan() is invoked for each host being scanned. If the scan fails to detect the target protocol, it should return nil for the ScanResults. Otherwise, it should return a pointer to a (maybe only partially filled) ScanResults instance.
    • ScanResults: This will be returned by the Scanner.Scan() method and JSON-encoded in the output.
      • Ideally, this should provide both a MarshalJSON() and an UnmarshalJSON() method (if the defaults are not sufficient)
      • This should be query-friendly
        • No unconstrained map[string]strings
        • No cycles
      • The schemas/<module-id>.py should
    • RegisterModule(): A function that calls zgrab2.AddModule() on a module instance.
  • modules/<module-id>.go: Calls <module>.RegisterModule() in its init() function.
  • schemas/<module-id>.py:

Clone this wiki locally