utils

package
v0.16.12 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: BSD-3-Clause, GPL-3.0 Imports: 28 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DeviceEnricher func(ip string, hostnames, deviceTypes, roles []string, os string)

DeviceEnricher is a callback function to enrich a device profile by IP. Set by the collector during initialization to avoid circular imports.

View Source
var Stats struct {
	sync.Mutex

	IPdefrag                int64
	MissedBytes             int64
	Pkt                     int64
	Sz                      int64
	Totalsz                 int64
	RejectFsm               int64
	RejectOpt               int64
	RejectChecksum          int64
	RejectIPv4Checksum      int64
	RejectConnFsm           int64
	Reassembled             int64
	OutOfOrderBytes         int64
	OutOfOrderPackets       int64
	BiggestChunkBytes       int64
	BiggestChunkPackets     int64
	OverlapBytes            int64
	OverlapPackets          int64
	SavedTCPConnections     int64
	SavedUDPConnections     int64
	SavedNetworkConnections int64
	NumSoftware             int64
	NumServices             int64

	Requests  int64
	Responses int64
	Count     int64
	DataBytes int64
	NumConns  int64
	NumFlows  int64

	// HTTP
	NumUnmatchedResp        int64
	NumNilRequests          int64
	NumFoundRequests        int64
	NumRemovedRequests      int64
	NumUnansweredRequests   int64
	NumClientStreamNotFound int64
	NumRequests             int64
	NumResponses            int64

	// keep this one after all 64bit types to fix alignment problems on ARM
	NumErrors uint
}

Stats contains statistics about the stream reassembly.

Functions

func CalcCommunityIDSCTP

func CalcCommunityIDSCTP(srcIP, dstIP string, srcPort, dstPort uint16) string

CalcCommunityIDSCTP calculates a Community ID v1 for an SCTP stream. Returns an empty string if the IP addresses cannot be parsed.

func CalcCommunityIDTCP

func CalcCommunityIDTCP(srcIP, dstIP string, srcPort, dstPort uint16) string

CalcCommunityIDTCP calculates a Community ID v1 for a TCP stream. Returns an empty string if the IP addresses cannot be parsed.

func CalcCommunityIDUDP

func CalcCommunityIDUDP(srcIP, dstIP string, srcPort, dstPort uint16) string

CalcCommunityIDUDP calculates a Community ID v1 for a UDP stream. Returns an empty string if the IP addresses cannot be parsed.

func DecodeConversation

func DecodeConversation(
	ident string,
	data core.DataFragments,
	client func(buf *bufio.Reader) error,
	server func(buf *bufio.Reader) error,
)

DecodeConversation is a Transport layer agnostic util to decode client / server data streams.

func DecodeConversationAt

func DecodeConversationAt(
	ident string,
	data core.DataFragments,
	client func(buf *bufio.Reader, pos *ReadPosition) error,
	server func(buf *bufio.Reader, pos *ReadPosition) error,
)

DecodeConversationAt is DecodeConversation with the read position exposed, so a reader can timestamp each message from the packet that carried it.

func DecodeSourceConversation added in v0.16.11

func DecodeSourceConversation(conversation *core.ConversationInfo, client, server func(*bufio.Reader) error) error

func DecodeSourceConversationAt added in v0.16.11

func DecodeSourceConversationAt(conversation *core.ConversationInfo, client, server func(*bufio.Reader, *ReadPosition) error) (resultErr error)

Each contiguous directional run is pulled on demand; parser state outlives reads.

func ResetStats

func ResetStats()

ResetStats clears all stream reassembly statistics This should be called when resetting state between processing different files

func SaveConversation

func SaveConversation(proto string, conversation core.DataFragments, ident string, firstPacket time.Time, transport gopacket.Flow, communityID string) error

SaveConversation will save TCP / UDP conversations to disk this also invokes the harvesters on the conversation banner The communityID parameter is the Corelight Community ID v1 for the connection, calculated once at the stream level and passed through to harvesters.

func SaveDatagramConversation added in v0.16.8

func SaveDatagramConversation(source core.FragmentSource, ident string, first time.Time, transport gopacket.Flow, communityID string) error

func SaveNetworkConversation

func SaveNetworkConversation(protocol string, conversation NetworkDataFragments, ident string, firstPacket time.Time) error

SaveNetworkConversation will save network-layer conversations (ICMP, IGMP, GRE, etc.) to disk Protocol should be the network layer protocol name (e.g., "ICMPv4", "ICMPv6", "IGMP", "GRE")

func SaveNetworkSource added in v0.16.9

func SaveNetworkSource(protocol string, source NetworkFragmentSource, ident string, firstPacket time.Time) error

func SaveSourceEvidence added in v0.16.8

func SaveSourceEvidence(out, protocol string, source core.FragmentSource, ident string, first time.Time, communityID string) (string, error)

func SaveStreamEvidence

func SaveStreamEvidence(out, protocol string, conversation core.DataFragments, ident string, first time.Time, communityID string) (string, error)

SaveStreamEvidence preserves payload bytes separately from presentation markup. Each call has its own directory, including when a tuple is reused.

