session

package
v2.3.1+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2018 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const (
	STRING ParamType = iota
	BOOL             = iota
	INT              = iota
)
View Source
const (
	PromptVariable = "$"
	DefaultPrompt  = "{by}{fw}{cidr} {fb}> {env.iface.ipv4} {reset} {bold}» {reset}"
)
View Source
const HistoryFile = "~/bettercap.history"
View Source
const IPv4Validator = `^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$`
View Source
const ParamIfaceAddress = "<interface address>"
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)

	ErrAlreadyStarted = errors.New("Module is already running.")
	ErrAlreadyStopped = errors.New("Module is not running.")
)
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 ParseCommands

func ParseCommands(line string) []string

Types

type CommandHandler

type CommandHandler struct {
	Name        string
	Description string
	Completer   *readline.PrefixCompleter
	Parser      *regexp.Regexp
	Exec        func(args []string, s *Session) error
}

func NewCommandHandler

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

func (*CommandHandler) Parse

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

type Environment

type Environment struct {
	sync.Mutex

	Padding int               `json:"-"`
	Data    map[string]string `json:"data"`
	// contains filtered or unexported fields
}

func NewEnvironment

func NewEnvironment(s *Session, envFile string) *Environment

func (*Environment) Get

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

func (*Environment) GetInt

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

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) SetCallback

func (env *Environment) SetCallback(name string, cb SetCallback)

func (*Environment) Sorted

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

func (*Environment) WithCallback

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

type Event

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

func NewEvent

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

func (Event) Label

func (e Event) Label() string

type EventPool

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

func NewEventPool

func NewEventPool(debug bool, silent bool) *EventPool

func (*EventPool) Add

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

func (*EventPool) Clear

func (p *EventPool) Clear()

func (*EventPool) Listen

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

func (*EventPool) Log

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

func (*EventPool) SetDebug

func (p *EventPool) SetDebug(d bool)

func (*EventPool) SetSilent

func (p *EventPool) SetSilent(s bool)

func (*EventPool) Sorted

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

type LogMessage

type LogMessage struct {
	Level   int
	Message string
}

type Module

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

	Running() bool
	Start() error
	Stop() error
}

type ModuleHandler

type ModuleHandler struct {
	Name        string
	Description string
	Parser      *regexp.Regexp
	Exec        func(args []string) error
}

func NewModuleHandler

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

func (*ModuleHandler) Help

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

func (*ModuleHandler) Parse

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

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 NewIntParameter

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

func NewModuleParameter

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

func NewStringParameter

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

func (ModuleParam) Dump

func (p ModuleParam) Dump(padding int) string

func (ModuleParam) Get

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

func (ModuleParam) Help

func (p ModuleParam) Help(padding int) string

func (ModuleParam) Register

func (p ModuleParam) Register(s *Session)

func (ModuleParam) Validate

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

type ParamType

type ParamType int

type Prompt

type Prompt struct {
}

func NewPrompt

func NewPrompt() Prompt

func (Prompt) Render

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

type Session

type Session struct {
	Options   core.Options             `json:"options"`
	Interface *network.Endpoint        `json:"interface"`
	Gateway   *network.Endpoint        `json:"gateway"`
	Firewall  firewall.FirewallManager `json:"-"`
	Env       *Environment             `json:"env"`
	Lan       *network.LAN             `json:"lan"`
	WiFi      *network.WiFi            `json:"wifi"`
	BLE       *network.BLE             `json:"ble"`
	Queue     *packets.Queue           `json:"packets"`
	Input     *readline.Instance       `json:"-"`
	StartedAt time.Time                `json:"started_at"`
	Active    bool                     `json:"active"`
	GPS       nmea.GNGGA               `json:"gps"`
	Prompt    Prompt                   `json:"-"`

	CoreHandlers []CommandHandler `json:"-"`
	Modules      []Module         `json:"-"`

	Events *EventPool `json:"-"`

	UnkCmdCallback UnknownCommandCallback `json:"-"`
}

func New

func New() (*Session, error)

func (*Session) Close

func (s *Session) Close()

func (*Session) IsOn

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

func (*Session) Module

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

func (*Session) ReadLine

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

func (*Session) Refresh

func (s *Session) Refresh()

func (*Session) Register

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

func (*Session) Run

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

func (*Session) RunCaplet

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

func (*Session) Skip

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

func (*Session) Start

func (s *Session) Start() error

type SessionModule

type SessionModule struct {
	Name       string        `json:"name"`
	Session    *Session      `json:"-"`
	Started    bool          `json:"started"`
	StatusLock *sync.RWMutex `json:"-"`
	// 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) BoolParam

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

func (*SessionModule) Handlers

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

func (SessionModule) IntParam

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

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) 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)

type SetCallback

type SetCallback func(newValue string)

type UnknownCommandCallback

type UnknownCommandCallback func(cmd string) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL