bettercap: github.com/bettercap/bettercap/session Index | Files

package session

import "github.com/bettercap/bettercap/session"

Package session contains code to manage the interactive session, modules, environment, etc.

Index

Package Files

command_handler.go doc.go environment.go events.go events_ignore_list.go module.go module_handler.go module_param.go prompt.go session.go session_completers.go session_core_handlers.go session_json.go session_parse.go session_setup.go

Constants

const (
    IPv4Validator = `^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$`
    IPv6Validator = `^[:a-fA-F0-9]{6,}$`
)
const (
    STRING ParamType = iota
    BOOL             = iota
    INT              = iota
    FLOAT            = iota
)
const (
    PromptVariable       = "$"
    DefaultPrompt        = "{by}{fw}{cidr} {fb}> {env.iface.ipv4} {reset} {bold}» {reset}"
    DefaultPromptMonitor = "{by}{fb} {env.iface.name} {reset} {bold}» {reset}"
)
const AliasesFile = "~/bettercap.aliases"
const (
    HistoryFile = "~/bettercap.history"
)
const ParamIfaceAddress = "<interface address>"
const ParamIfaceAddress6 = "<interface address6>"
const ParamIfaceName = "<interface name>"
const ParamRandomMAC = "<random mac>"
const ParamSubnet = "<entire subnet>"

Variables

var (
    I   = (*Session)(nil)

    ErrNotSupported = errors.New("this component is not supported on this OS")
)
var (
    ErrEmptyExpression = errors.New("expression can not be empty")
)
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)
        },
    }
)

func AsTag Uses

func AsTag(name string) string

func ErrAlreadyStarted Uses

func ErrAlreadyStarted(name string) error

func ErrAlreadyStopped Uses

func ErrAlreadyStopped(name string) error

func ParseCommands Uses

func ParseCommands(line string) []string

type CommandHandler Uses

type CommandHandler struct {
    sync.Mutex
    Name        string
    Description string
    Completer   *readline.PrefixCompleter
    Parser      *regexp.Regexp
    // contains filtered or unexported fields
}

func NewCommandHandler Uses

func NewCommandHandler(name string, expr string, desc string, exec func(args []string, s *Session) error) CommandHandler

func (*CommandHandler) Exec Uses

func (h *CommandHandler) Exec(args []string, s *Session) error

func (*CommandHandler) Parse Uses

func (h *CommandHandler) Parse(line string) (bool, []string)

type Environment Uses

type Environment struct {
    sync.Mutex
    Data map[string]string `json:"data"`
    // contains filtered or unexported fields
}

func NewEnvironment Uses

func NewEnvironment(envFile string) (*Environment, error)

func (*Environment) Get Uses

func (env *Environment) Get(name string) (bool, string)

func (*Environment) GetInt Uses

func (env *Environment) GetInt(name string) (error, int)

func (*Environment) GetUnlocked Uses

func (env *Environment) GetUnlocked(name string) (bool, string)

func (*Environment) Has Uses

func (env *Environment) Has(name string) bool

func (*Environment) Load Uses

func (env *Environment) Load(fileName string) error

func (*Environment) Save Uses

func (env *Environment) Save(fileName string) error

func (*Environment) Set Uses

func (env *Environment) Set(name, value string) string

func (*Environment) Sorted Uses

func (env *Environment) Sorted() []string

func (*Environment) WithCallback Uses

func (env *Environment) WithCallback(name, value string, cb EnvironmentChangedCallback) string

type EnvironmentChangedCallback Uses

type EnvironmentChangedCallback func(newValue string)

type Event Uses

type Event struct {
    Tag  string      `json:"tag"`
    Time time.Time   `json:"time"`
    Data interface{} `json:"data"`
}

func NewEvent Uses

func NewEvent(tag string, data interface{}) Event

func (Event) Label Uses

func (e Event) Label() string

type EventPool Uses

type EventPool struct {
    sync.Mutex
    // contains filtered or unexported fields
}

func NewEventPool Uses

func NewEventPool(debug bool, silent bool) *EventPool

func (*EventPool) Add Uses

func (p *EventPool) Add(tag string, data interface{})

func (*EventPool) Clear Uses

func (p *EventPool) Clear()

func (*EventPool) Listen Uses

func (p *EventPool) Listen() <-chan Event

func (*EventPool) Log Uses

func (p *EventPool) Log(level log.Verbosity, format string, args ...interface{})

func (*EventPool) SetDebug Uses

func (p *EventPool) SetDebug(d bool)

func (*EventPool) SetSilent Uses

func (p *EventPool) SetSilent(s bool)

func (*EventPool) Sorted Uses

