Documentation
¶
Index ¶
- Constants
- Variables
- func FragmentTime(f Fragment) int64
- func FromServer(f Fragment) bool
- type ConversationInfo
- type DataFragment
- type DataFragments
- func (d DataFragments) Bytes() []byte
- func (d DataFragments) ContiguousBytes() []byte
- func (d DataFragments) First() []byte
- func (d DataFragments) FirstNonEmpty() []byte
- func (d DataFragments) Len() int
- func (d DataFragments) Less(i, j int) bool
- func (d DataFragments) Size() int
- func (d DataFragments) SourceIP() string
- func (d DataFragments) Swap(i, j int)
- type DecoderAPI
- type Fragment
- type FragmentIndex
- type IncrementalDecoder
- type IncrementalFactory
- type IncrementalReport
- type IncrementalReporter
- type IncrementalTailObserver
- type StateBudget
- type StateBudgetHealth
- type StreamCompletion
- type StreamData
- func (s *StreamData) CaptureInfo() gopacket.CaptureInfo
- func (s *StreamData) Context() reassembly.AssemblerContext
- func (s *StreamData) Direction() reassembly.TCPFlowDirection
- func (s *StreamData) HasGap(started bool) bool
- func (s *StreamData) Network() gopacket.Flow
- func (s *StreamData) Raw() []byte
- func (s *StreamData) SetDirection(d reassembly.TCPFlowDirection)
- func (s *StreamData) Transport() gopacket.Flow
- type StreamDecoderAPI
- type StreamDecoderFactory
- type StreamDecoderInterface
- type TransportProtocol
Constants ¶
const ( // SpecificityHeuristic is a statistical judgement or a single nibble: no // fixed bytes that the protocol guarantees. SpecificityHeuristic = 10 // SpecificityWeak is one to three fixed bytes, a range check, or an // unanchored substring. SpecificityWeak = 20 // SpecificityStructural is a field enum plus a length that has to agree // with the data present. SpecificityStructural = 30 // SpecificityMagic is four or more fixed bytes, or a literal long enough // that it cannot collide. SpecificityMagic = 40 // SpecificityValidated is a checksum, or a complete parse of the message. SpecificityValidated = 50 )
How much evidence a decoder required before claiming a stream.
The port-independent scan used to take the first decoder that said yes, walking ports in ascending order, so a one-byte check on port 21 outranked a checksum on port 20000. Measured over one sample per decoder, that sent 5 of 29 protocols to the wrong decoder off their own port -- including SMTP, whose signature is strictly stronger than the FTP one that took it and which lost only because 25 > 21.
These values rank the evidence instead. They are not a confidence that the guess is right; they say how much had to match before the guess was made.
Variables ¶
var ErrIncrementalLimit = errors.New("incremental parser retained-state limit")
var ErrStreamStateBudget = errors.New("TCP stream state budget exceeded")
Functions ¶
func FragmentTime ¶
FragmentTime returns the capture time of the packet that carried a fragment, in Unix nanoseconds.
Readers used to stamp every record with ConversationInfo.FirstClientPacket. That is the time the conversation opened, not the time anything in it happened: a connection held open for days collapses to one instant, and no question about ordering, rate or a maintenance window survives it.
The assembler context is preferred because it carries the capture time of the packet that closed a hole, rather than of the page the fragment sits in.
func FromServer ¶
FromServer reports whether a fragment traveled from the server.
Types ¶
type ConversationInfo ¶
type ConversationInfo struct {
Transport TransportProtocol
Data DataFragments
// TCP directions in reassembly order; capture timestamps can run backwards.
ClientData DataFragments
ServerData DataFragments
Ident string
// Immutable packetview scope shared by every packet in this conversation.
NetworkScope string
FirstClientPacket time.Time
FirstServerPacket time.Time
ClientIP string
ServerIP string
ClientPort int32
ServerPort int32
ClientMAC string
ServerMAC string
// True only when SYN, SYN-ACK and the acknowledging client ACK were observed.
TCPHandshakeComplete bool
// syn, syn-ack, service-port, or first-observed (roles unknown).
TCPRoleSource string
// CommunityID is the Corelight Community ID v1 for this stream.
// This provides a standardized flow identifier compatible with
// Zeek, Suricata, and other network monitoring tools.
// See: https://github.com/corelight/community-id-spec
CommunityID string
}
ConversationInfo is wrapper structure for traffic sent over a Transport protocol to allow Transport agnostic decoding of data streams.
func (*ConversationInfo) Endpoints ¶
func (c *ConversationInfo) Endpoints(f Fragment) (srcIP, dstIP string, srcPort, dstPort int32)
Endpoints returns the addresses for the direction a fragment traveled in.
Readers used to assign ClientIP to every record unconditionally, which makes a response indistinguishable from the command that provoked it: both carry the client as their source. A reply belongs to the server.
func (*ConversationInfo) EndpointsAt ¶
func (c *ConversationInfo) EndpointsAt(i *FragmentIndex, offset int) (srcIP, dstIP string, srcPort, dstPort int32)
Endpoints returns the addresses for the direction at offset.
type DataFragment ¶
type DataFragment = dataFragment
DataFragment carries directional bytes and their original capture metadata.
type DataFragments ¶
type DataFragments []dataFragment
DataFragments implements sort.Interface to sort data fragments based on their timestamps.
func MergeByTimestamp ¶
func MergeByTimestamp(a, b DataFragments) DataFragments
MergeByTimestamp interleaves two per-direction fragment slices by capture timestamp into a newly allocated slice.
The merge is stable: a fragment never moves relative to the other fragments of the same input. Both inputs are in stream (byte) order by construction, but their timestamps are not monotonic, because reassembly delivers the packet that closed a hole together with the earlier-captured packets it had queued. Sorting the concatenation instead reorders bytes within a direction and corrupts every consumer that reads the result as a byte stream.
Fragments with equal timestamps - such as the pages a single large segment is split into - keep their input order, with a taking precedence over b.
func (DataFragments) Bytes ¶
func (d DataFragments) Bytes() []byte
Bytes returns all fragment data concatenated into a single byte slice.
func (DataFragments) ContiguousBytes ¶ added in v0.16.0
func (d DataFragments) ContiguousBytes() []byte
ContiguousBytes returns the first observed byte run without joining across loss. A leading loss marker is permitted; it cannot bridge two observed byte ranges.
func (DataFragments) First ¶
func (d DataFragments) First() []byte
First returns the first fragment.
func (DataFragments) FirstNonEmpty ¶
func (d DataFragments) FirstNonEmpty() []byte
FirstNonEmpty returns the first fragment that carries bytes.
Reassembly prepends a zero-length marker when a direction begins midstream with no observed SYN, so First returns no bytes for every such conversation. Protocol detection run on that marker rejects the real protocol and then admits whichever decoder accepts an empty stream.
func (DataFragments) Less ¶
func (d DataFragments) Less(i, j int) bool
Less will check if the value at index i is less than the one at index j.
func (DataFragments) Size ¶
func (d DataFragments) Size() int
Size returns the fragments total data size.
func (DataFragments) SourceIP ¶
func (d DataFragments) SourceIP() string
SourceIP returns the source IP address from the first fragment's network layer. Returns empty string if no fragments are available.
type DecoderAPI ¶
type DecoderAPI interface {
// PostInitFunc is called after the decoder has been initialized
PostInitFunc() error
// DeInitFunc is called prior to teardown
DeInitFunc() error
// GetName returns the name of the decoder
GetName() string
// SetWriter sets the netcap writer to use for the decoder
SetWriter(netio.AuditRecordWriter)
// GetWriter returns the current writer
GetWriter() netio.AuditRecordWriter
// GetType returns the netcap type of the decoder
GetType() types.Type
// GetDescription returns the description of the decoder
GetDescription() string
// GetChan returns a channel to receive serialized audit records from the decoder
GetChan() <-chan []byte
// Destroy initiates teardown
Destroy() (string, int64)
// NumRecords returns the number of processed audit records
NumRecords() int64
// FlushCurrentState writes the current state of accumulating records to disk
// without clearing the in-memory state. This is used during live capture
// to periodically make data visible while continuing to track state.
// Returns the number of records flushed.
FlushCurrentState() int64
}
DecoderAPI describes functionality of a decoder.
type Fragment ¶
type Fragment interface {
Raw() []byte
Context() reassembly.AssemblerContext
Direction() reassembly.TCPFlowDirection
}
Fragment is the read-only view of a stream fragment that a reader needs to place a record in time and direction.
It is the exported subset of the unexported fragment interface, so readers can take a DataFragments element without restating the whole thing.
type FragmentIndex ¶
type FragmentIndex struct {
// contains filtered or unexported fields
}
FragmentIndex maps byte offsets in a concatenated buffer back to the fragment each byte arrived in.
Readers that need the whole direction in one slice -- anything with messages that span fragments -- lose the per-fragment metadata by concatenating. The index keeps it, so a message can still be placed in time and direction by the offset of its first byte.
func Flatten ¶
func Flatten(fragments DataFragments) ([]byte, *FragmentIndex)
Flatten concatenates fragments and returns an index over the result.
func (*FragmentIndex) At ¶
func (i *FragmentIndex) At(offset int) (timestamp int64, fromServer bool)
At returns the capture time and direction of the fragment covering offset.
An offset past the end resolves to the last fragment rather than to zero: a message whose framing ran off the end still happened, and at the time of the bytes that were seen.
type IncrementalDecoder ¶ added in v0.16.0
type IncrementalDecoder interface {
Push(*StreamData) error
Finish(StreamCompletion) error
Abort()
}
type IncrementalFactory ¶ added in v0.16.0
type IncrementalFactory interface {
NewIncremental(*ConversationInfo, *StateBudget) IncrementalDecoder
}
IncrementalFactory is opt-in. Push owns no input after returning: retained bytes/metadata must be copied under StateBudget. Finish emits the final tail once; Abort releases ownership without interpreting omitted bytes as EOF.
type IncrementalReport ¶ added in v0.16.0
type IncrementalReporter ¶ added in v0.16.0
type IncrementalReporter interface{ IncrementalReport() IncrementalReport }
type IncrementalTailObserver ¶ added in v0.16.0
type IncrementalTailObserver interface{ SetTailObserver(func(*ConversationInfo)) }
The tail is borrowed only during the callback, while its parser reservations remain held. Existing upgrade decoders can inspect deferred bytes here.
type StateBudget ¶ added in v0.16.0
type StateBudget struct {
// contains filtered or unexported fields
}
func NewStateBudget ¶ added in v0.16.0
func NewStateBudget(limit int64, cancel func()) (*StateBudget, error)
func (*StateBudget) Error ¶ added in v0.16.0
func (b *StateBudget) Error() error
func (*StateBudget) Health ¶ added in v0.16.0
func (b *StateBudget) Health() StateBudgetHealth
func (*StateBudget) Release ¶ added in v0.16.0
func (b *StateBudget) Release(n int64)
func (*StateBudget) Reserve ¶ added in v0.16.0
func (b *StateBudget) Reserve(n int64) error
type StateBudgetHealth ¶ added in v0.16.0
type StreamCompletion ¶ added in v0.16.0
type StreamData ¶
type StreamData struct {
// raw binary data
RawData []byte
// tcp specific fields
AssemblerContext reassembly.AssemblerContext
Dir reassembly.TCPFlowDirection
SkippedBytes int // Gap before this fragment; -1 means unknown initial loss.
DiscardedBytes int64 // Observed payload omitted locally, not a network sequence gap.
DiscardReason string
// after-fin / after-rst: observed on the wire, endpoint delivery unconfirmed.
TCPObservation string
// capture metadata of the packet this fragment was taken from, set for TCP and UDP
CaptureInformation gopacket.CaptureInfo
// udp specific fields
Net gopacket.Flow
Trans gopacket.Flow
}
StreamData is a payload fragment of data we received from a streamReader its contains the raw bytes as well an assembler context with timestamp information.
func (*StreamData) CaptureInfo ¶
func (s *StreamData) CaptureInfo() gopacket.CaptureInfo
CaptureInfo returns the capture information from gopacket
func (*StreamData) Context ¶
func (s *StreamData) Context() reassembly.AssemblerContext
Context returns the assembler context.
func (*StreamData) Direction ¶
func (s *StreamData) Direction() reassembly.TCPFlowDirection
Direction returns the direction of the flow.
func (*StreamData) HasGap ¶ added in v0.16.0
func (s *StreamData) HasGap(started bool) bool
HasGap distinguishes an unknown initial sequence from a hole in observed data. Local budget loss always breaks framing, including before the first byte.
func (*StreamData) Network ¶
func (s *StreamData) Network() gopacket.Flow
Network returns the network layer
func (*StreamData) Raw ¶
func (s *StreamData) Raw() []byte
Raw returns the raw byte slice that makes up the data fragment.
func (*StreamData) SetDirection ¶
func (s *StreamData) SetDirection(d reassembly.TCPFlowDirection)
SetDirection will update the flow direction.
func (*StreamData) Transport ¶
func (s *StreamData) Transport() gopacket.Flow
Transport returns the transport layer
type StreamDecoderAPI ¶
type StreamDecoderAPI interface {
DecoderAPI
// CanDecodeStream determines if this decoder can understand the protocol used
CanDecodeStream(client []byte, server []byte) bool
// MatchSpecificity reports how much evidence this decoder required to
// accept these bytes. Only meaningful when CanDecodeStream returned true.
//
// It takes the data because for several decoders the answer varies with it:
// s7comm validates an S7 payload on a data-transfer PDU and only a COTP
// header otherwise, and ENIP carries CIP on some commands and nothing on
// others. A single number per decoder cannot express that, and those are
// exactly the cases where the wrong decoder wins.
MatchSpecificity(client []byte, server []byte) int
// GetReaderFactory returns a factory for processing streams of the current decoder
GetReaderFactory() StreamDecoderFactory
Transport() TransportProtocol
}
StreamDecoderAPI describes an interface that all stream decoders need to implement this allows to supply a custom structure and maintain state for advanced protocol analysis.
type StreamDecoderFactory ¶
type StreamDecoderFactory interface {
// New StreamDecoderInterface
New(conversation *ConversationInfo) StreamDecoderInterface
}
StreamDecoderFactory produces stream decoder instances.
type StreamDecoderInterface ¶
type StreamDecoderInterface interface {
// Decode parses the stream according to the identified protocol.
Decode()
}
StreamDecoderInterface is the interface for processing a bi-directional network connection.
type TransportProtocol ¶
type TransportProtocol int
TransportProtocol is a layer 4 protocol from the OSI model
const ( // TCP protocol TCP TransportProtocol = iota // UDP protocol UDP // All will invoke decoder for all transport protocols All )