Documentation ¶
Overview ¶
Package session contains code to manage the interactive session, modules, environment, etc.
Index ¶
- Constants
- Variables
- func AsTag(name string) string
- func ErrAlreadyStarted(name string) error
- func ErrAlreadyStopped(name string) error
- func ParseCommands(line string) []string
- type CommandHandler
- type Environment
- func (env *Environment) Get(name string) (bool, string)
- func (env *Environment) GetInt(name string) (error, int)
- func (env *Environment) GetUnlocked(name string) (bool, string)
- func (env *Environment) Has(name string) bool
- func (env *Environment) Load(fileName string) error
- func (env *Environment) Save(fileName string) error
- func (env *Environment) Set(name, value string) string
- func (env *Environment) Sorted() []string
- func (env *Environment) WithCallback(name, value string, cb EnvironmentChangedCallback) string
- type EnvironmentChangedCallback
- type Event
- type EventPool
- func (p *EventPool) Add(tag string, data interface{})
- func (p *EventPool) Clear()
- func (p *EventPool) Listen() <-chan Event
- func (p *EventPool) Log(level log.Verbosity, format string, args ...interface{})
- func (p *EventPool) SetDebug(d bool)
- func (p *EventPool) SetSilent(s bool)
- func (p *EventPool) Sorted() []Event
- func (p *EventPool) Unlisten(listener <-chan Event)
- type EventsIgnoreList
- func (l *EventsIgnoreList) Add(expr string) (err error)
- func (l *EventsIgnoreList) Clear()
- func (l *EventsIgnoreList) Empty() bool
- func (l *EventsIgnoreList) Filters() []filter
- func (l *EventsIgnoreList) Ignored(e Event) bool
- func (l *EventsIgnoreList) MarshalJSON() ([]byte, error)
- func (l *EventsIgnoreList) Remove(expr string) (err error)
- type GPS
- type JSONModuleHandler
- type JSONModuleParam
- type LogMessage
- type Module
- type ModuleHandler
- type ModuleList
- type ModuleParam
- func NewBoolParameter(name string, def_value string, desc string) *ModuleParam
- func NewDecimalParameter(name string, def_value string, desc string) *ModuleParam
- func NewIntParameter(name string, def_value string, desc string) *ModuleParam
- func NewModuleParameter(name string, def_value string, t ParamType, validator string, desc string) *ModuleParam
- func NewStringParameter(name string, def_value string, validator string, desc string) *ModuleParam
- type ParamType
- type Prompt
- type Session
- func (s *Session) BLECompleter(prefix string) []string
- func (s *Session) Close()
- func (s *Session) EventsCompleter(prefix string) []string
- func (s *Session) FindMAC(ip net.IP, probe bool) (net.HardwareAddr, error)
- func (s *Session) HIDCompleter(prefix string) []string
- func (s *Session) IsOn(moduleName string) bool
- func (s *Session) LANCompleter(prefix string) []string
- func (s *Session) Lock()
- func (s *Session) MarshalJSON() ([]byte, error)
- func (s *Session) Module(name string) (err error, mod Module)
- func (s *Session) ReadLine() (string, error)
- func (s *Session) Refresh()
- func (s *Session) Register(mod Module) error
- func (s *Session) Run(line string) error
- func (s *Session) RunCaplet(filename string) error
- func (s *Session) Skip(ip net.IP) bool
- func (s *Session) Start() error
- func (s *Session) Unlock()
- func (s *Session) WiFiCompleter(prefix string) []string
- func (s *Session) WiFiCompleterFull(prefix string) []string
- type SessionJSON
- type SessionModule
- func (m *SessionModule) AddHandler(h ModuleHandler)
- func (m *SessionModule) AddParam(p *ModuleParam) *ModuleParam
- func (m SessionModule) BoolParam(name string) (error, bool)
- func (m *SessionModule) Debug(format string, args ...interface{})
- func (m SessionModule) DecParam(name string) (error, float64)
- func (m *SessionModule) Error(format string, args ...interface{})
- func (m *SessionModule) Extra() map[string]interface{}
- func (m *SessionModule) Fatal(format string, args ...interface{})
- func (m *SessionModule) Handlers() []ModuleHandler
- func (m SessionModule) IPParam(name string) (error, net.IP)
- func (m *SessionModule) Info(format string, args ...interface{})
- func (m *SessionModule) InitState(keys ...string)
- func (m SessionModule) IntParam(name string) (error, int)
- func (m SessionModule) ListParam(name string) (err error, values []string)
- func (m *SessionModule) Param(name string) *ModuleParam
- func (m *SessionModule) Parameters() map[string]*ModuleParam
- func (m *SessionModule) Required() []string
- func (m *SessionModule) Requires(modName string)
- func (m *SessionModule) ResetState()
- func (m *SessionModule) Running() bool
- func (m *SessionModule) SetRunning(running bool, cb func()) error
- func (m SessionModule) StringParam(name string) (error, string)
- func (m *SessionModule) Warning(format string, args ...interface{})
- type UnknownCommandCallback
Constants ¶
View Source
const ( IPv4Validator = `^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$` IPv6Validator = `^[:a-fA-F0-9]{6,}$` )
View Source
const ( PromptVariable = "$" DefaultPrompt = "{by}{fw}{cidr} {fb}> {env.iface.ipv4} {reset} {bold}» {reset}" DefaultPromptMonitor = "{by}{fb} {env.iface.name} {reset} {bold}» {reset}" )
View Source
const AliasesFile = "~/bettercap.aliases"
View Source
const (
HistoryFile = "~/bettercap.history"
)
View Source
const ParamIfaceAddress = "<interface address>"
View Source
const ParamIfaceAddress6 = "<interface address6>"
View Source
const ParamIfaceName = "<interface name>"
View Source
const ParamRandomMAC = "<random mac>"
View Source
const ParamSubnet = "<entire subnet>"
Variables ¶
View Source
var ( I = (*Session)(nil) ErrNotSupported = errors.New("this component is not supported on this OS") )
View Source
var (
ErrEmptyExpression = errors.New("expression can not be empty")
)
View Source
var ( PromptCallbacks = map[string]func(s *Session) string{ "{cidr}": func(s *Session) string { return s.Interface.CIDR() }, "{net.sent}": func(s *Session) string { return fmt.Sprintf("%d", s.Queue.Stats.Sent) }, "{net.sent.human}": func(s *Session) string { return humanize.Bytes(s.Queue.Stats.Sent) }, "{net.received}": func(s *Session) string { return fmt.Sprintf("%d", s.Queue.Stats.Received) }, "{net.received.human}": func(s *Session) string { return humanize.Bytes(s.Queue.Stats.Received) }, "{net.packets}": func(s *Session) string { return fmt.Sprintf("%d", s.Queue.Stats.PktReceived) }, "{net.errors}": func(s *Session) string { return fmt.Sprintf("%d", s.Queue.Stats.Errors) }, } )
Functions ¶
func ErrAlreadyStarted ¶
func ErrAlreadyStopped ¶
func ParseCommands ¶
Types ¶
type CommandHandler ¶
type CommandHandler struct { sync.Mutex Name string Description string Completer *readline.PrefixCompleter Parser *regexp.Regexp // contains filtered or unexported fields }
func NewCommandHandler ¶
type Environment ¶
type Environment struct { sync.Mutex Data map[string]string `json:"data"` // contains filtered or unexported fields }
func NewEnvironment ¶
func NewEnvironment(envFile string) (*Environment, error)
func (*Environment) GetUnlocked ¶
func (env *Environment) GetUnlocked(name string) (bool, string)
func (*Environment) Has ¶
func (env *Environment) Has(name string) bool
func (*Environment) Load ¶
func (env *Environment) Load(fileName string) error
func (*Environment) Save ¶
func (env *Environment) Save(fileName string) error
func (*Environment) Set ¶
func (env *Environment) Set(name, value string) string
func (*Environment) Sorted ¶
func (env *Environment) Sorted() []string
func (*Environment) WithCallback ¶
func (env *Environment) WithCallback(name, value string, cb EnvironmentChangedCallback) string
type EnvironmentChangedCallback ¶
type EnvironmentChangedCallback func(newValue string)
type Event ¶
type EventsIgnoreList ¶
func NewEventsIgnoreList ¶
func NewEventsIgnoreList() *EventsIgnoreList
func (*EventsIgnoreList) Add ¶
func (l *EventsIgnoreList) Add(expr string) (err error)
func (*EventsIgnoreList) Clear ¶
func (l *EventsIgnoreList) Clear()
func (*EventsIgnoreList) Empty ¶
func (l *EventsIgnoreList) Empty() bool
func (*EventsIgnoreList) Filters ¶
func (l *EventsIgnoreList) Filters() []filter
func (*EventsIgnoreList) Ignored ¶
func (l *EventsIgnoreList) Ignored(e Event) bool
func (*EventsIgnoreList) MarshalJSON ¶
func (l *EventsIgnoreList) MarshalJSON() ([]byte, error)
func (*EventsIgnoreList) Remove ¶
func (l *EventsIgnoreList) Remove(expr string) (err error)
type GPS ¶
type GPS struct { Updated time.Time Latitude float64 // Latitude. Longitude float64 // Longitude. FixQuality string // Quality of fix. NumSatellites int64 // Number of satellites in use. HDOP float64 // Horizontal dilution of precision. Altitude float64 // Altitude. Separation float64 // Geoidal separation }
type JSONModuleHandler ¶
type JSONModuleParam ¶
type LogMessage ¶
type ModuleHandler ¶
type ModuleHandler struct { sync.Mutex Name string Description string Parser *regexp.Regexp Completer *readline.PrefixCompleter // contains filtered or unexported fields }
func NewModuleHandler ¶
func (*ModuleHandler) Complete ¶
func (h *ModuleHandler) Complete(name string, cb func(prefix string) []string)
func (*ModuleHandler) Exec ¶
func (h *ModuleHandler) Exec(args []string) error
func (*ModuleHandler) Help ¶
func (h *ModuleHandler) Help(padding int) string
func (ModuleHandler) MarshalJSON ¶
func (h ModuleHandler) MarshalJSON() ([]byte, error)
type ModuleList ¶
type ModuleList []Module
func (ModuleList) MarshalJSON ¶
func (mm ModuleList) MarshalJSON() ([]byte, error)
type ModuleParam ¶
type ModuleParam struct { Name string Type ParamType Value string Description string Validator *regexp.Regexp }
func NewBoolParameter ¶
func NewBoolParameter(name string, def_value string, desc string) *ModuleParam
func NewDecimalParameter ¶
func NewDecimalParameter(name string, def_value string, desc string) *ModuleParam
func NewIntParameter ¶
func NewIntParameter(name string, def_value string, desc string) *ModuleParam
func NewModuleParameter ¶
func NewStringParameter ¶
func NewStringParameter(name string, def_value string, validator string, desc string) *ModuleParam
func (ModuleParam) Get ¶
func (p ModuleParam) Get(s *Session) (error, interface{})
func (ModuleParam) Help ¶
func (p ModuleParam) Help(padding int) string
func (ModuleParam) MarshalJSON ¶
func (p ModuleParam) MarshalJSON() ([]byte, error)
func (ModuleParam) Register ¶
func (p ModuleParam) Register(s *Session)
func (ModuleParam) Validate ¶
func (p ModuleParam) Validate(value string) (error, interface{})
type Session ¶
type Session struct { Options core.Options Interface *network.Endpoint Gateway *network.Endpoint Env *Environment Lan *network.LAN WiFi *network.WiFi BLE *network.BLE HID *network.HID Queue *packets.Queue StartedAt time.Time Active bool GPS GPS Modules ModuleList Aliases *data.UnsortedKV Input *readline.Instance Prompt Prompt CoreHandlers []CommandHandler Events *EventPool EventsIgnoreList *EventsIgnoreList UnkCmdCallback UnknownCommandCallback Firewall firewall.FirewallManager }
func (*Session) BLECompleter ¶
func (*Session) EventsCompleter ¶
func (*Session) HIDCompleter ¶
func (*Session) LANCompleter ¶
func (*Session) MarshalJSON ¶
func (*Session) WiFiCompleter ¶
func (*Session) WiFiCompleterFull ¶
type SessionJSON ¶
type SessionJSON struct { Version string `json:"version"` OS string `json:"os"` Arch string `json:"arch"` GoVersion string `json:"goversion"` Resources resourcesJSON `json:"resources"` Interfaces []ifaceJSON `json:"interfaces"` Options core.Options `json:"options"` Interface *network.Endpoint `json:"interface"` Gateway *network.Endpoint `json:"gateway"` Env *Environment `json:"env"` Lan *network.LAN `json:"lan"` WiFi *network.WiFi `json:"wifi"` BLE *network.BLE `json:"ble"` HID *network.HID `json:"hid"` Queue *packets.Queue `json:"packets"` StartedAt time.Time `json:"started_at"` PolledAt time.Time `json:"polled_at"` Active bool `json:"active"` GPS GPS `json:"gps"` Modules ModuleList `json:"modules"` Caplets []*caplets.Caplet `json:"caplets"` }
type SessionModule ¶
type SessionModule struct { Name string Session *Session Started bool StatusLock *sync.RWMutex State *sync.Map // contains filtered or unexported fields }
func NewSessionModule ¶
func NewSessionModule(name string, s *Session) SessionModule
func (*SessionModule) AddHandler ¶
func (m *SessionModule) AddHandler(h ModuleHandler)
func (*SessionModule) AddParam ¶
func (m *SessionModule) AddParam(p *ModuleParam) *ModuleParam
func (*SessionModule) Debug ¶
func (m *SessionModule) Debug(format string, args ...interface{})
func (*SessionModule) Error ¶
func (m *SessionModule) Error(format string, args ...interface{})
func (*SessionModule) Extra ¶
func (m *SessionModule) Extra() map[string]interface{}
func (*SessionModule) Fatal ¶
func (m *SessionModule) Fatal(format string, args ...interface{})
func (*SessionModule) Handlers ¶
func (m *SessionModule) Handlers() []ModuleHandler
func (*SessionModule) Info ¶
func (m *SessionModule) Info(format string, args ...interface{})
func (*SessionModule) InitState ¶
func (m *SessionModule) InitState(keys ...string)
func (SessionModule) ListParam ¶
func (m SessionModule) ListParam(name string) (err error, values []string)
func (*SessionModule) Param ¶
func (m *SessionModule) Param(name string) *ModuleParam
func (*SessionModule) Parameters ¶
func (m *SessionModule) Parameters() map[string]*ModuleParam
func (*SessionModule) Required ¶
func (m *SessionModule) Required() []string
func (*SessionModule) Requires ¶
func (m *SessionModule) Requires(modName string)
func (*SessionModule) ResetState ¶
func (m *SessionModule) ResetState()
func (*SessionModule) Running ¶
func (m *SessionModule) Running() bool
func (*SessionModule) SetRunning ¶
func (m *SessionModule) SetRunning(running bool, cb func()) error
func (SessionModule) StringParam ¶
func (m SessionModule) StringParam(name string) (error, string)
func (*SessionModule) Warning ¶
func (m *SessionModule) Warning(format string, args ...interface{})
type UnknownCommandCallback ¶
Click to show internal directories.
Click to hide internal directories.