-
Notifications
You must be signed in to change notification settings - Fork 316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ModuleSet object #247
Merged
Merged
Add ModuleSet object #247
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package bin | ||
|
||
import ( | ||
"github.com/zmap/zgrab2" | ||
"github.com/zmap/zgrab2/modules" | ||
"github.com/zmap/zgrab2/modules/bacnet" | ||
"github.com/zmap/zgrab2/modules/banner" | ||
"github.com/zmap/zgrab2/modules/dnp3" | ||
"github.com/zmap/zgrab2/modules/fox" | ||
"github.com/zmap/zgrab2/modules/ftp" | ||
"github.com/zmap/zgrab2/modules/http" | ||
"github.com/zmap/zgrab2/modules/imap" | ||
"github.com/zmap/zgrab2/modules/ipp" | ||
"github.com/zmap/zgrab2/modules/modbus" | ||
"github.com/zmap/zgrab2/modules/mongodb" | ||
"github.com/zmap/zgrab2/modules/mssql" | ||
"github.com/zmap/zgrab2/modules/mysql" | ||
"github.com/zmap/zgrab2/modules/ntp" | ||
"github.com/zmap/zgrab2/modules/oracle" | ||
"github.com/zmap/zgrab2/modules/pop3" | ||
"github.com/zmap/zgrab2/modules/postgres" | ||
"github.com/zmap/zgrab2/modules/redis" | ||
"github.com/zmap/zgrab2/modules/siemens" | ||
"github.com/zmap/zgrab2/modules/smb" | ||
"github.com/zmap/zgrab2/modules/smtp" | ||
"github.com/zmap/zgrab2/modules/telnet" | ||
) | ||
|
||
var defaultModules zgrab2.ModuleSet | ||
|
||
func init() { | ||
defaultModules = map[string]zgrab2.ScanModule{ | ||
"bacnet": &bacnet.Module{}, | ||
"banner": &banner.Module{}, | ||
"dnp3": &dnp3.Module{}, | ||
"fox": &fox.Module{}, | ||
"ftp": &ftp.Module{}, | ||
"http": &http.Module{}, | ||
"imap": &imap.Module{}, | ||
"ipp": &ipp.Module{}, | ||
"modbus": &modbus.Module{}, | ||
"mongodb": &mongodb.Module{}, | ||
"mssql": &mssql.Module{}, | ||
"mysql": &mysql.Module{}, | ||
"ntp": &ntp.Module{}, | ||
"oracle": &oracle.Module{}, | ||
"pop3": &pop3.Module{}, | ||
"postgres": &postgres.Module{}, | ||
"redis": &redis.Module{}, | ||
"siemens": &siemens.Module{}, | ||
"smb": &smb.Module{}, | ||
"smtp": &smtp.Module{}, | ||
"ssh": &modules.SSHModule{}, | ||
"telnet": &telnet.Module{}, | ||
"tls": &modules.TLSModule{}, | ||
} | ||
} | ||
|
||
// NewModuleSetWithDefaults returns a newly allocated ModuleSet containing all | ||
// ScanModules implemented by the ZGrab2 framework. | ||
func NewModuleSetWithDefaults() zgrab2.ModuleSet { | ||
out := zgrab2.ModuleSet{} | ||
defaultModules.CopyInto(out) | ||
return out | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Package bin contains functions useful for creating a binary version of | ||
// ZGrab2. | ||
// | ||
// This package can import "github.com/zmap/zgrab2", and should be imported by | ||
// targets within "github.com/zmap/zgrab2/cmd" | ||
package bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package zgrab2 | ||
|
||
// ModuleSet is a container holding named scan modules. It is a wrapper around a | ||
// map. | ||
type ModuleSet map[string]ScanModule | ||
|
||
// AddModule adds m to the ModuleSet, accessible via the given name. If the name | ||
// is already in the ModuleSet, it is overwritten. | ||
func (s ModuleSet) AddModule(name string, m ScanModule) { | ||
s[name] = m | ||
} | ||
|
||
// RemoveModule removes the module at the specified name. If the name is not in | ||
// the module set, nothing happens. | ||
func (s ModuleSet) RemoveModule(name string) { | ||
delete(s, name) | ||
} | ||
|
||
// CopyInto copies the modules in s to destination. The sets will be unique, but | ||
// the underlying ScanModule instances will be the same. | ||
func (s ModuleSet) CopyInto(destination ModuleSet) { | ||
for name, m := range s { | ||
destination[name] = m | ||
} | ||
} | ||
|
||
// NewModuleSet returns an empty ModuleSet. | ||
func NewModuleSet() ModuleSet { | ||
return make(ModuleSet) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is ever going to be a possible writer and reader that access the map concurrently, ModuleSet should be a struct that contains a
sync.Mutex
to guard the map. e.g.,And then of course the methods can all do s.Lock() / s.Unlock() as appropriate.