db

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package db provides BBolt persistence for Kitchen state.

Index

Constants

This section is empty.

Variables

View Source
var (
	BucketMeta          = []byte("meta")
	BucketOrders        = []byte("orders")
	BucketAgents        = []byte("agents")
	BucketSessions      = []byte("sessions")
	BucketStagers       = []byte("stagers")
	BucketMetrics       = []byte("metrics")
	BucketPantry        = []byte("pantry")
	BucketHistory       = []byte("history")
	BucketKnownEntities = []byte("known_entities")
	BucketLoot          = []byte("loot")
)

Bucket names

Functions

This section is empty.

Types

type AgentRepository

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

AgentRepository provides database operations for agents.

func NewAgentRepository

func NewAgentRepository(db *DB) *AgentRepository

NewAgentRepository creates a new AgentRepository.

func (*AgentRepository) Get

func (r *AgentRepository) Get(agentID string) (*AgentRow, error)

Get retrieves an agent by ID.

func (*AgentRepository) List

func (r *AgentRepository) List() ([]*AgentRow, error)

List retrieves all agents.

func (*AgentRepository) SetDwellDeadline

func (r *AgentRepository) SetDwellDeadline(sessionID string, deadline *time.Time) error

SetDwellDeadline sets the dwell deadline for all agents in a session.

func (*AgentRepository) Upsert

func (r *AgentRepository) Upsert(agent *AgentRow) error

Upsert inserts or updates an agent in the database.

type AgentRow

type AgentRow struct {
	AgentID       string     `json:"agent_id"`
	SessionID     string     `json:"session_id"`
	Hostname      string     `json:"hostname"`
	OS            string     `json:"os"`
	Arch          string     `json:"arch"`
	FirstSeen     time.Time  `json:"first_seen"`
	LastSeen      time.Time  `json:"last_seen"`
	IsOnline      bool       `json:"is_online"`
	DwellDeadline *time.Time `json:"dwell_deadline,omitempty"`
}

AgentRow represents an agent record in the database.

type Config

type Config struct {
	// Path is the path to the BBolt database file.
	Path string

	// CreateDir creates the parent directory if it doesn't exist.
	CreateDir bool
}

Config holds database configuration.

type DB

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

DB wraps a BBolt database connection for Kitchen persistence.

func Open

func Open(config Config) (*DB, error)

Open opens or creates a BBolt database.

func (*DB) Close

func (db *DB) Close() error

Close closes the database connection.

func (*DB) LoadPantry

func (db *DB) LoadPantry() (*pantry.Pantry, error)

LoadPantry retrieves the attack graph from the database. Returns nil if no graph is stored.

func (*DB) SavePantry

func (db *DB) SavePantry(p *pantry.Pantry) error

SavePantry persists the attack graph to the database.

type EntityType

type EntityType string
const (
	EntityTypeRepo EntityType = "repo"
	EntityTypeOrg  EntityType = "org"
)

type HistoryEventType

type HistoryEventType string
const (
	HistoryAnalysisStarted   HistoryEventType = "analysis.started"
	HistoryAnalysisCompleted HistoryEventType = "analysis.completed"
	HistoryAnalysisFailed    HistoryEventType = "analysis.failed"
	HistoryExploitAttempted  HistoryEventType = "exploit.attempted"
	HistoryExploitSucceeded  HistoryEventType = "exploit.succeeded"
	HistoryExploitFailed     HistoryEventType = "exploit.failed"
	HistoryAgentConnected    HistoryEventType = "agent.connected"
	HistorySecretExtracted   HistoryEventType = "secret.extracted"
	HistoryPurgeExecuted     HistoryEventType = "purge.executed"
)

type HistoryRepository

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

func NewHistoryRepository

func NewHistoryRepository(db *DB) *HistoryRepository

func (*HistoryRepository) Insert

func (r *HistoryRepository) Insert(entry *HistoryRow) error

func (*HistoryRepository) List

func (r *HistoryRepository) List(limit int) ([]*HistoryRow, error)

func (*HistoryRepository) ListBySession

func (r *HistoryRepository) ListBySession(sessionID string) ([]*HistoryRow, error)

func (*HistoryRepository) ListSince

func (r *HistoryRepository) ListSince(since time.Time) ([]*HistoryRow, error)

type HistoryRow

type HistoryRow struct {
	ID        string           `json:"id"`
	Type      HistoryEventType `json:"type"`
	Timestamp time.Time        `json:"timestamp"`
	SessionID string           `json:"session_id,omitempty"`

	Target     string `json:"target,omitempty"`
	TargetType string `json:"target_type,omitempty"`
	TokenType  string `json:"token_type,omitempty"`

	VulnID     string `json:"vuln_id,omitempty"`
	Repository string `json:"repository,omitempty"`
	StagerID   string `json:"stager_id,omitempty"`
	PRURL      string `json:"pr_url,omitempty"`

	Outcome     string `json:"outcome,omitempty"`
	ErrorDetail string `json:"error_detail,omitempty"`
	AgentID     string `json:"agent_id,omitempty"`
}

type KnownEntityRepository

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

func NewKnownEntityRepository

func NewKnownEntityRepository(db *DB) *KnownEntityRepository

func (*KnownEntityRepository) CountByScope

