Documentation
¶
Index ¶
- Variables
- func AddBehavioralAlert(alert BehavioralAlert)
- func AnalyzeBehavior(event FileEvent, logger *zap.Logger)
- func BasicAuthMiddleware(next http.HandlerFunc, username, password string) http.HandlerFunc
- func LoadConfig(configPath string) error
- func SetConfigForTest(cfg Config)
- func Start(rootDir, configFile, httpAddr, authUser, authPassword string, concurrency int)
- func StartBehavioralMonitoring(logger *zap.Logger)
- func UpdateThreatFeed(logger *zap.Logger) error
- func WalkLimit(ctx context.Context, root string, walkFn filepath.WalkFunc, limit int) error
- func WalkLimitWithFilter(ctx context.Context, root string, walkFn filepath.WalkFunc, limit int, ...) error
- func WalkLimitWithOptions(ctx context.Context, root string, walkFn filepath.WalkFunc, opts WalkOptions) error
- func WalkLimitWithProgress(ctx context.Context, root string, walkFn filepath.WalkFunc, limit int, ...) error
- type BehavioralAlert
- type Config
- type ErrorHandling
- type FileEvent
- type FileMonitor
- type FileMonitorOptions
- type FilterOptions
- type HTTPClientInterface
- type LogLevel
- type MemoryLimit
- type ProcessInfo
- type ProgressFn
- type Stats
- type SymlinkHandling
- type WalkOptions
Constants ¶
This section is empty.
Variables ¶
var SuspiciousExecutionPaths = []string{
"/tmp",
"/var/tmp",
"/dev/shm",
"/run",
"/var/run",
"/proc",
"C:\\Windows\\Temp",
"C:\\Temp",
"C:\\Users\\Public",
}
SuspiciousExecutionPaths contains paths that are suspicious for executing files from
var SuspiciousPaths = []string{
"/etc/passwd",
"/etc/shadow",
"/etc/sudoers",
"/etc/ssh",
"/etc/crontab",
"/etc/cron.d",
"/boot",
"/sbin",
"/bin",
"/usr/bin",
"/usr/sbin",
"/usr/local/bin",
"/lib",
"/lib64",
"/usr/lib",
"/usr/lib64",
"/System/Library",
"/Library/StartupItems",
"/Library/LaunchAgents",
"/Library/LaunchDaemons",
"C:\\Windows\\System32",
"C:\\Windows\\SysWOW64",
"C:\\Program Files",
"C:\\Program Files (x86)",
"C:\\Windows\\Tasks",
"C:\\Windows\\Temp",
}
SuspiciousPaths contains paths that are sensitive and should be monitored for modifications
var SuspiciousProcessNames = []string{
"nc", "netcat", "ncat",
"socat", "cryptcat",
"nmap", "zenmap",
"wireshark", "tcpdump",
"mimikatz",
"psexec",
"powershell", "pwsh",
"cmd.exe",
"bash", "sh", "zsh",
"python", "python3", "perl", "ruby",
"wget", "curl",
"ssh", "telnet", "rdesktop",
}
SuspiciousProcessNames contains process names that are commonly associated with malicious activity
Functions ¶
func AddBehavioralAlert ¶
func AddBehavioralAlert(alert BehavioralAlert)
AddBehavioralAlert adds a new behavioral alert to the global store
func AnalyzeBehavior ¶
AnalyzeBehavior analyzes a file event for suspicious behavior
func BasicAuthMiddleware ¶
func BasicAuthMiddleware(next http.HandlerFunc, username, password string) http.HandlerFunc
BasicAuthMiddleware provides basic authentication. In production, use a *real* auth system.
func LoadConfig ¶
Load configuration from external sources (file, env, etc.) - Good for production.
func SetConfigForTest ¶
func SetConfigForTest(cfg Config)
SetConfigForTest sets the global configuration for testing purposes. This function should only be used in tests.
func StartBehavioralMonitoring ¶
StartBehavioralMonitoring initializes behavioral monitoring
func UpdateThreatFeed ¶
UpdateThreatFeed fetches and updates the malicious hashes from a threat feed. Exported for testing.
func WalkLimitWithFilter ¶
func WalkLimitWithFilter(ctx context.Context, root string, walkFn filepath.WalkFunc, limit int, filter FilterOptions) error
WalkLimitWithFilter walks the file tree with a limit on concurrency and applies filtering. Exported for testing.
func WalkLimitWithOptions ¶
func WalkLimitWithOptions(ctx context.Context, root string, walkFn filepath.WalkFunc, opts WalkOptions) error
WalkLimitWithOptions provides flexible, enterprise-grade traversal.
func WalkLimitWithProgress ¶
func WalkLimitWithProgress(ctx context.Context, root string, walkFn filepath.WalkFunc, limit int, progressFn ProgressFn) error
WalkLimitWithProgress walks the file tree with a limit on concurrency and reports progress. Exported for testing.
Types ¶
type BehavioralAlert ¶
type BehavioralAlert struct { Timestamp time.Time `json:"timestamp"` Type string `json:"type"` Description string `json:"description"` Severity string `json:"severity"` // "low", "medium", "high", "critical" ProcessInfo ProcessInfo `json:"process_info,omitempty"` FileEvent *FileEvent `json:"file_event,omitempty"` RelatedPaths []string `json:"related_paths,omitempty"` }
BehavioralAlert represents a suspicious behavior detected by the system
func GetBehavioralAlerts ¶
func GetBehavioralAlerts() []BehavioralAlert
GetBehavioralAlerts returns all behavioral alerts
type Config ¶
type Config struct { MaliciousHashes map[string]bool `json:"malicious_hashes"` SuspiciousExtensions []string `json:"suspicious_extensions"` MaxSizeThreshold int64 `json:"max_size_threshold"` // In bytes YaraRules []string // Add Yara rules support ThreatFeedURL string `json:"threat_feed_url"` // URL for dynamic threat feed ThreatFeedInterval time.Duration `json:"threat_feed_interval"` // How often to refresh LogFilePath string `json:"log_file_path"` // Path for log file }
--------------------------------------------------------------------------
Configuration and External Data
--------------------------------------------------------------------------
type ErrorHandling ¶
type ErrorHandling int
const ( ErrorHandlingContinue ErrorHandling = iota ErrorHandlingStop ErrorHandlingSkip )
type FileEvent ¶
type FileEvent struct { Path string `json:"path"` Hash string `json:"hash"` Size int64 `json:"size"` Mode os.FileMode `json:"mode"` ModTime time.Time `json:"mod_time"` Suspicious bool `json:"suspicious"` Reason string `json:"reason"` Timestamp time.Time `json:"timestamp"` User string `json:"user,omitempty"` // User who owns the file (if available) Process string `json:"process,omitempty"` // Process associated to the file (if available) - Requires more advanced monitoring ParentProcess string `json:"parent_process,omitempty"` // Useful in advanced investigations PID int `json:"pid,omitempty"` // Process ID that modified the file PPID int `json:"ppid,omitempty"` // Parent Process ID CmdLine string `json:"cmdline,omitempty"` // Full command line of the process NetConnections []string `json:"net_connections,omitempty"` // Network connections associated with the process }
type FileMonitor ¶
type FileMonitor struct {
// contains filtered or unexported fields
}
FileMonitor represents a real-time file monitor
func MonitorDirectories ¶
func MonitorDirectories(ctx context.Context, paths []string, recursive bool, eventHandler func(FileEvent), logger *zap.Logger) (*FileMonitor, error)
MonitorDirectories starts real-time monitoring of directories
func NewFileMonitor ¶
func NewFileMonitor(options FileMonitorOptions) (*FileMonitor, error)
NewFileMonitor creates a new file monitor
type FileMonitorOptions ¶
type FileMonitorOptions struct { Paths []string // Paths to monitor RecursiveWatch bool // Whether to watch directories recursively EventHandler func(FileEvent) // Function to call when a file event is detected ExcludePaths []string // Paths to exclude from monitoring IncludePatterns []string // File patterns to include (e.g., "*.exe") ExcludePatterns []string // File patterns to exclude Logger *zap.Logger // Logger to use }
FileMonitorOptions contains options for real-time file monitoring
type FilterOptions ¶
type HTTPClientInterface ¶
HTTPClientInterface defines the interface for HTTP clients
var HTTPClient HTTPClientInterface = http.DefaultClient
HTTPClient is the client used for HTTP requests, can be mocked in tests
type MemoryLimit ¶
type ProcessInfo ¶
type ProcessInfo struct { PID int PPID int ProcessName string CmdLine string NetConnections []string }
ProcessInfo contains information about a process
type ProgressFn ¶
type ProgressFn func(stats Stats)
type Stats ¶
type Stats struct { FilesProcessed int64 // Number of files processed DirsProcessed int64 // Number of directories processed EmptyDirs int64 // Number of empty directories BytesProcessed int64 // Total bytes processed ErrorCount int64 // Number of errors encountered ElapsedTime time.Duration // Total time elapsed AvgFileSize int64 // Average file size in bytes SpeedMBPerSec float64 // Processing speed in MB/s }
type SymlinkHandling ¶
type SymlinkHandling int
const ( SymlinkFollow SymlinkHandling = iota SymlinkIgnore SymlinkReport )
type WalkOptions ¶
type WalkOptions struct { ErrorHandling ErrorHandling Filter FilterOptions Progress ProgressFn Logger *zap.Logger LogLevel LogLevel BufferSize int SymlinkHandling SymlinkHandling MemoryLimit MemoryLimit }