plugin

package
v0.0.0-...-bad515c Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2024 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const T_ANY = 4
View Source
const T_DIR = 1
View Source
const T_FILE = 2
View Source
const T_SYMLINK = 3

Variables

This section is empty.

Functions

func OptsModule

func OptsModule(L *lua.LState) *lua.LTable

Types

type CmdArgs

type CmdArgs struct {
	RawArgs string
	// contains filtered or unexported fields
}

func (*CmdArgs) Array

func (args *CmdArgs) Array() []string

func (*CmdArgs) ArrayWithCommand

func (args *CmdArgs) ArrayWithCommand(cmd string) []string

func (*CmdArgs) ForEach

func (args *CmdArgs) ForEach(callback func(string, any))

func (*CmdArgs) Get

func (args *CmdArgs) Get(key string) any

func (*CmdArgs) Parse

func (args *CmdArgs) Parse()

func (*CmdArgs) ParseOpts

func (args *CmdArgs) ParseOpts(optsConfig *OptConfig, multiCharSingleDash bool) (map[string]any, []string, error)

type CommandFn

type CommandFn func(*CmdArgs, *Session)

type Config

type Config struct {
	CommandCallbacks    map[string]CommandFn
	PasswordInterceptor PasswordInterceptFn
	PromptFn            PromptFn
	LoginMessageFn      LoginMessageFn
	// contains filtered or unexported fields
}

Config is a struct that handles everything related to the sandbox. For example, the registered commands, the password interceptor, the fake prompt, and other things.

func (*Config) Init

func (c *Config) Init()

Init initializes the instance. This must run, as it instanciates the command callbacks.

func (*Config) RegisterCommand

func (c *Config) RegisterCommand(cmd, dir string, cmdFn CommandFn) bool

RegisterCommand adds a command to the list of supported commands. This means that an attacker can run the command by the supplied `cmd` and then that will run the command function (`cmdFn`).

func (*Config) RegisterLoginMessage

func (c *Config) RegisterLoginMessage(loginMsgFn LoginMessageFn)

func (*Config) RegisterPasswordIntercept

func (c *Config) RegisterPasswordIntercept(interceptor PasswordInterceptFn)

func (*Config) RegisterPrompt

func (c *Config) RegisterPrompt(promptFn PromptFn)

type LoginMessageFn

type LoginMessageFn func(*Session) string

type OptConfig

type OptConfig struct {
	Opts       map[string]bool
	ParsedOpts map[string]any
	BareArgs   []string
}

OptConfig manages options.

func CreateOptsConfig

func CreateOptsConfig() *OptConfig

func (*OptConfig) AddBoth

func (o *OptConfig) AddBoth(short, long string, hasArg bool)

AddBoth is similar ot AddOne, but it also adds a long description.

func (*OptConfig) AddOne

func (o *OptConfig) AddOne(arg string, hasArg bool)

AddOne adds a single argument and a boolean on whether it has args to the map.

func (*OptConfig) Get

func (o *OptConfig) Get(arg string) any

Get returns the parsed options.

type PasswordInterceptFn

type PasswordInterceptFn func(string, string, *net.IP) bool

type Perm

type Perm struct {
	Read  bool
	Write bool
	Exec  bool
}

Perm is the basic permissions structure of a Linux file.

type Plugin

type Plugin struct {
	Path   string
	Dir    fs.DirEntry
	Main   fs.DirEntry
	L      *lua.LState
	Config *Config
	DB     *gorm.DB
	// contains filtered or unexported fields
}

func LoadPlugins

func LoadPlugins(path string, db *gorm.DB) ([]*Plugin, error)

func (*Plugin) CallPasswordInterceptor

func (p *Plugin) CallPasswordInterceptor(username, password string, ip *net.IP) bool

func (*Plugin) Commands

func (p *Plugin) Commands() map[string]CommandFn

func (*Plugin) GetPath

func (p *Plugin) GetPath(withMain bool) string

func (*Plugin) HasCommandDefined

func (p *Plugin) HasCommandDefined() bool

func (*Plugin) HasLoginMessage

func (p *Plugin) HasLoginMessage() bool

