new: implemented '!shell-command' session command (closes #18)

This commit is contained in:
evilsocket 2018-01-16 10:10:56 +01:00
parent 63761b0254
commit 9f31cfa4b9
3 changed files with 24 additions and 0 deletions

5
core/core_unix.go Normal file
View file

@ -0,0 +1,5 @@
package core
func Shell(cmd string) (string, error) {
return Exec("/bin/sh", []string{"-c", cmd})
}

5
core/core_windows.go Normal file
View file

@ -0,0 +1,5 @@
package core
func Shell(cmd string) (string, error) {
return Exec("cmd.exe", []string{"/c", cmd})
}

View file

@ -165,6 +165,14 @@ func (s *Session) includeHandler(args []string, sess *Session) error {
return s.RunCaplet(args[0]) return s.RunCaplet(args[0])
} }
func (s *Session) shHandler(args []string, sess *Session) error {
out, err := core.Shell(args[0])
if err == nil {
fmt.Printf("%s\n", out)
}
return err
}
func (s *Session) addHandler(h CommandHandler, c *readline.PrefixCompleter) { func (s *Session) addHandler(h CommandHandler, c *readline.PrefixCompleter) {
h.Completer = c h.Completer = c
s.CoreHandlers = append(s.CoreHandlers, h) s.CoreHandlers = append(s.CoreHandlers, h)
@ -254,4 +262,10 @@ func (s *Session) registerCoreHandlers() {
files, _ = filepath.Glob(prefix + "*") files, _ = filepath.Glob(prefix + "*")
return files return files
}))) })))
s.addHandler(NewCommandHandler("! COMMAND",
"^!\\s*(.+)$",
"Execute a shell command and print its output.",
s.shHandler),
readline.PcItem("!"))
} }