Documentation
¶
Overview ¶
Package injection provides packet manipulation and injection capabilities for offensive security testing and network research.
Index ¶
- Variables
- func CompileRules(config *Config) error
- func GetFirewallManager() *firewall.Manager
- func IsNFQueueSupported() bool
- func PrintBanner()
- func SetFirewallManager(manager *firewall.Manager)
- func ValidateAction(action Action) bool
- type ARPPacketConfig
- type ARPSpoofHandler
- type Action
- type ActionHandler
- type ActionResult
- type Config
- type DNSQueryConfig
- type DNSResponseConfig
- type DNSSpoofHandler
- type DelayHandler
- type Engine
- type EngineConfig
- type EngineStats
- type EngineStatsSnapshot
- type HTTPInjectHeaderHandler
- type HTTPRedirectHandler
- type HTTPSSLStripHandler
- type ICMPPacketConfig
- type IPTablesBlockHandler
- type IPTablesLogHandler
- type IPTablesRateLimitHandler
- type IPTablesRejectHandler
- type InjectionContext
- func (ctx *InjectionContext) DstIP() string
- func (ctx *InjectionContext) DstPort() uint16
- func (ctx *InjectionContext) HasARP() bool
- func (ctx *InjectionContext) HasDNS() bool
- func (ctx *InjectionContext) HasTCP() bool
- func (ctx *InjectionContext) HasUDP() bool
- func (ctx *InjectionContext) Protocol() string
- func (ctx *InjectionContext) SrcIP() string
- func (ctx *InjectionContext) SrcPort() uint16
- type ModifyPayloadHandler
- type NFQueueHandler
- type PacketBuilder
- func (pb *PacketBuilder) BuildARPPacket(config ARPPacketConfig) ([]byte, error)
- func (pb *PacketBuilder) BuildARPReplyPacket(senderMAC, targetMAC net.HardwareAddr, senderIP, targetIP net.IP) ([]byte, error)
- func (pb *PacketBuilder) BuildARPRequestPacket(senderMAC net.HardwareAddr, senderIP, targetIP net.IP) ([]byte, error)
- func (pb *PacketBuilder) BuildDNSQueryPacket(config DNSQueryConfig) ([]byte, error)
- func (pb *PacketBuilder) BuildDNSResponsePacket(config DNSResponseConfig) ([]byte, error)
- func (pb *PacketBuilder) BuildGratuitousARPPacket(mac net.HardwareAddr, ip net.IP) ([]byte, error)
- func (pb *PacketBuilder) BuildICMPEchoReply(srcMAC, dstMAC net.HardwareAddr, srcIP, dstIP net.IP, id, seq uint16, ...) ([]byte, error)
- func (pb *PacketBuilder) BuildICMPEchoRequest(srcMAC, dstMAC net.HardwareAddr, srcIP, dstIP net.IP, id, seq uint16, ...) ([]byte, error)
- func (pb *PacketBuilder) BuildICMPPacket(config ICMPPacketConfig) ([]byte, error)
- func (pb *PacketBuilder) BuildTCPPacket(config TCPPacketConfig) ([]byte, error)
- func (pb *PacketBuilder) BuildTCPRSTPacket(srcMAC, dstMAC net.HardwareAddr, srcIP, dstIP net.IP, srcPort, dstPort uint16, ...) ([]byte, error)
- func (pb *PacketBuilder) BuildTCPSYNACKPacket(srcMAC, dstMAC net.HardwareAddr, srcIP, dstIP net.IP, srcPort, dstPort uint16, ...) ([]byte, error)
- func (pb *PacketBuilder) BuildTCPSYNPacket(srcMAC, dstMAC net.HardwareAddr, srcIP, dstIP net.IP, srcPort, dstPort uint16, ...) ([]byte, error)
- func (pb *PacketBuilder) BuildUDPPacket(config UDPPacketConfig) ([]byte, error)
- type PacketDirection
- type RawInjector
- type Rule
- type TCPFlags
- type TCPPacketConfig
- type TCPRSTHandler
- type UDPPacketConfig
Constants ¶
This section is empty.
Variables ¶
var DefaultEngineConfig = EngineConfig{ QueueNum: 0, MaxQueueLen: 1024, DefaultAction: ActionAccept, Verbose: false, DryRun: false, LogActions: true, LogFile: "injection.log", }
DefaultEngineConfig returns a sane default configuration.
Functions ¶
func CompileRules ¶
CompileRules compiles all rule expressions in the configuration.
func GetFirewallManager ¶
GetFirewallManager returns the global firewall manager.
func PrintBanner ¶
func PrintBanner()
PrintBanner prints the warning banner for the injection engine.
func SetFirewallManager ¶
SetFirewallManager sets the global firewall manager for iptables actions.
func ValidateAction ¶
ValidateAction checks if an action string is valid.
Types ¶
type ARPPacketConfig ¶
type ARPPacketConfig struct {
SrcMAC net.HardwareAddr
DstMAC net.HardwareAddr
SenderMAC net.HardwareAddr
SenderIP net.IP
TargetMAC net.HardwareAddr
TargetIP net.IP
Operation uint16 // layers.ARPRequest or layers.ARPReply
IsGratuitous bool
}
ARPPacketConfig holds configuration for building ARP packets.
type ARPSpoofHandler ¶
type ARPSpoofHandler struct{}
ARPSpoofHandler handles ARP reply spoofing.
func (*ARPSpoofHandler) Execute ¶
func (h *ARPSpoofHandler) Execute(ctx *InjectionContext, config map[string]any) (*ActionResult, error)
Execute generates a spoofed ARP reply.
type Action ¶
type Action string
Action represents the type of injection action to perform.
const ( // ActionAccept forwards the packet unchanged. ActionAccept Action = "accept" // ActionDrop silently drops the packet. ActionDrop Action = "drop" // ActionModifyPayload modifies the packet payload using search/replace. ActionModifyPayload Action = "modify_payload" // ActionInjectPacket injects an additional crafted packet. ActionInjectPacket Action = "inject_packet" // ActionInjectTCPRST sends a TCP RST to terminate the connection. ActionInjectTCPRST Action = "inject_tcp_rst" // ActionInjectDNS spoofs a DNS response. ActionInjectDNS Action = "inject_dns" // ActionInjectARP sends a spoofed ARP reply. ActionInjectARP Action = "inject_arp" // ActionDelay delays packet forwarding by a specified duration. ActionDelay Action = "delay" // ActionHTTPInjectHeader injects or modifies HTTP headers. ActionHTTPInjectHeader Action = "http_inject_header" // ActionHTTPSSLStrip downgrades HTTPS links to HTTP in responses. ActionHTTPSSLStrip Action = "http_ssl_strip" // ActionHTTPRedirect injects an HTTP redirect response. ActionHTTPRedirect Action = "http_redirect" // ActionIPTablesBlock blocks an IP/CIDR using iptables DROP. ActionIPTablesBlock Action = "iptables_block" // ActionIPTablesReject rejects traffic with ICMP response. ActionIPTablesReject Action = "iptables_reject" // ActionIPTablesRateLimit rate-limits traffic from/to an IP. ActionIPTablesRateLimit Action = "iptables_rate_limit" // ActionIPTablesLog logs matching traffic via iptables LOG target. ActionIPTablesLog Action = "iptables_log" )
type ActionHandler ¶
type ActionHandler interface {
Execute(ctx *InjectionContext, config map[string]any) (*ActionResult, error)
}
ActionHandler is an interface for implementing injection actions.
func GetActionHandler ¶
func GetActionHandler(action Action) (ActionHandler, error)
GetActionHandler returns the appropriate handler for an action type.
type ActionResult ¶
type ActionResult struct {
// Action is the action that was executed.
Action Action
// Success indicates if the action completed successfully.
Success bool
// Error contains any error that occurred.
Error error
// ModifiedPacket is the modified packet data (for modify actions).
ModifiedPacket []byte
// InjectPackets are additional packets to inject.
InjectPackets [][]byte
// Drop indicates the original packet should be dropped.
Drop bool
// Delay specifies how long to delay the packet.
Delay time.Duration
// RuleName is the name of the rule that triggered this action.
RuleName string
// Timestamp is when the action was executed.
Timestamp time.Time
// Details contains action-specific details for logging.
Details map[string]any
}
ActionResult represents the outcome of an injection action.
type Config ¶
type Config struct {
// Description provides information about this rule set.
Description string `yaml:"description"`
// Rules is the list of injection rules.
Rules []*Rule `yaml:"rules"`
}
Config holds a collection of injection rules loaded from a YAML file.
func LoadEmbeddedRules ¶
LoadEmbeddedRules loads the embedded default injection rules. These are bundled into the binary at compile time.
func LoadRulesFromDirectory ¶
LoadRulesFromDirectory loads all rule files from a directory and returns a merged configuration.
func LoadRulesFromFile ¶
LoadRulesFromFile loads injection rules from a YAML file.
func LoadRulesWithEmbeddedDefaults ¶
LoadRulesWithEmbeddedDefaults loads rules from a file/directory path, but first loads embedded defaults. File rules override embedded rules with the same name.
type DNSQueryConfig ¶
type DNSQueryConfig struct {
SrcMAC net.HardwareAddr
DstMAC net.HardwareAddr
SrcIP net.IP
DstIP net.IP
SrcPort uint16
DstPort uint16 // Usually 53
QueryID uint16
QueryName string
QueryType layers.DNSType
TTL uint8
}
DNSQueryConfig holds configuration for building DNS query packets.
type DNSResponseConfig ¶
type DNSResponseConfig struct {
SrcMAC net.HardwareAddr
DstMAC net.HardwareAddr
SrcIP net.IP
DstIP net.IP
SrcPort uint16 // Usually 53
DstPort uint16
QueryID uint16
QueryName string
QueryType layers.DNSType
ResponseIP net.IP
ResponseTTL uint32
TTL uint8
}
DNSResponseConfig holds configuration for building DNS response packets.
type DNSSpoofHandler ¶
type DNSSpoofHandler struct{}
DNSSpoofHandler handles DNS response spoofing.
func (*DNSSpoofHandler) Execute ¶
func (h *DNSSpoofHandler) Execute(ctx *InjectionContext, config map[string]any) (*ActionResult, error)
Execute generates a spoofed DNS response.
type DelayHandler ¶
type DelayHandler struct{}
DelayHandler handles packet delay actions.
func (*DelayHandler) Execute ¶
func (h *DelayHandler) Execute(ctx *InjectionContext, config map[string]any) (*ActionResult, error)
Execute returns a result indicating the packet should be delayed.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is the core injection engine that evaluates rules and executes actions.
func NewEngine ¶
func NewEngine(rulesPath string, eConfig *EngineConfig) (*Engine, error)
NewEngine creates a new injection engine with the given configuration.
func (*Engine) GetEnabledRulesCount ¶
GetEnabledRulesCount returns the number of enabled rules.
func (*Engine) GetStats ¶
func (e *Engine) GetStats() EngineStatsSnapshot
GetStats returns a snapshot of the current statistics.
func (*Engine) ProcessPacket ¶
ProcessPacket evaluates all rules against a packet and returns actions to perform.
type EngineConfig ¶
type EngineConfig struct {
// RulesPath is the path to rules file or directory.
RulesPath string
// QueueNum is the nfqueue number to use.
QueueNum uint16
// Interface is the network interface for packet injection.
Interface string
// AutoIPTables enables automatic iptables rule configuration.
AutoIPTables bool
// IPTablesTarget specifies the iptables target filter (e.g., "-d 192.168.1.0/24").
IPTablesTarget string
// Verbose enables verbose logging.
Verbose bool
// DryRun if true, evaluates rules but does not actually inject or modify packets.
DryRun bool
// LogActions if true, logs all injection actions to a file.
LogActions bool
// LogFile is the path to the action log file.
LogFile string
// MaxQueueLen is the maximum number of packets to queue.
MaxQueueLen uint32
// DefaultAction is the action to take when no rules match.
DefaultAction Action
}
EngineConfig holds configuration for the injection engine.
type EngineStats ¶
type EngineStats struct {
// Atomic counters for high-performance updates
PacketsProcessed atomic.Uint64
PacketsMatched atomic.Uint64
ActionsExecuted atomic.Uint64
PacketsDropped atomic.Uint64
PacketsModified atomic.Uint64
PacketsInjected atomic.Uint64
Errors atomic.Uint64
// Per-rule match counts (requires mutex)
RuleMatches map[string]uint64
// Per-action counts (requires mutex)
ActionCounts map[Action]uint64
// Start time
StartTime time.Time
// contains filtered or unexported fields
}
EngineStats tracks injection engine statistics using atomic operations for counters.
func NewEngineStats ¶
func NewEngineStats() *EngineStats
NewEngineStats creates new statistics tracker.
type EngineStatsSnapshot ¶
type EngineStatsSnapshot struct {
PacketsProcessed uint64
PacketsMatched uint64
ActionsExecuted uint64
PacketsDropped uint64
PacketsModified uint64
PacketsInjected uint64
Errors uint64
RuleMatches map[string]uint64
ActionCounts map[Action]uint64
StartTime time.Time
}
EngineStatsSnapshot is a snapshot of engine statistics for reporting.
type HTTPInjectHeaderHandler ¶
type HTTPInjectHeaderHandler struct{}
HTTPInjectHeaderHandler handles HTTP header injection/modification.
func (*HTTPInjectHeaderHandler) Execute ¶
func (h *HTTPInjectHeaderHandler) Execute(ctx *InjectionContext, config map[string]any) (*ActionResult, error)
Execute injects or modifies HTTP headers in the payload. Supports the following action_config options:
- headers: map[string]string of headers to inject/modify
- remove_headers: []string of header names to remove
- position: "request" or "response" (which headers to modify)
type HTTPRedirectHandler ¶
type HTTPRedirectHandler struct{}
HTTPRedirectHandler handles HTTP redirect injection.
func (*HTTPRedirectHandler) Execute ¶
func (h *HTTPRedirectHandler) Execute(ctx *InjectionContext, config map[string]any) (*ActionResult, error)
Execute creates an HTTP redirect response. Supports the following action_config options:
- location: URL to redirect to (required)
- status_code: HTTP status code (default: 302)
type HTTPSSLStripHandler ¶
type HTTPSSLStripHandler struct{}
HTTPSSLStripHandler handles SSL stripping by downgrading HTTPS to HTTP.
func (*HTTPSSLStripHandler) Execute ¶
func (h *HTTPSSLStripHandler) Execute(ctx *InjectionContext, config map[string]any) (*ActionResult, error)
Execute replaces HTTPS URLs with HTTP in the payload. This is commonly used in SSL stripping attacks.
type ICMPPacketConfig ¶
type ICMPPacketConfig struct {
SrcMAC net.HardwareAddr
DstMAC net.HardwareAddr
SrcIP net.IP
DstIP net.IP
Type layers.ICMPv4TypeCode
ID uint16
Seq uint16
Payload []byte
TTL uint8
}
ICMPPacketConfig holds configuration for building ICMP packets.
type IPTablesBlockHandler ¶
type IPTablesBlockHandler struct{}
IPTablesBlockHandler handles iptables block actions.
func (*IPTablesBlockHandler) Execute ¶
func (h *IPTablesBlockHandler) Execute(ctx *InjectionContext, config map[string]any) (*ActionResult, error)
Execute blocks the source or destination IP via iptables.
type IPTablesLogHandler ¶
type IPTablesLogHandler struct{}
IPTablesLogHandler handles iptables log actions.
func (*IPTablesLogHandler) Execute ¶
func (h *IPTablesLogHandler) Execute(ctx *InjectionContext, config map[string]any) (*ActionResult, error)
Execute logs traffic matching the rule via iptables LOG target.
type IPTablesRateLimitHandler ¶
type IPTablesRateLimitHandler struct{}
IPTablesRateLimitHandler handles iptables rate limiting actions.
func (*IPTablesRateLimitHandler) Execute ¶
func (h *IPTablesRateLimitHandler) Execute(ctx *InjectionContext, config map[string]any) (*ActionResult, error)
Execute rate-limits traffic from/to an IP.
type IPTablesRejectHandler ¶
type IPTablesRejectHandler struct{}
IPTablesRejectHandler handles iptables reject actions.
func (*IPTablesRejectHandler) Execute ¶
func (h *IPTablesRejectHandler) Execute(ctx *InjectionContext, config map[string]any) (*ActionResult, error)
Execute rejects traffic from/to an IP with an ICMP response.
type InjectionContext ¶
type InjectionContext struct {
// Packet is the decoded gopacket packet.
Packet gopacket.Packet
// RawData is the raw packet bytes.
RawData []byte
// Timestamp is when the packet was captured.
Timestamp time.Time
// Interface is the network interface the packet arrived on.
Interface string
// Direction indicates if packet is inbound or outbound.
Direction PacketDirection
// Ethernet layer (if present).
Ethernet *layers.Ethernet
// IPv4 layer (if present).
IPv4 *layers.IPv4
// IPv6 layer (if present).
IPv6 *layers.IPv6
// TCP layer (if present).
TCP *layers.TCP
// UDP layer (if present).
UDP *layers.UDP
// DNS layer (if present).
DNS *layers.DNS
// ARP layer (if present).
ARP *layers.ARP
// Payload is the application-layer payload.
Payload []byte
// AuditRecord is the decoded netcap audit record (if available).
AuditRecord types.AuditRecord
// Flow identifier string.
Flow string
// MatchedRules contains the names of rules that matched this packet.
MatchedRules []string
}
InjectionContext provides access to packet data and metadata during rule evaluation.
func NewInjectionContext ¶
func NewInjectionContext(pkt gopacket.Packet, iface string) *InjectionContext
NewInjectionContext creates a new InjectionContext from a gopacket.Packet.
func (*InjectionContext) DstIP ¶
func (ctx *InjectionContext) DstIP() string
DstIP returns the destination IP address as a string.
func (*InjectionContext) DstPort ¶
func (ctx *InjectionContext) DstPort() uint16
DstPort returns the destination port.
func (*InjectionContext) HasARP ¶
func (ctx *InjectionContext) HasARP() bool
HasARP returns true if the packet has an ARP layer.
func (*InjectionContext) HasDNS ¶
func (ctx *InjectionContext) HasDNS() bool
HasDNS returns true if the packet has a DNS layer.
func (*InjectionContext) HasTCP ¶
func (ctx *InjectionContext) HasTCP() bool
HasTCP returns true if the packet has a TCP layer.
func (*InjectionContext) HasUDP ¶
func (ctx *InjectionContext) HasUDP() bool
HasUDP returns true if the packet has a UDP layer.
func (*InjectionContext) Protocol ¶
func (ctx *InjectionContext) Protocol() string
Protocol returns the transport protocol.
func (*InjectionContext) SrcIP ¶
func (ctx *InjectionContext) SrcIP() string
SrcIP returns the source IP address as a string.
func (*InjectionContext) SrcPort ¶
func (ctx *InjectionContext) SrcPort() uint16
SrcPort returns the source port.
type ModifyPayloadHandler ¶
type ModifyPayloadHandler struct{}
ModifyPayloadHandler handles payload modification actions.
func (*ModifyPayloadHandler) Execute ¶
func (h *ModifyPayloadHandler) Execute(ctx *InjectionContext, config map[string]any) (*ActionResult, error)
Execute performs payload modification using search/replace or regex. Supports the following action_config options:
- search: string to search for (literal or regex pattern)
- replace: replacement string (supports regex capture groups like $1, $2 when regex=true)
- regex: bool (optional, default false) - if true, search is treated as a regex pattern
type NFQueueHandler ¶
type NFQueueHandler struct {
// contains filtered or unexported fields
}
NFQueueHandler handles packets from netfilter queue.
func NewNFQueueHandler ¶
func NewNFQueueHandler(engine *Engine, config *EngineConfig) (*NFQueueHandler, error)
NewNFQueueHandler creates a new nfqueue handler.
func (*NFQueueHandler) GetStats ¶
func (h *NFQueueHandler) GetStats() (received, accepted, dropped, modified uint64)
GetStats returns nfqueue handler statistics.
func (*NFQueueHandler) Start ¶
func (h *NFQueueHandler) Start() error
Start begins processing packets from the nfqueue.
func (*NFQueueHandler) Stop ¶
func (h *NFQueueHandler) Stop() error
Stop shuts down the nfqueue handler.
type PacketBuilder ¶
type PacketBuilder struct {
// Default TTL for IP packets
DefaultTTL uint8
// Default window size for TCP packets
DefaultWindow uint16
}
PacketBuilder provides utilities for constructing network packets.
func NewPacketBuilder ¶
func NewPacketBuilder() *PacketBuilder
NewPacketBuilder creates a new packet builder with default settings.
func (*PacketBuilder) BuildARPPacket ¶
func (pb *PacketBuilder) BuildARPPacket(config ARPPacketConfig) ([]byte, error)
BuildARPPacket constructs an ARP packet.
func (*PacketBuilder) BuildARPReplyPacket ¶
func (pb *PacketBuilder) BuildARPReplyPacket(senderMAC, targetMAC net.HardwareAddr, senderIP, targetIP net.IP) ([]byte, error)
BuildARPReplyPacket creates an ARP reply packet.
func (*PacketBuilder) BuildARPRequestPacket ¶
func (pb *PacketBuilder) BuildARPRequestPacket(senderMAC net.HardwareAddr, senderIP, targetIP net.IP) ([]byte, error)
BuildARPRequestPacket creates an ARP request packet.
func (*PacketBuilder) BuildDNSQueryPacket ¶
func (pb *PacketBuilder) BuildDNSQueryPacket(config DNSQueryConfig) ([]byte, error)
BuildDNSQueryPacket constructs a DNS query packet.
func (*PacketBuilder) BuildDNSResponsePacket ¶
func (pb *PacketBuilder) BuildDNSResponsePacket(config DNSResponseConfig) ([]byte, error)
BuildDNSResponsePacket constructs a DNS response packet.
func (*PacketBuilder) BuildGratuitousARPPacket ¶
func (pb *PacketBuilder) BuildGratuitousARPPacket(mac net.HardwareAddr, ip net.IP) ([]byte, error)
BuildGratuitousARPPacket creates a gratuitous ARP packet.
func (*PacketBuilder) BuildICMPEchoReply ¶
func (pb *PacketBuilder) BuildICMPEchoReply(srcMAC, dstMAC net.HardwareAddr, srcIP, dstIP net.IP, id, seq uint16, payload []byte) ([]byte, error)
BuildICMPEchoReply creates an ICMP echo reply packet.
func (*PacketBuilder) BuildICMPEchoRequest ¶
func (pb *PacketBuilder) BuildICMPEchoRequest(srcMAC, dstMAC net.HardwareAddr, srcIP, dstIP net.IP, id, seq uint16, payload []byte) ([]byte, error)
BuildICMPEchoRequest creates an ICMP echo request (ping) packet.
func (*PacketBuilder) BuildICMPPacket ¶
func (pb *PacketBuilder) BuildICMPPacket(config ICMPPacketConfig) ([]byte, error)
BuildICMPPacket constructs an ICMPv4 packet.
func (*PacketBuilder) BuildTCPPacket ¶
func (pb *PacketBuilder) BuildTCPPacket(config TCPPacketConfig) ([]byte, error)
BuildTCPPacket constructs a complete TCP packet.
func (*PacketBuilder) BuildTCPRSTPacket ¶
func (pb *PacketBuilder) BuildTCPRSTPacket(srcMAC, dstMAC net.HardwareAddr, srcIP, dstIP net.IP, srcPort, dstPort uint16, seq, ack uint32) ([]byte, error)
BuildTCPRSTPacket creates a TCP RST packet.
func (*PacketBuilder) BuildTCPSYNACKPacket ¶
func (pb *PacketBuilder) BuildTCPSYNACKPacket(srcMAC, dstMAC net.HardwareAddr, srcIP, dstIP net.IP, srcPort, dstPort uint16, seq, ack uint32) ([]byte, error)
BuildTCPSYNACKPacket creates a TCP SYN-ACK packet.
func (*PacketBuilder) BuildTCPSYNPacket ¶
func (pb *PacketBuilder) BuildTCPSYNPacket(srcMAC, dstMAC net.HardwareAddr, srcIP, dstIP net.IP, srcPort, dstPort uint16, seq uint32) ([]byte, error)
BuildTCPSYNPacket creates a TCP SYN packet.
func (*PacketBuilder) BuildUDPPacket ¶
func (pb *PacketBuilder) BuildUDPPacket(config UDPPacketConfig) ([]byte, error)
BuildUDPPacket constructs a complete UDP packet.
type PacketDirection ¶
type PacketDirection int
PacketDirection indicates packet flow direction.
const ( // DirectionUnknown when direction cannot be determined. DirectionUnknown PacketDirection = iota // DirectionInbound for packets coming into the system. DirectionInbound // DirectionOutbound for packets leaving the system. DirectionOutbound )
type RawInjector ¶
type RawInjector struct {
// contains filtered or unexported fields
}
RawInjector handles raw packet injection via raw sockets.
func NewRawInjector ¶
func NewRawInjector(iface string) (*RawInjector, error)
NewRawInjector creates a new raw packet injector for an interface.
func (*RawInjector) InjectPacket ¶
func (ri *RawInjector) InjectPacket(data []byte) error
InjectPacket sends a raw packet on the wire.
type Rule ¶
type Rule struct {
// Name is a unique identifier for the rule.
Name string `yaml:"name"`
// Description provides human-readable information about the rule.
Description string `yaml:"description"`
// Type specifies which audit record type this rule applies to (e.g., "TCP", "HTTP", "DNS").
Type string `yaml:"type"`
// Expression is the expr-lang expression to evaluate against packets.
Expression string `yaml:"expression"`
// Action specifies what action to perform when the rule matches.
Action Action `yaml:"action"`
// ActionConfig contains action-specific configuration parameters.
ActionConfig map[string]any `yaml:"action_config"`
// Enabled determines whether this rule is active.
Enabled bool `yaml:"enabled"`
// Priority determines rule evaluation order (higher = evaluated first).
Priority int `yaml:"priority,omitempty"`
// StopOnMatch if true, stops evaluating further rules after this one matches.
StopOnMatch bool `yaml:"stop_on_match,omitempty"`
// Tags are custom labels for categorizing rules.
Tags []string `yaml:"tags,omitempty"`
// contains filtered or unexported fields
}
Rule represents an injection rule that matches packets and performs actions.
func (*Rule) GetCompiled ¶
GetCompiled returns the compiled expression program.
func (*Rule) IsCompiled ¶
IsCompiled returns true if the rule has been compiled.
type TCPFlags ¶
type TCPFlags struct {
SYN bool
ACK bool
FIN bool
RST bool
PSH bool
URG bool
ECE bool
CWR bool
NS bool
}
TCPFlags represents TCP control flags.
type TCPPacketConfig ¶
type TCPPacketConfig struct {
SrcMAC net.HardwareAddr
DstMAC net.HardwareAddr
SrcIP net.IP
DstIP net.IP
SrcPort uint16
DstPort uint16
Seq uint32
Ack uint32
Flags TCPFlags
Window uint16
Payload []byte
TTL uint8
}
TCPPacketConfig holds configuration for building TCP packets.
type TCPRSTHandler ¶
type TCPRSTHandler struct{}
TCPRSTHandler handles TCP RST injection.
func (*TCPRSTHandler) Execute ¶
func (h *TCPRSTHandler) Execute(ctx *InjectionContext, config map[string]any) (*ActionResult, error)
Execute generates and returns a TCP RST packet.
type UDPPacketConfig ¶
type UDPPacketConfig struct {
SrcMAC net.HardwareAddr
DstMAC net.HardwareAddr
SrcIP net.IP
DstIP net.IP
SrcPort uint16
DstPort uint16
Payload []byte
TTL uint8
}
UDPPacketConfig holds configuration for building UDP packets.