func (p *EventPool) Sorted() []Event

func (*EventPool) Unlisten Uses

func (p *EventPool) Unlisten(listener <-chan Event)

type EventsIgnoreList Uses

type EventsIgnoreList struct {
    sync.RWMutex
    // contains filtered or unexported fields
}

func NewEventsIgnoreList Uses

func NewEventsIgnoreList() *EventsIgnoreList

func (*EventsIgnoreList) Add Uses

func (l *EventsIgnoreList) Add(expr string) (err error)

func (*EventsIgnoreList) Clear Uses

func (l *EventsIgnoreList) Clear()

func (*EventsIgnoreList) Empty Uses

func (l *EventsIgnoreList) Empty() bool

func (*EventsIgnoreList) Filters Uses

func (l *EventsIgnoreList) Filters() []filter

func (*EventsIgnoreList) Ignored Uses

func (l *EventsIgnoreList) Ignored(e Event) bool

func (*EventsIgnoreList) MarshalJSON Uses

func (l *EventsIgnoreList) MarshalJSON() ([]byte, error)

func (*EventsIgnoreList) Remove Uses

func (l *EventsIgnoreList) Remove(expr string) (err error)

type GPS Uses

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 Uses

type JSONModuleHandler struct {
    Name        string `json:"name"`
    Description string `json:"description"`
    Parser      string `json:"parser"`
}

type JSONModuleParam Uses

type JSONModuleParam struct {
    Name        string    `json:"name"`
    Type        ParamType `json:"type"`
    Description string    `json:"description"`
    Value       string    `json:"default_value"`
    Current     string    `json:"current_value"`
    Validator   string    `json:"validator"`
}

type LogMessage Uses

type LogMessage struct {
    Level   log.Verbosity
    Message string
}

type Module Uses

type Module interface {
    Name() string
    Description() string
    Author() string
    Handlers() []ModuleHandler
    Parameters() map[string]*ModuleParam

    Extra() map[string]interface{}
    Required() []string
    Running() bool
    Start() error
    Stop() error
}

type ModuleHandler Uses

type ModuleHandler struct {
    sync.Mutex

    Name        string
    Description string
    Parser      *regexp.Regexp
    Completer   *readline.PrefixCompleter
    // contains filtered or unexported fields
}

func NewModuleHandler Uses

func NewModuleHandler(name string, expr string, desc string, exec func(args []string) error) ModuleHandler

func (*ModuleHandler) Complete Uses

func (h *ModuleHandler) Complete(name string, cb func(prefix string) []string)

func (*ModuleHandler) Exec Uses

func (h *ModuleHandler) Exec(args []string) error

func (*ModuleHandler) Help Uses

func (h *ModuleHandler) Help(padding int) string

func (ModuleHandler) MarshalJSON Uses

func (h ModuleHandler) MarshalJSON() ([]byte, error)

func (*ModuleHandler) Parse Uses

func (h *ModuleHandler) Parse(line string) (bool, []string)

type ModuleList Uses

type ModuleList []Module

func (ModuleList) MarshalJSON Uses

func (mm ModuleList) MarshalJSON() ([]byte, error)

type ModuleParam Uses

type ModuleParam struct {
    Name        string
    Type        ParamType
    Value       string
    Description string

    Validator *regexp.Regexp
}

func NewBoolParameter Uses

func NewBoolParameter(name string, def_value string, desc string) *ModuleParam

func NewDecimalParameter Uses

func NewDecimalParameter(name string, def_value string, desc string) *ModuleParam

func NewIntParameter Uses

func NewIntParameter(name string, def_value string, desc string) *ModuleParam

func NewModuleParameter Uses

func NewModuleParameter(name string, def_value string, t ParamType, validator string, desc string) *ModuleParam

func NewStringParameter Uses

func NewStringParameter(name string, def_value string, validator string, desc string) *ModuleParam

func (ModuleParam) Get Uses

func (p ModuleParam) Get(s *Session) (error, interface{})

func (ModuleParam) Help Uses

func (p ModuleParam) Help(padding int) string

func (ModuleParam) MarshalJSON Uses

func (p ModuleParam) MarshalJSON() ([]byte, error)

func (ModuleParam) Register Uses

func (p ModuleParam) Register(s *Session)

func (ModuleParam) Validate Uses

func (p ModuleParam) Validate(value string) (error, interface{})

type ParamType Uses

type ParamType int

type Prompt Uses

type Prompt struct {
}

func NewPrompt Uses

func NewPrompt() Prompt

func (Prompt) Render Uses

func (p Prompt) Render(s *Session) string

type Session Uses

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 New Uses

