Documentation
¶
Index ¶
- type BanHandler
- type Config
- type EveAlert
- type EveReader
- type Event
- type EventLogger
- func (l *EventLogger) Close() error
- func (l *EventLogger) LogBanAction(ip string, filter string, score int, threshold int, banTime time.Duration, ...) error
- func (l *EventLogger) LogError(context string, err error) error
- func (l *EventLogger) LogEvent(event *Event, score int, threshold int, action string, decision string) error
- type FilterConfig
- type FilterMatcher
- type IPScore
- type NetlinkBanHandler
- type Processor
- type ProcessorConfig
- type Scorer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BanHandler ¶
BanHandler defines the interface for banning IPs
type Config ¶
type Config struct {
GlobalEnabled bool
DefaultThreshold int
DefaultBanTime time.Duration
DefaultAction string
ScoreDecay time.Duration
Filters map[string]*FilterConfig
}
Config holds the complete Suricata filter configuration
func LoadConfig ¶
LoadConfig loads Suricata filter configuration from files Loads filters.conf first, then filters.conf.local overrides
func (*Config) GetEnabledFilters ¶
func (c *Config) GetEnabledFilters() map[string]*FilterConfig
GetEnabledFilters returns only enabled filters
type EveAlert ¶
type EveAlert struct {
Timestamp string `json:"timestamp"`
EventType string `json:"event_type"`
SrcIP string `json:"src_ip"`
SrcPort int `json:"src_port"`
DestIP string `json:"dest_ip"`
DestPort int `json:"dest_port"`
Proto string `json:"proto"`
Alert struct {
SignatureID int `json:"signature_id"`
Signature string `json:"signature"`
Category string `json:"category"`
Severity int `json:"severity"` // 1=High, 2=Medium, 3=Low, 4=Info
Action string `json:"action"`
} `json:"alert"`
HTTP *struct {
Hostname string `json:"hostname"`
URL string `json:"url"`
Method string `json:"http_method"`
} `json:"http,omitempty"`
SSH *struct {
Client string `json:"client"`
Server string `json:"server"`
Version string `json:"proto_version"`
} `json:"ssh,omitempty"`
}
EveAlert represents a Suricata eve.json alert entry
type EveReader ¶
type EveReader struct {
// contains filtered or unexported fields
}
EveReader reads and parses Suricata eve.json log file
func NewEveReader ¶
func NewEveReader(evePath string, matcher *FilterMatcher) (*EveReader, error)
NewEveReader creates a new eve.json reader
func (*EveReader) ReadEvent ¶
ReadEvent reads the next event from eve.json Returns nil if no event available (non-blocking)
func (*EveReader) ReadEvents ¶
ReadEvents continuously reads events from eve.json Sends events to the provided channel
type Event ¶
type Event struct {
Timestamp time.Time
EventType string // "alert", "http", "ssh", etc.
SrcIP string
SrcPort int
DestIP string
DestPort int
Proto string
SignatureID int
Signature string
Category string
Severity int // 1=High, 2=Medium, 3=Low, 4=Info
Filter string // Matched filter name (e.g., "ssh", "http")
}
Event represents a normalized Suricata event for NFTBan processing
type EventLogger ¶
type EventLogger struct {
// contains filtered or unexported fields
}
EventLogger logs Suricata events and actions to file
func NewEventLogger ¶
func NewEventLogger(logPath string) (*EventLogger, error)
NewEventLogger creates a new event logger
func (*EventLogger) LogBanAction ¶
func (l *EventLogger) LogBanAction(ip string, filter string, score int, threshold int, banTime time.Duration, reason string) error
LogBanAction logs a Suricata-triggered ban action with score details
type FilterConfig ¶
type FilterConfig struct {
Name string
Enabled bool
Keywords []string
Threshold int
BanTime time.Duration
Action string // "log", "observe", "ban"
BanType string // "temporary", "permanent", "escalate"
MaxBans int // For escalate: after X temp bans, go permanent
Period time.Duration // For escalate: count bans in this period
Description string
}
FilterConfig represents a single Suricata filter configuration
type FilterMatcher ¶
type FilterMatcher struct {
// contains filtered or unexported fields
}
FilterMatcher handles matching Suricata signatures to filters
func NewFilterMatcher ¶
func NewFilterMatcher(config *Config) *FilterMatcher
NewFilterMatcher creates a new filter matcher
func (*FilterMatcher) GetFilterForEvent ¶
func (fm *FilterMatcher) GetFilterForEvent(signature, category string) (string, *FilterConfig)
GetFilterForEvent determines which filter matches an event Tries signature first, then category, returns first match
func (*FilterMatcher) MatchCategory ¶
func (fm *FilterMatcher) MatchCategory(category string) (string, *FilterConfig)
MatchCategory matches a Suricata category against configured filters
func (*FilterMatcher) MatchSignature ¶
func (fm *FilterMatcher) MatchSignature(signature string) (string, *FilterConfig)
MatchSignature matches a Suricata signature against configured filters Returns the matching filter name, or empty string if no match
type IPScore ¶
type IPScore struct {
IP string
CurrentScore int
Events []time.Time // Timestamps of recent events (capped to MaxEventsPerIP)
LastUpdate time.Time
TotalEvents int
// contains filtered or unexported fields
}
IPScore tracks scoring for a single IP address
type NetlinkBanHandler ¶
type NetlinkBanHandler struct {
// contains filtered or unexported fields
}
NetlinkBanHandler implements BanHandler using the existing netlink infrastructure This matches the existing fail2ban approach - uses sync.NFTManager for banning
func NewNetlinkBanHandler ¶
func NewNetlinkBanHandler() (*NetlinkBanHandler, error)
NewNetlinkBanHandler creates a new ban handler using the existing netlink infrastructure
func (*NetlinkBanHandler) BanIP ¶
BanIP bans an IP using the existing netlink/nftables infrastructure This is the same mechanism used by fail2ban integration
func (*NetlinkBanHandler) Close ¶
func (h *NetlinkBanHandler) Close()
Close closes the ban handler and cleans up resources
type Processor ¶
type Processor struct {
// contains filtered or unexported fields
}
Processor handles the main Suricata event processing loop
func NewProcessor ¶
func NewProcessor(cfg *ProcessorConfig) (*Processor, error)
NewProcessor creates a new Suricata event processor
type ProcessorConfig ¶
type ProcessorConfig struct {
ConfigDir string
EvePath string
LogPath string
BanHandler BanHandler
}
ProcessorConfig holds configuration for the processor
type Scorer ¶
type Scorer struct {
// contains filtered or unexported fields
}
Scorer calculates threat scores for IPs based on Suricata events Implements bounded memory via LRU eviction and per-IP event caps. Protects against CWE-400 (Uncontrolled Resource Consumption).
func (*Scorer) GetAllScores ¶
GetAllScores returns all current IP scores
func (*Scorer) GetIPScore ¶
GetIPScore returns full scoring details for an IP
func (*Scorer) ResetScore ¶
ResetScore resets the score for an IP (e.g., after banning)