func SaveTCPConversation added in v0.16.11

func SaveTCPConversation(source core.FragmentSource, ident string, first time.Time, transport gopacket.Flow, communityID string) error

func SetLogger

func SetLogger(l *zap.Logger)

SetLogger is an alias for SetReassemblyLogger for backward compatibility

func SetReassemblyLogger

func SetReassemblyLogger(l *zap.Logger)

SetReassemblyLogger configures the logger for this package.

func TransportQualification added in v0.16.0

func TransportQualification(observation string) string

func WalkSourceGapRuns added in v0.16.11

func WalkSourceGapRuns(source core.RangedFragmentSource, consume func(core.RangedFragmentSource, bool, bool) error) error

func WalkSourceTransportRuns added in v0.16.11

func WalkSourceTransportRuns(c *core.ConversationInfo, consume func(*core.ConversationInfo, string) error) error

Range-backed runs retain only the two iterator heads while consumers replay a run.

func WithSourceReader added in v0.16.11

func WithSourceReader(c *core.ConversationInfo, source core.FragmentSource, server bool, bufferSize int, consume func(*bufio.Reader, *ReadPosition) error) error

The caller supplies one directional, loss-bounded range and qualifies its initial loss.

Types

type NetworkDataFragment

type NetworkDataFragment interface {
	Raw() []byte
	CaptureInfo() gopacket.CaptureInfo
	Network() gopacket.Flow
	Direction() reassembly.TCPFlowDirection
}

NetworkDataFragment represents a single network-layer packet fragment This interface allows the network package to pass data without circular imports

type NetworkDataFragments

type NetworkDataFragments []NetworkDataFragment

NetworkDataFragments is a slice of network data fragments

func (NetworkDataFragments) Walk added in v0.16.9

func (n NetworkDataFragments) Walk(yield func(NetworkDataFragment) bool) error

type NetworkFragmentSource added in v0.16.9

type NetworkFragmentSource interface {
	Walk(func(NetworkDataFragment) bool) error
}

type ReadPosition

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

ReadPosition reports where in the capture a line-oriented reader currently is.

Readers driven through a bufio.Reader used to have nothing to timestamp a record with except ConversationInfo.FirstClientPacket, so every FTP command, IMAP response and IRC message in a session carried the time the session opened. A conversation held open for hours collapsed to one instant.

The offset is exact rather than approximate: bytes handed to the buffer, minus what the buffer still holds, minus what bufio has read ahead and not yet returned.

func FragmentReader

func FragmentReader(fragments core.DataFragments, server bool) (*bufio.Reader, *ReadPosition)

FragmentReader reads one contiguous direction while retaining capture offsets.

func (*ReadPosition) FromServer

func (p *ReadPosition) FromServer() bool

FromServer reports whether the current direction is the server's.

func (*ReadPosition) Offset

func (p *ReadPosition) Offset() int

Offset returns how many bytes of the current direction the reader has consumed.

func (*ReadPosition) TCPObservation added in v0.16.0

func (p *ReadPosition) TCPObservation() string

TCPObservation qualifies post-close wire evidence; it never confirms delivery.

func (*ReadPosition) Timestamp

func (p *ReadPosition) Timestamp() int64

Timestamp returns the capture time of the packet carrying the byte the reader is positioned at, in Unix nanoseconds.

type StreamEvidenceFile

type StreamEvidenceFile struct {
	Name   string `json:"name"`
	Length int64  `json:"length,string"`
	SHA256 string `json:"sha256"`
}

type StreamEvidenceManifest

type StreamEvidenceManifest struct {
	Version       int                  `json:"version"`
	Protocol      string               `json:"protocol"`
	ConnectionKey string               `json:"connectionKey"`
	CommunityID   string               `json:"communityId"`
	FirstPacketNs string               `json:"firstPacketNs"`
	Status        string               `json:"status"`
	Client        StreamEvidenceFile   `json:"client"`
	Server        StreamEvidenceFile   `json:"server"`
	Spans         []StreamEvidenceSpan `json:"spans"`
	Limitations   []string             `json:"limitations"`
}

type StreamEvidenceSpan

type StreamEvidenceSpan struct {
	Direction      string `json:"direction"`
	Offset         int64  `json:"offset,string"`
	Length         int    `json:"length"`
	TimestampNs    string `json:"timestampNs"`
	MissingBytes   int    `json:"missingBytes"`
	Datagram       bool   `json:"datagram"`
	DiscardedBytes int64  `json:"discardedBytes,omitempty,string"`
	DiscardReason  string `json:"discardReason,omitempty"`
}

type TransportRun added in v0.16.0

type TransportRun struct {
	Conversation *core.ConversationInfo
	Observation  string
}

TransportRun is a framing domain bounded by transport qualification changes.

func TransportRuns added in v0.16.0

func TransportRuns(c *core.ConversationInfo) []TransportRun

TransportRuns preserves each direction's sequence order while merging capture times. A qualification transition breaks both framing and request pairing.

Jump to

Keyboard shortcuts

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