protobuf

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: BSD-3-Clause, GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Decoder = &decoder.StreamDecoder{
	Type:        types.Type_NC_Protobuf,
	Name:        "Protobuf",
	Description: "Generic Protocol Buffer wire format decoder for unknown protobuf traffic",
	PostInit: func(sd *decoder.StreamDecoder) error {
		var err error
		pbLog, _, err = logging.InitZapLogger(
			decoderconfig.Instance.Out,
			"protobuf",
			decoderconfig.Instance.Debug,
		)
		return err
	},
	CanDecode: func(client, server []byte) bool {
		return IsProtobufData(client) || IsProtobufData(server)
	},
	DeInit: func(sd *decoder.StreamDecoder) error {
		return pbLog.Sync()
	},
	Factory: &protobufReader{},
	Typ:     core.TCP,
}

Decoder for generic Protocol Buffer wire format detection and analysis.

Functions

func CalculateEntropy

func CalculateEntropy(data []byte) float64

CalculateEntropy computes Shannon entropy of the data in bits.

func DecodeMessages

func DecodeMessages(data []byte) ([][]Field, error)

DecodeMessages attempts to decode one or more protobuf messages from raw bytes.

func DetectMessageType

func DetectMessageType(fields []Field) string

DetectMessageType classifies a decoded message based on field patterns.

func DetectServiceName

func DetectServiceName(srcPort, dstPort int32) string

DetectServiceName guesses the service type from port numbers.

func IsPrintable

func IsPrintable(data []byte) bool

IsPrintable returns true if all bytes are printable ASCII.

func IsProtobufData

func IsProtobufData(data []byte) bool

IsProtobufData uses heuristics to detect if data might be protobuf encoded. Checks for valid wire type distribution, varint continuation patterns, and sufficient entropy to distinguish from text protocols.

func PopulateFields

func PopulateFields(fields []Field, out map[string]string, order *[]string)

PopulateFields converts ordered decoded fields into the audit record's Fields map (keyed as "type_fieldnum") and FieldOrder slice (preserving wire order).

func ReadVarint

func ReadVarint(buf *bytes.Reader) (uint64, error)

ReadVarint reads a varint-encoded uint64 from the reader.

Types

type Field

type Field struct {
	Number uint64 // protobuf field number
	Type   string // "varint", "fixed64", "string", "bytes", "nested", "fixed32"
	Value  string // string representation of the value
}

Field represents a single decoded protobuf field, preserving wire order.

func ParseMessage

func ParseMessage(buf *bytes.Reader) ([]Field, error)

ParseMessage parses a single protobuf message from a reader. Returns fields in wire order.

Jump to

Keyboard shortcuts

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