func (r *KnownEntityRepository) CountByScope(scopeType EntityType, scopeValue string) (int, error)

func (*KnownEntityRepository) CountByScopeAndSession

func (r *KnownEntityRepository) CountByScopeAndSession(scopeType EntityType, scopeValue, sessionID string) (int, error)

func (*KnownEntityRepository) DeleteByScope

func (r *KnownEntityRepository) DeleteByScope(scopeType EntityType, scopeValue string) (int, error)

func (*KnownEntityRepository) DeleteByScopeAndSession

func (r *KnownEntityRepository) DeleteByScopeAndSession(scopeType EntityType, scopeValue, sessionID string) (int, error)

func (*KnownEntityRepository) ListBySession

func (r *KnownEntityRepository) ListBySession(sessionID string) ([]*KnownEntityRow, error)

func (*KnownEntityRepository) ListOrgs

func (r *KnownEntityRepository) ListOrgs(sessionID string) ([]*KnownEntityRow, error)

func (*KnownEntityRepository) ListRepos

func (r *KnownEntityRepository) ListRepos(sessionID string) ([]*KnownEntityRow, error)

func (*KnownEntityRepository) Upsert

func (r *KnownEntityRepository) Upsert(entity *KnownEntityRow) error

type KnownEntityRow

type KnownEntityRow struct {
	ID            string     `json:"id"`
	EntityType    EntityType `json:"entity_type"`
	Name          string     `json:"name"`
	SessionID     string     `json:"session_id"`
	DiscoveredAt  time.Time  `json:"discovered_at"`
	DiscoveredVia string     `json:"discovered_via"`
	IsPrivate     bool       `json:"is_private"`
	Permissions   []string   `json:"permissions,omitempty"`
	SSHPermission string     `json:"ssh_permission,omitempty"`
}

type LootRepository

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

func NewLootRepository

func NewLootRepository(db *DB) *LootRepository

func (*LootRepository) List

func (r *LootRepository) List() ([]*LootRow, error)

func (*LootRepository) Upsert

func (r *LootRepository) Upsert(entry *LootRow) error

type LootRow

type LootRow struct {
	ID        string    `json:"id"`
	SessionID string    `json:"session_id"`
	AgentID   string    `json:"agent_id"`
	Hostname  string    `json:"hostname,omitempty"`
	Timestamp time.Time `json:"timestamp"`

	Name      string `json:"name"`
	Value     string `json:"value"`
	Type      string `json:"type"`
	Source    string `json:"source"`
	HighValue bool   `json:"high_value"`

	Repository string `json:"repository,omitempty"`
	Workflow   string `json:"workflow,omitempty"`
	Job        string `json:"job,omitempty"`

	TokenPermissions map[string]string `json:"token_permissions,omitempty"`
}

type OrderRepository

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

OrderRepository provides database operations for orders.

func NewOrderRepository

func NewOrderRepository(db *DB) *OrderRepository

NewOrderRepository creates a new OrderRepository.

func (*OrderRepository) ListPending

func (r *OrderRepository) ListPending() ([]*models.Order, error)

ListPending retrieves all pending orders across all agents.

type SessionRepository

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

SessionRepository provides database operations for sessions.

func NewSessionRepository

func NewSessionRepository(db *DB) *SessionRepository

NewSessionRepository creates a new SessionRepository.

func (*SessionRepository) List

func (r *SessionRepository) List() ([]*SessionRow, error)

List retrieves all sessions.

type SessionRow

type SessionRow struct {
	ID            string     `json:"id"`
	Target        string     `json:"target"`
	ThreatModel   string     `json:"threat_model"`
	CreatedAt     time.Time  `json:"created_at"`
	DwellDeadline *time.Time `json:"dwell_deadline,omitempty"`
}

SessionRow represents a session record in the database.

type StagerRepository

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

func NewStagerRepository

func NewStagerRepository(db *DB) *StagerRepository

func (*StagerRepository) Delete

func (r *StagerRepository) Delete(id string) error

func (*StagerRepository) List

func (r *StagerRepository) List() ([]*StagerRow, error)

func (*StagerRepository) Upsert

func (r *StagerRepository) Upsert(row *StagerRow) error

type StagerRow

type StagerRow struct {
	ID            string            `json:"id"`
	ResponseType  string            `json:"response_type"`
	Payload       string            `json:"payload"`
	CreatedAt     time.Time         `json:"created_at"`
	ExpiresAt     time.Time         `json:"expires_at"`
	CalledBack    bool              `json:"called_back"`
	CallbackAt    time.Time         `json:"callback_at"`
	CallbackIP    string            `json:"callback_ip"`
	SessionID     string            `json:"session_id"`
	Metadata      map[string]string `json:"metadata,omitempty"`
	DwellTime     time.Duration     `json:"dwell_time"`
	Persistent    bool              `json:"persistent"`
	MaxCallbacks  int               `json:"max_callbacks,omitempty"`
	DefaultMode   string            `json:"default_mode,omitempty"`
	NextMode      string            `json:"next_mode,omitempty"`
	CallbackCount int               `json:"callback_count"`
	LastAgentID   string            `json:"last_agent_id,omitempty"`
	RevokedAt     *time.Time        `json:"revoked_at,omitempty"`
}

Jump to

Keyboard shortcuts

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