shell

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package shell is the boundary between AIMS and the operator's interactive shell for the `bring` implant-context feature (see BRING.md). It knows the supported shell dialects and, crucially, how to quote a value so that a shell reproduces it verbatim without interpreting its contents.

Quote is the single trusted escaping boundary of the whole feature. In a C2 setting an agent's reported strings (name, working directory, hostname) are attacker-controlled; if any such value reached generated shell code unescaped, a malicious implant would gain code execution on the operator's box. Every agent-derived value interpolated into a bring payload must therefore pass through Quote.

Index

Constants

View Source
const (
	KeyID      = "id"
	KeyName    = "name"
	KeyTool    = "tool"
	KeyCWD     = "cwd"
	KeyRoute   = "route"
	KeyPending = "pending"
)

Payload field keys. The Go emitter (cmd/bring.writePayload) and the shell parser in the init templates must agree on these exact strings; the templates receive them via initData so the two sides cannot drift apart.

Variables

This section is empty.

Functions

func Init

func Init(w io.Writer, sh Shell) error

Init writes the shell integration — the bring()/leave() functions and their helpers — for the given shell to w. This is the trusted half of the `bring` feature: the emitted code contains no agent data (agent values arrive only later, as inert payload data parsed by bring()). Source it once from your shell rc, e.g. `source <(aims init zsh)`.

Only zsh is wired today (P1); bash and fish return a clear not-implemented error so the command fails loudly rather than emitting a broken snippet.

func Quote

func Quote(sh Shell, s string) string

Quote renders s as a single shell token that the given shell expands back to exactly s, with no interpretation of its contents. It is the single trusted boundary between attacker-controlled agent data and generated shell code (see the package doc): every value interpolated into a bring payload MUST pass through Quote. The result is safe for arbitrary bytes — including newlines, $(...), backticks, semicolons and quotes.

func SanitizeDisplay

func SanitizeDisplay(s string) string

SanitizeDisplay hardens an agent-derived value before it is carried into the shell. It removes: control characters — including the newline and the TAB that delimits payload fields; and the bytes a prompt might re-interpret — '$' and '`' (command substitution under zsh PROMPT_SUBST) and '%' (zsh prompt escapes). The result is also length-capped.

This is display hardening layered on top of the capture-as-data payload (which already prevents execution, since the shell parses rather than evals the payload): together they guarantee a hostile implant string is inert data — never code — and cannot corrupt the prompt. It is applied to every emitted value, including the id, so control bytes can never break the line format.

func Supported

func Supported() []string

Supported lists the shell names bring can generate integration for.

Types

type Shell

type Shell int

Shell identifies a supported shell dialect. Dialects differ in how they quote string literals, which is why quoting is dispatched on the Shell.

const (
	// Bash is the default dialect and the POSIX-family reference.
	Bash Shell = iota
	// Zsh shares POSIX single-quote semantics with bash.
	Zsh
	// Fish quotes single-quoted strings differently (backslash is an escape).
	Fish
)

func Detect

func Detect() Shell

Detect guesses the operator's shell from the $SHELL environment variable, defaulting to Bash when it is unset or unrecognized.

func Parse

func Parse(name string) (Shell, error)

Parse resolves a shell name to a Shell. It accepts a bare name ("zsh") or the path of a shell binary ("/usr/bin/zsh"), case-insensitively, and errors on anything unsupported.

func (Shell) String

func (s Shell) String() string

String returns the canonical lowercase name of the shell.

Jump to

Keyboard shortcuts

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