func New() (*Session, error)

func (*Session) BLECompleter Uses

func (s *Session) BLECompleter(prefix string) []string

func (*Session) Close Uses

func (s *Session) Close()

func (*Session) EventsCompleter Uses

func (s *Session) EventsCompleter(prefix string) []string

func (*Session) FindMAC Uses

func (s *Session) FindMAC(ip net.IP, probe bool) (net.HardwareAddr, error)

func (*Session) HIDCompleter Uses

func (s *Session) HIDCompleter(prefix string) []string

func (*Session) IsOn Uses

func (s *Session) IsOn(moduleName string) bool

func (*Session) LANCompleter Uses

func (s *Session) LANCompleter(prefix string) []string

func (*Session) Lock Uses

func (s *Session) Lock()

func (*Session) MarshalJSON Uses

func (s *Session) MarshalJSON() ([]byte, error)

func (*Session) Module Uses

func (s *Session) Module(name string) (err error, mod Module)

func (*Session) ReadLine Uses

func (s *Session) ReadLine() (string, error)

func (*Session) Refresh Uses

func (s *Session) Refresh()

func (*Session) Register Uses

func (s *Session) Register(mod Module) error

func (*Session) Run Uses

func (s *Session) Run(line string) error

func (*Session) RunCaplet Uses

func (s *Session) RunCaplet(filename string) error

func (*Session) Skip Uses

func (s *Session) Skip(ip net.IP) bool

func (*Session) Start Uses

func (s *Session) Start() error

func (*Session) Unlock Uses

func (s *Session) Unlock()

func (*Session) WiFiCompleter Uses

func (s *Session) WiFiCompleter(prefix string) []string

func (*Session) WiFiCompleterFull Uses

func (s *Session) WiFiCompleterFull(prefix string) []string

type SessionJSON Uses

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 Uses

type SessionModule struct {
    Name       string
    Session    *Session
    Started    bool
    StatusLock *sync.RWMutex
    State      *sync.Map
    // contains filtered or unexported fields
}

func NewSessionModule Uses

func NewSessionModule(name string, s *Session) SessionModule

func (*SessionModule) AddHandler Uses

func (m *SessionModule) AddHandler(h ModuleHandler)

func (*SessionModule) AddParam Uses

func (m *SessionModule) AddParam(p *ModuleParam) *ModuleParam

func (SessionModule) BoolParam Uses

func (m SessionModule) BoolParam(name string) (error, bool)

func (*SessionModule) Debug Uses

func (m *SessionModule) Debug(format string, args ...interface{})

func (SessionModule) DecParam Uses

func (m SessionModule) DecParam(name string) (error, float64)

func (*SessionModule) Error Uses

func (m *SessionModule) Error(format string, args ...interface{})

func (*SessionModule) Extra Uses

func (m *SessionModule) Extra() map[string]interface{}

func (*SessionModule) Fatal Uses

func (m *SessionModule) Fatal(format string, args ...interface{})

func (*SessionModule) Handlers Uses

func (m *SessionModule) Handlers() []ModuleHandler

func (SessionModule) IPParam Uses

func (m SessionModule) IPParam(name string) (error, net.IP)

func (*SessionModule) Info Uses

func (m *SessionModule) Info(format string, args ...interface{})

func (*SessionModule) InitState Uses

func (m *SessionModule) InitState(keys ...string)

func (SessionModule) IntParam Uses

func (m SessionModule) IntParam(name string) (error, int)

func (SessionModule) ListParam Uses

func (m SessionModule) ListParam(name string) (err error, values []string)

func (*SessionModule) Param Uses

func (m *SessionModule) Param(name string) *ModuleParam

func (*SessionModule) Parameters Uses

func (m *SessionModule) Parameters() map[string]*ModuleParam

func (*SessionModule) Required Uses

func (m *SessionModule) Required() []string

func (*SessionModule) Requires Uses

func (m *SessionModule) Requires(modName string)

func (*SessionModule) ResetState Uses

func (m *SessionModule) ResetState()

func (*SessionModule) Running Uses

func (m *SessionModule) Running() bool

func (*SessionModule) SetRunning Uses

func (m *SessionModule) SetRunning(running bool, cb func()) error

func (SessionModule) StringParam Uses

func (m SessionModule) StringParam(name string) (error, string)

func (*SessionModule) Warning Uses

func (m *SessionModule) Warning(format string, args ...interface{})

type UnknownCommandCallback Uses

type UnknownCommandCallback func(cmd string) bool

Package session imports 33 packages (graph) and is imported by 84 packages. Updated 2019-04-25. Refresh now. Tools for package owners.