mirror of
https://github.com/bettercap/bettercap
synced 2025-07-11 07:37:00 -07:00
new: implemented '!shell-command' session command (closes #18)
This commit is contained in:
parent
63761b0254
commit
9f31cfa4b9
3 changed files with 24 additions and 0 deletions
5
core/core_unix.go
Normal file
5
core/core_unix.go
Normal 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
5
core/core_windows.go
Normal file
|
@ -0,0 +1,5 @@
|
|||
package core
|
||||
|
||||
func Shell(cmd string) (string, error) {
|
||||
return Exec("cmd.exe", []string{"/c", cmd})
|
||||
}
|
|
@ -165,6 +165,14 @@ func (s *Session) includeHandler(args []string, sess *Session) error {
|
|||
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) {
|
||||
h.Completer = c
|
||||
s.CoreHandlers = append(s.CoreHandlers, h)
|
||||
|
@ -254,4 +262,10 @@ func (s *Session) registerCoreHandlers() {
|
|||
files, _ = filepath.Glob(prefix + "*")
|
||||
return files
|
||||
})))
|
||||
|
||||
s.addHandler(NewCommandHandler("! COMMAND",
|
||||
"^!\\s*(.+)$",
|
||||
"Execute a shell command and print its output.",
|
||||
s.shHandler),
|
||||
readline.PcItem("!"))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue