core

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: Apache-2.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFoundSession = errors.New("session not found")
	Prompt             = "IoM"
)
View Source
var ErrLuaVMDead = fmt.Errorf("lua vm is dead")
View Source
var ErrMCPAlreadyRunning = errors.New("mcp already running")

Functions

func ExecuteLuaScript added in v0.3.0

func ExecuteLuaScript(con *Console, script string) (string, error)

ExecuteLuaScript 执行Lua脚本并返回结果

func FormatResponseWithCommands added in v0.3.0

func FormatResponseWithCommands(response string, commands []CommandSuggestion) string

FormatResponseWithCommands formats the AI response with numbered command suggestions

func HandlerTask added in v0.1.0

func HandlerTask(sess *client.Session, log *client.Logger, ctx *clientpb.TaskContext, message []byte, callee string, isFinish bool)

func Login added in v0.3.0

func Login(con *Console, config *mtls.ClientConfig) error

func LoginWithOptions added in v0.3.0

func LoginWithOptions(con *Console, config *mtls.ClientConfig, options LoginOptions) error

func NewConfigLogin added in v0.3.0

func NewConfigLogin(con *Console, yamlFile string) error

func RenderTaskOutput added in v0.3.0

func RenderTaskOutput(taskCtx *clientpb.TaskContext) (string, error)

func RunCommand added in v0.3.0

func RunCommand(con *Console, cmdline interface{}) (string, error)

func WrapClientCallback added in v0.3.0

func WrapClientCallback(callback ImplantFuncCallback) intermediate.ImplantCallback

func WrapImplantFunc added in v0.3.0

func WrapImplantFunc(con *Console, fun interface{}, callback ImplantFuncCallback) *mals.MalFunction

func WrapServerFunc added in v0.3.0

func WrapServerFunc(con *Console, fun interface{}) *mals.MalFunction

Types

type AIClient added in v0.3.0

type AIClient struct {
	// contains filtered or unexported fields
}

AIClient handles communication with AI APIs (OpenAI and Claude)

func NewAIClient added in v0.3.0

func NewAIClient(settings *assets.AISettings) *AIClient

NewAIClient creates a new AI client

func (*AIClient) Ask added in v0.3.0

func (c *AIClient) Ask(ctx context.Context, question string, history []string) (string, error)

Ask sends a question to the AI with context

func (*AIClient) AskStream added in v0.3.0

func (c *AIClient) AskStream(ctx context.Context, question string, history []string, onChunk func(chunk string)) (string, error)

AskStream sends a question to the AI and streams the response

type BindCmds added in v0.3.0

type BindCmds func(console *Console) console.Commands

BindCmds - Bind extra commands to the app object

type ClaudeChatRequest added in v0.3.0

type ClaudeChatRequest struct {
	Model     string          `json:"model"`
	MaxTokens int             `json:"max_tokens"`
	System    string          `json:"system,omitempty"`
	Messages  []ClaudeMessage `json:"messages"`
}

Claude API structures

type ClaudeChatResponse added in v0.3.0

type ClaudeChatResponse struct {
	ID      string `json:"id"`
	Type    string `json:"type"`
	Role    string `json:"role"`
	Content []struct {
		Type string `json:"type"`
		Text string `json:"text"`
	} `json:"content"`
	StopReason string `json:"stop_reason"`
	Error      *struct {
		Type    string `json:"type"`
		Message string `json:"message"`
	} `json:"error,omitempty"`
}

type ClaudeMessage added in v0.3.0

type ClaudeMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type ClaudeStreamEvent added in v0.3.0

type ClaudeStreamEvent struct {
	Type  string `json:"type"`
	Index int    `json:"index,omitempty"`
	Delta *struct {
		Type string `json:"type"`
		Text string `json:"text"`
	} `json:"delta,omitempty"`
}

Claude streaming response structures

type CommandSuggestion added in v0.3.0

type CommandSuggestion struct {
	Command     string
	Description string
}

CommandSuggestion represents a command extracted from AI response

func ParseCommandSuggestions added in v0.3.0

func ParseCommandSuggestions(response string) []CommandSuggestion

ParseCommandSuggestions extracts command suggestions from AI response Commands are expected to be wrapped in backticks like `command`

type Console added in v0.3.0

type Console struct {
	//*core.ActiveTarget
	*Server
	Log     *client.Logger
	App     *console.Console
	Profile *assets.Profile

	MCPAddr  string
	RPCAddr  string
	MCP      *MCPServer
	LocalRPC *LocalRPC

	CMDs    map[string]*cobra.Command
	Helpers map[string]*cobra.Command

	MalManager *plugin.MalManager

	// ConfigPath is the auth config file path used for the current login.
	// Populated by LoginCmd so the multiplexer can forward it to child processes.
	ConfigPath string

	// MuxChild indicates this process was spawned by the terminal multiplexer.
	MuxChild bool

	// Quiet suppresses notification event output, startup banners, and
	// MCP/LocalRPC initialization. Used by non-index mux child panes.
	// Task events (user command results) still display.
	Quiet bool
	// contains filtered or unexported fields
}

func NewConsole added in v0.3.0

func NewConsole() (*Console, error)

Start - Console entrypoint

func (*Console) AddCommandFuncHelper added in v0.3.0

func (c *Console) AddCommandFuncHelper(cmdName string, funcName string, example string, input, output []string) error

func (*Console) Context added in v0.3.0

func (c *Console) Context() context.Context

func (*Console) GetPrompt added in v0.3.0

func (c *Console) GetPrompt() string

func (*Console) GetRecentHistory added in v0.3.0

func (c *Console) GetRecentHistory(limit int) []string

func (*Console) ImplantMenu added in v0.3.0

func (c *Console) ImplantMenu() *cobra.Command

func (*Console) InitLocalRPCServer added in v0.3.0

func (con *Console) InitLocalRPCServer()

InitLocalRPCServer 在命令注册完成后初始化 Local RPC 服务器 该函数应该在所有命令注册完成后调用,避免并发映射访问错误 Local RPC 服务器在后台 goroutine 中启动,不会阻塞主流程 Local RPC 默认关闭,需要通过 --rpc 参数或配置文件中设置 localrpc_enable: true 来启用

func (*Console) InitMCPServer added in v0.3.0

func (con *Console) InitMCPServer()

InitMCPServer 在命令注册完成后初始化 MCP 服务器 该函数应该在所有命令注册完成后调用,避免并发映射访问错误 MCP 服务器在后台 goroutine 中启动,不会阻塞主流程 MCP 默认关闭,需要通过 --mcp 参数或配置文件中设置 mcp_enable: true 来启用

func (*Console) IsDaemonExecution added in v0.3.0

func (c *Console) IsDaemonExecution() bool

func (*Console) IsMuxIndex added in v0.3.0

func (c *Console) IsMuxIndex() bool

IsMuxIndex returns true when this process is the index (first) pane of the terminal multiplexer. The index pane acts as the notification bus — it receives all global events and intercepts `use` to open new panes via OSC.

func (*Console) IsNonInteractiveExecution added in v0.3.0

func (c *Console) IsNonInteractiveExecution() bool

func (*Console) NewConsole added in v0.3.0

func (c *Console) NewConsole()

func (*Console) RefreshActiveSession added in v0.3.0

func (c *Console) RefreshActiveSession()

func (*Console) RefreshCmd added in v0.3.0

func (c *Console) RefreshCmd(sess *client.Session) int

func (*Console) RegisterAggressiveFunc added in v0.3.0

func (c *Console) RegisterAggressiveFunc(name string, fn interface{}, internalCallback ImplantFuncCallback, callback intermediate.ImplantCallback)

func (*Console) RegisterBuiltinFunc added in v0.3.0

func (c *Console) RegisterBuiltinFunc(pkg, name string, fn interface{}, callback ImplantFuncCallback) error

func (*Console) RegisterImplantFunc added in v0.3.0

func (c *Console) RegisterImplantFunc(name string, fn interface{},
	bname string, bfn interface{},
	internalCallback ImplantFuncCallback, callback intermediate.ImplantCallback)

func (*Console) RegisterServerFunc added in v0.3.0

func (c *Console) RegisterServerFunc(name string, fn interface{}, helper *mals.Helper) error

func (*Console) Start added in v0.3.0

func (c *Console) Start(bindCmds ...BindCmds) error

func (*Console) SwitchImplant added in v0.3.0

func (c *Console) SwitchImplant(sess *client.Session, callee string)

func (*Console) SyncBuildContext added in v0.3.0

func (c *Console) SyncBuildContext() context.Context

func (*Console) WithDaemonExecution added in v0.3.0

func (c *Console) WithDaemonExecution(enabled bool) func()

func (*Console) WithNonInteractiveExecution added in v0.3.0

func (c *Console) WithNonInteractiveExecution(enabled bool) func()

func (*Console) WithREPLExecution added in v0.3.0

func (c *Console) WithREPLExecution(enabled bool) func()

type ImplantFuncCallback added in v0.3.0

type ImplantFuncCallback func(content *clientpb.TaskContext) (interface{}, error)

ImplantFuncCallback, function internal callback func, retrun golang struct

type LocalRPC added in v0.3.0

type LocalRPC struct {
	// contains filtered or unexported fields
}

LocalRPC wraps the gRPC server instance

func NewLocalRPC added in v0.3.0

func NewLocalRPC(console *Console, address string) (*LocalRPC, error)

NewLocalRPC creates and starts a new LocalRPC server

func (*LocalRPC) Stop added in v0.3.0

func (l *LocalRPC) Stop() error

Stop stops the local gRPC server

type LocalRPCServer added in v0.3.0

type LocalRPCServer struct {
	localrpc.UnimplementedCommandServiceServer
	// contains filtered or unexported fields
}

LocalRPCServer wraps the gRPC server for local command execution

func NewLocalRPCServer added in v0.3.0

func NewLocalRPCServer(console *Console) *LocalRPCServer

NewLocalRPCServer creates a new LocalRPCServer instance

func (*LocalRPCServer) ExecuteCommand added in v0.3.0

ExecuteCommand implements the CommandService.ExecuteCommand RPC method

func (*LocalRPCServer) ExecuteLua added in v0.3.0

ExecuteLua implements the CommandService.ExecuteLua RPC method

func (*LocalRPCServer) GetGroups added in v0.3.0

GetGroups implements the CommandService.GetGroups RPC method

func (*LocalRPCServer) GetHistory added in v0.3.0

GetHistory implements the CommandService.GetHistory RPC method

func (*LocalRPCServer) GetSchemas added in v0.3.0

GetSchemas implements the CommandService.GetSchemas RPC method

func (*LocalRPCServer) SearchCommands added in v0.3.0

SearchCommands implements the CommandService.SearchCommands RPC method

func (*LocalRPCServer) StreamCommand added in v0.3.0

StreamCommand executes a command and continuously streams back task event output. It is a general-purpose streaming RPC: any command that produces persistent EventTaskDone events (tapping, poison, etc.) will have its rendered output streamed to the caller.

Design:

  1. Register an EventHook BEFORE executing the command (no race window).
  2. Execute the command via cobra; read Session.LastTask for the task ID (no polling).
  3. EventHook filters events by task ID, renders via InternalFunctions, writes to channel.
  4. Main loop reads channel and streams to gRPC client.
  5. On context cancel: remove EventHook, return.

type LoginOptions added in v0.3.0

type LoginOptions struct {
	SuppressStartupOutput bool
}

type MCPServer added in v0.3.0

type MCPServer struct {
	// contains filtered or unexported fields
}

MCPServer 包装了MCP服务器实例

func NewMCP added in v0.3.0

func NewMCP(console *Console) *MCPServer

NewMCP 创建一个新的MCP服务器实例

func (*MCPServer) AddTool added in v0.3.0

func (m *MCPServer) AddTool(tool mcp.Tool, handler server.ToolHandlerFunc)

AddTool 添加新的工具到 MCP 服务器

func (*MCPServer) Start added in v0.3.0

func (m *MCPServer) Start(host string, port int) error

Start 启动 MCP HTTP 服务器

func (*MCPServer) Stop added in v0.3.0

func (m *MCPServer) Stop() error

Stop 停止 MCP 服务器

type Message added in v0.3.0

type Message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

Message represents a chat message

type OpenAIChatRequest added in v0.3.0

type OpenAIChatRequest struct {
	Model       string    `json:"model"`
	Messages    []Message `json:"messages"`
	MaxTokens   int       `json:"max_tokens,omitempty"`
	Temperature float64   `json:"temperature,omitempty"`
	Stream      bool      `json:"stream,omitempty"`
}

OpenAI API structures

type OpenAIChatResponse added in v0.3.0

type OpenAIChatResponse struct {
	ID      string `json:"id"`
	Choices []struct {
		Message      Message `json:"message"`
		FinishReason string  `json:"finish_reason"`
	} `json:"choices"`
	Error *struct {
		Message string `json:"message"`
		Type    string `json:"type"`
	} `json:"error,omitempty"`
}

type OpenAIStreamChunk added in v0.3.0

type OpenAIStreamChunk struct {
	Choices []struct {
		Delta struct {
			Content string `json:"content"`
		} `json:"delta"`
		FinishReason string `json:"finish_reason"`
	} `json:"choices"`
}

OpenAI streaming response structures

type Server added in v0.3.0

type Server struct {
	*client.ServerState

	// Quiet suppresses console event output while still updating internal state.
	Quiet bool
	// contains filtered or unexported fields
}

func NewServer added in v0.3.0

func NewServer(conn *grpc.ClientConn, config *mtls.ClientConfig) (*Server, error)

NewServer wraps client.ServerState into core.ServerState

func NewServerWithOptions added in v0.3.0

func NewServerWithOptions(conn *grpc.ClientConn, config *mtls.ClientConfig, suppressStartupOutput bool) (*Server, error)

func (*Server) AddCallback added in v0.3.0

func (s *Server) AddCallback(task *clientpb.Task, callback client.TaskCallback)

func (*Server) AddDoneCallback added in v0.3.0

func (s *Server) AddDoneCallback(task *clientpb.Task, callback client.TaskCallback)

func (*Server) AddEventHook added in v0.3.0

func (s *Server) AddEventHook(event client.EventCondition, callback client.OnEventFunc)

func (*Server) EventHandler added in v0.3.0

func (s *Server) EventHandler()

func (*Server) HandlerEvent added in v0.3.0

func (s *Server) HandlerEvent(event *clientpb.Event)

Jump to

Keyboard shortcuts

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