suriwrap

package module
v0.0.8 Latest Latest
Warning

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

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

README

suriwrap

A Go library for using Suricata as a library.

Installation

go get github.com/VaiTon/suriwrap

Usage

// we won't check for errors in this example, but you should in your code

rules := []string{
	"alert http any any -> any any (msg:\"Test rule\"; sid:1;)",
}
config := suriwrap.Config{...}
suri, _ := suriwrap.NewEngine(config, rules)

_ := suri.Start()

pw := suri.PcapWriter()

go func() {
	pw.WriteFileHeader(...)
	pw.WritePacket(...)
}()

go func() {
	for e = range e.EveLines() {
		fmt.Println("Received event:", e)
	}
}()


time.Sleep(2 * time.Second) // wait for some events
p.Stop()

Documentation

For more detailed documentation, please refer to the GoDoc page.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	SuricataPath  string   // Path to the Suricata binary (default is "suricata")
	CaptureOutput bool     // Whether to capture output from Suricata
	Args          []string // Additional command line arguments for Suricata
}

Config holds the configuration for the Suricata engine.

type Engine

type Engine struct {
	Config
	// contains filtered or unexported fields
}

Engine represents a Suricata engine instance that can be started and stopped. It manages Suricata processes, rules, and input/output files. It provides methods to start/stop Suricata, add/remove rules, and read EVE JSON output. It also provides a PCAP writer for sending packets to Suricata.

func NewEngine

func NewEngine(config Config, rules []string) *Engine

NewEngine creates a new Suricata engine instance with the given configuration and rules.

You should call Start() to start the Suricata process.

func (*Engine) AddRule

func (e *Engine) AddRule(rule string)

AddRule adds a new rule to the Suricata engine.

You should call Reload() to apply the new rule.

func (*Engine) ClearRules

func (e *Engine) ClearRules()

ClearRules removes all rules from the Suricata engine.

func (*Engine) EveLines

func (e *Engine) EveLines() <-chan eve.Event

EveLines returns a channel that streams EVE JSON lines parsed into EveLine structs.

func (*Engine) EveOutput added in v0.0.8

func (e *Engine) EveOutput() <-chan []byte

EveOutput returns a channel that streams raw EVE JSON lines from the Suricata engine.

func (*Engine) ListRules

func (e *Engine) ListRules() []string

ListRules returns the current list of rules in the Suricata engine.

func (*Engine) Reload

func (e *Engine) Reload() error

Reload instructs Suricata to reload its rules, by writing the current rules to the temporary rules file and sending a USR2 signal to the Suricata process.

func (*Engine) RemoveRule

func (e *Engine) RemoveRule(idx int) error

RemoveRule removes a rule by index from the Suricata engine.

You should call Reload() to apply the changes.

func (*Engine) SetSuricataPath

func (e *Engine) SetSuricataPath(path string)

SetSuricataPath sets the path to the Suricata binary.

func (*Engine) Start

func (e *Engine) Start() error

Start initializes and starts the Suricata engine.

It creates necessary temporary files and pipes, writes initial rules, and starts the Suricata process with the specified arguments.

func (*Engine) Stop

func (e *Engine) Stop() error

Stop gracefully stops the Suricata engine and cleans up resources. It sends a SIGTERM signal to the Suricata process, waits for it to exit, and then closes the named pipes and temporary files.

func (*Engine) Writer added in v0.0.7

func (e *Engine) Writer() io.Writer

Writer returns an io.Writer that can be used to send a PCAP stream to Suricata.

Directories

Path Synopsis
cmd
eveprint command
Package eve defines the structure of the EVE JSON output from Suricata.
Package eve defines the structure of the EVE JSON output from Suricata.

Jump to

Keyboard shortcuts

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