dynamic

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnalysisResult

type AnalysisResult struct {
	PackageName       string    `json:"package_name"`
	Registry          string    `json:"registry"`
	AnalysisTimestamp time.Time `json:"analysis_timestamp"`

	// Execution results
	ExecutionResults []ExecutionResult `json:"execution_results"`

	// Behavioral analysis
	NetworkActivity    []NetworkActivity   `json:"network_activity"`
	FileSystemChanges  []FileSystemChange  `json:"file_system_changes"`
	ProcessActivity    []ProcessActivity   `json:"process_activity"`
	EnvironmentChanges []EnvironmentChange `json:"environment_changes"`

	// Security assessment
	SecurityFindings []SecurityFinding `json:"security_findings"`
	RiskScore        float64           `json:"risk_score"`
	ThreatLevel      string            `json:"threat_level"`

	// Metadata
	SandboxInfo     SandboxInfo   `json:"sandbox_info"`
	ProcessingTime  time.Duration `json:"processing_time"`
	ResourceUsage   ResourceUsage `json:"resource_usage"`
	Warnings        []string      `json:"warnings"`
	Recommendations []string      `json:"recommendations"`
}

AnalysisResult represents dynamic analysis results

type Config

type Config struct {
	Enabled bool `yaml:"enabled"`

	// Sandbox configuration
	SandboxType            string `yaml:"sandbox_type"` // docker, vm, chroot, namespace
	SandboxImage           string `yaml:"sandbox_image"`
	SandboxTimeout         string `yaml:"sandbox_timeout"`
	MaxConcurrentSandboxes int    `yaml:"max_concurrent_sandboxes"`

	// Analysis configuration
	AnalyzeInstallScripts  bool `yaml:"analyze_install_scripts"`
	AnalyzeNetworkActivity bool `yaml:"analyze_network_activity"`
	AnalyzeFileSystem      bool `yaml:"analyze_file_system"`
	AnalyzeProcesses       bool `yaml:"analyze_processes"`
	AnalyzeEnvironment     bool `yaml:"analyze_environment"`

	// Security limits
	MaxExecutionTime      string `yaml:"max_execution_time"`
	MaxMemoryUsage        int64  `yaml:"max_memory_usage"`
	MaxDiskUsage          int64  `yaml:"max_disk_usage"`
	MaxNetworkConnections int    `yaml:"max_network_connections"`

	// Monitoring
	MonitoringInterval string `yaml:"monitoring_interval"`
	Verbose            bool   `yaml:"verbose"`
	LogLevel           string `yaml:"log_level"`
}

Config contains dynamic analyzer configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns default dynamic analyzer configuration

type DynamicAnalyzer

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

DynamicAnalyzer performs lightweight dynamic analysis in sandboxed environments

func NewAnalyzer

func NewAnalyzer(cfg interface{}) (*DynamicAnalyzer, error)

NewAnalyzer creates a new dynamic analyzer from a config.Config

func NewDynamicAnalyzer

func NewDynamicAnalyzer(config *Config) (*DynamicAnalyzer, error)

NewDynamicAnalyzer creates a new dynamic analyzer

func (*DynamicAnalyzer) AnalyzePackage

func (da *DynamicAnalyzer) AnalyzePackage(ctx context.Context, packagePath string) (*AnalysisResult, error)

AnalyzePackage performs dynamic analysis on a package

func (*DynamicAnalyzer) CleanupSandboxes

func (da *DynamicAnalyzer) CleanupSandboxes() error

CleanupSandboxes cleans up all sandboxes

func (*DynamicAnalyzer) ExportResults

func (da *DynamicAnalyzer) ExportResults(result *AnalysisResult, outputPath string) error

ExportResults exports analysis results to JSON

func (*DynamicAnalyzer) GetSandboxStatus

func (da *DynamicAnalyzer) GetSandboxStatus() map[string]string

GetSandboxStatus returns the status of all sandboxes

type EnvironmentChange

type EnvironmentChange struct {
	Timestamp   time.Time `json:"timestamp"`
	Variable    string    `json:"variable"`
	OldValue    string    `json:"old_value"`
	NewValue    string    `json:"new_value"`
	Operation   string    `json:"operation"` // set, unset, modify
	RiskLevel   string    `json:"risk_level"`
	Description string    `json:"description"`
}

EnvironmentChange represents environment variable changes

type ExecutionResult

type ExecutionResult struct {
	Command            string              `json:"command"`
	ExitCode           int                 `json:"exit_code"`
	Stdout             string              `json:"stdout"`
	Stderr             string              `json:"stderr"`
	ExecutionTime      time.Duration       `json:"execution_time"`
	ResourceUsage      ResourceUsage       `json:"resource_usage"`
	SecurityViolations []SecurityViolation `json:"security_violations"`
}

