new: http and https proxy modules can now define an onCommand callback to handle custom session commands (closes #182)

This commit is contained in:
evilsocket 2018-03-19 18:02:43 +01:00
commit 86ba73f5bb
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
3 changed files with 59 additions and 5 deletions

View file

@ -37,6 +37,8 @@ var (
reCmdSpaceCleaner = regexp.MustCompile(`^([^\s]+)\s+(.+)$`)
)
type UnknownCommandCallback func(cmd string) bool
type Session struct {
Options core.Options `json:"options"`
Interface *network.Endpoint `json:"interface"`
@ -57,6 +59,8 @@ type Session struct {
Modules []Module `json:"-"`
Events *EventPool `json:"-"`
UnkCmdCallback UnknownCommandCallback `json:"-"`
}
func ParseCommands(line string) []string {
@ -132,9 +136,10 @@ func New() (*Session, error) {
Active: false,
Queue: nil,
CoreHandlers: make([]CommandHandler, 0),
Modules: make([]Module, 0),
Events: nil,
CoreHandlers: make([]CommandHandler, 0),
Modules: make([]Module, 0),
Events: nil,
UnkCmdCallback: nil,
}
if s.Options, err = core.ParseOptions(); err != nil {
@ -501,5 +506,9 @@ func (s *Session) Run(line string) error {
}
}
if s.UnkCmdCallback != nil && s.UnkCmdCallback(line) == true {
return nil
}
return fmt.Errorf("Unknown or invalid syntax \"%s%s%s\", type %shelp%s for the help menu.", core.BOLD, line, core.RESET, core.BOLD, core.RESET)
}