1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
package caplets
import (
"fmt"
"github.com/bettercap/bettercap/caplets"
"github.com/bettercap/bettercap/session"
"github.com/dustin/go-humanize"
"github.com/evilsocket/islazy/tui"
)
type CapletsModule struct {
session.SessionModule
}
func NewCapletsModule(s *session.Session) *CapletsModule {
mod := &CapletsModule{
SessionModule: session.NewSessionModule("caplets", s),
}
mod.AddHandler(session.NewModuleHandler("caplets.show", "",
"Show a list of installed caplets.",
func(args []string) error {
return mod.Show()
}))
mod.AddHandler(session.NewModuleHandler("caplets.paths", "",
"Show a list caplet search paths.",
func(args []string) error {
return mod.Paths()
}))
mod.AddHandler(session.NewModuleHandler("caplets.update", "",
"Install/updates the caplets.",
func(args []string) error {
return mod.Update()
}))
return mod
}
func (mod *CapletsModule) Name() string {
return "caplets"
}
func (mod *CapletsModule) Description() string {
return "A module to list caplets."
}
func (mod *CapletsModule) Author() string {
return "Simone Margaritelli <evilsocket@gmail.com>"
}
func (mod *CapletsModule) Configure() error {
return nil
}
func (mod *CapletsModule) Stop() error {
return nil
}
func (mod *CapletsModule) Start() error {
return nil
}
func (mod *CapletsModule) Show() error {
caplets := caplets.List()
if len(caplets) == 0 {
return fmt.Errorf("no installed caplets on this system, in Debian install bettercap-caplets package")
}
colNames := []string{
"Name",
"Path",
"Size",
}
rows := [][]string{}
for _, caplet := range caplets {
rows = append(rows, []string{
tui.Bold(caplet.Name),
caplet.Path,
tui.Dim(humanize.Bytes(uint64(caplet.Size))),
})
}
tui.Table(mod.Session.Events.Stdout, colNames, rows)
return nil
}
func (mod *CapletsModule) Paths() error {
colNames := []string{
"Path",
}
rows := [][]string{}
for _, path := range caplets.LoadPaths {
rows = append(rows, []string{path})
}
tui.Table(mod.Session.Events.Stdout, colNames, rows)
mod.Printf("(paths can be customized by defining the %s environment variable)\n", tui.Bold(caplets.EnvVarName))
return nil
}
func (mod *CapletsModule) Update() error {
mod.Info("this command is inactive in Debian. Install the Debian package bettercap-caplets to get the caplets")
return nil
}
|