func (*Plugin) HasPasswordIntercept

func (p *Plugin) HasPasswordIntercept() bool

func (*Plugin) HasPromptFn

func (p *Plugin) HasPromptFn() bool

func (*Plugin) Init

func (p *Plugin) Init(vfs *VFS) error

func (*Plugin) SetVFS

func (p *Plugin) SetVFS(vfs *VFS)

type PluginManager

type PluginManager struct {
	DB        *gorm.DB
	PluginVFS *VFS

	PromptPlugin   PromptFn
	LoginMessageFn LoginMessageFn
	// contains filtered or unexported fields
}

PluginManager handles all things related to the plugins. Use this instance to load plugins and get commands.

func (*PluginManager) GetCommand

func (pm *PluginManager) GetCommand(cmd string) (CommandFn, bool)

GetComand returns a function handler and a boolean (if it was found or not) for a command (as a string).

func (*PluginManager) GetPasswordIntercepts

func (pm *PluginManager) GetPasswordIntercepts() []*Plugin

func (*PluginManager) LoadPlugins

func (pm *PluginManager) LoadPlugins(path string) error

LoadPlugins loads the plugin by supplying a `path`.

func (*PluginManager) MatchCommand

func (pm *PluginManager) MatchCommand(part string) ([]CommandFn, []string)

type PromptFn

type PromptFn func(*Session) string

type Session

type Session struct {
	VFS     *VFS
	Term    *term.Terminal
	Manager *PluginManager

	User *User
	// contains filtered or unexported fields
}

func (*Session) AutoCompleteCallback

func (s *Session) AutoCompleteCallback(line string, pos int, key rune) (newLine string, newPos int, ok bool)

func (*Session) Chdir

func (s *Session) Chdir(newPath string) error

func (*Session) GetPWD

func (s *Session) GetPWD() string

func (*Session) TermWrite

func (s *Session) TermWrite(data ...string)

type TermWriteFn

type TermWriteFn func(...string)

type User

type User struct {
	Username string
	Group    string
}

type VFS

type VFS struct {
	Root VFSFile `json:"root"`
	Home string  `json:"home"`
	PWD  string  `json:"-"`
	User *User   `json:"-"`
}

VFS is the recursive struct that describes the virtual file system.

func ReadVFSJSONFile

func ReadVFSJSONFile(path string) (*VFS, error)

ReadVFSJSONFile reads the JSON file which contains the the virtual file system model.

func (*VFS) FindFile

func (vfs *VFS) FindFile(path string) (string, *VFSFile, error)

FindFile returns the path and VFSFile of a file in the path.

func (*VFS) Mkdir

func (vfs *VFS) Mkdir(path string, mode os.FileMode) (*VFSFile, error)

Mkdir creates a new directory at the given path.

func (*VFS) Rmfile

func (vfs *VFS) Rmfile(path string) error

Rmfile deletes a file in the filesystem.

func (*VFS) WriteFile

func (vfs *VFS) WriteFile(path, contents string) error

WriteFile adds contents to a specific file in the path.

type VFSFile

type VFSFile struct {
	Type     int                `json:"t"`
	Name     string             `json:"n"`
	Files    map[string]VFSFile `json:"f"`
	Contents string             `json:"c"`
	Mode     os.FileMode        `json:"m"`
	Owner    string             `json:"o"`
	Group    string             `json:"g"`
	ModTime  time.Time          `json:"mt"`
	LinkTo   string             `json:"lt"`
	NLink    int                `json:"nl"`
	CmdFn    CommandFn          `json:"-"`
}

VFSFile represents the virtual file in the VFS. It can be a regular file (text, executable, etc) or a directory containing its own set of files.

func (*VFSFile) CanAccess

func (f *VFSFile) CanAccess(user *User) Perm

CanAccess returns the permissions the user has on the specific file.

func (*VFSFile) ForEach

func (f *VFSFile) ForEach(callback func(*VFSFile, int))

ForEach loops through all of the files.

func (*VFSFile) StrMode

func (f *VFSFile) StrMode() string

StrMode converts the permissions (or mode) of a file into a string.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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