ExecutionResult represents the result of executing a script or command

type FileSystemChange

type FileSystemChange struct {
	Timestamp   time.Time `json:"timestamp"`
	Operation   string    `json:"operation"` // create, modify, delete, move, chmod
	Path        string    `json:"path"`
	OldPath     string    `json:"old_path,omitempty"`
	Permissions string    `json:"permissions,omitempty"`
	Size        int64     `json:"size,omitempty"`
	Checksum    string    `json:"checksum,omitempty"`
	RiskLevel   string    `json:"risk_level"`
	Description string    `json:"description"`
}

FileSystemChange represents file system modifications

type NetworkActivity

type NetworkActivity struct {
	Timestamp       time.Time `json:"timestamp"`
	Protocol        string    `json:"protocol"`
	SourceIP        string    `json:"source_ip"`
	SourcePort      int       `json:"source_port"`
	DestinationIP   string    `json:"destination_ip"`
	DestinationPort int       `json:"destination_port"`
	Domain          string    `json:"domain,omitempty"`
	DataSize        int64     `json:"data_size"`
	Direction       string    `json:"direction"` // inbound, outbound
	RiskLevel       string    `json:"risk_level"`
	Description     string    `json:"description"`
}

NetworkActivity represents network-related activities

type NetworkIO

type NetworkIO struct {
	BytesReceived   int64 `json:"bytes_received"`
	BytesSent       int64 `json:"bytes_sent"`
	PacketsReceived int64 `json:"packets_received"`
	PacketsSent     int64 `json:"packets_sent"`
	Connections     int   `json:"connections"`
}

NetworkIO represents network I/O statistics

type ProcessActivity

type ProcessActivity struct {
	Timestamp        time.Time         `json:"timestamp"`
	PID              int               `json:"pid"`
	PPID             int               `json:"ppid"`
	Command          string            `json:"command"`
	Arguments        []string          `json:"arguments"`
	User             string            `json:"user"`
	WorkingDirectory string            `json:"working_directory"`
	EnvironmentVars  map[string]string `json:"environment_vars"`
	Action           string            `json:"action"` // start, stop, signal
	ExitCode         int               `json:"exit_code,omitempty"`
	ResourceUsage    ResourceUsage     `json:"resource_usage"`
	RiskLevel        string            `json:"risk_level"`
	Description      string            `json:"description"`
}

ProcessActivity represents process-related activities

type ResourceUsage

type ResourceUsage struct {
	CPUUsage        float64   `json:"cpu_usage"`    // percentage
	MemoryUsage     int64     `json:"memory_usage"` // bytes
	DiskUsage       int64     `json:"disk_usage"`   // bytes
	NetworkIO       NetworkIO `json:"network_io"`
	FileDescriptors int       `json:"file_descriptors"`
	ProcessCount    int       `json:"process_count"`
}

ResourceUsage represents resource consumption metrics

type Sandbox

type Sandbox struct {
	ID          string
	Type        string
	Image       string
	ContainerID string
	CreatedAt   time.Time
	Status      string
	Config      *Config
	// contains filtered or unexported fields
}

Sandbox represents a sandboxed execution environment

type SandboxInfo

type SandboxInfo struct {
	Type          string                 `json:"type"`
	Image         string                 `json:"image"`
	ID            string                 `json:"id"`
	CreatedAt     time.Time              `json:"created_at"`
	DestroyedAt   time.Time              `json:"destroyed_at,omitempty"`
	Status        string                 `json:"status"`
	Configuration map[string]interface{} `json:"configuration"`
}

SandboxInfo contains information about the sandbox environment

type SecurityFinding

type SecurityFinding struct {
	ID          string                 `json:"id"`
	Type        string                 `json:"type"`
	Severity    string                 `json:"severity"`
	Title       string                 `json:"title"`
	Description string                 `json:"description"`
	Evidence    []string               `json:"evidence"`
	Remediation string                 `json:"remediation"`
	Confidence  float64                `json:"confidence"`
	Timestamp   time.Time              `json:"timestamp"`
	Metadata    map[string]interface{} `json:"metadata"`
}

SecurityFinding represents a security-related finding

type SecurityViolation

type SecurityViolation struct {
	Type        string                 `json:"type"`
	Description string                 `json:"description"`
	Severity    string                 `json:"severity"`
	Timestamp   time.Time              `json:"timestamp"`
	Context     map[string]interface{} `json:"context"`
}

SecurityViolation represents a security policy violation

Jump to

Keyboard shortcuts

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