dump

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DirClientToServer byte = 0x00
	DirServerToClient byte = 0x01
)

Packet direction constants.

View Source
const (
	ProtocolOracle     = "oracle"
	ProtocolPostgreSQL = "postgresql"
	ProtocolMySQL      = "mysql"
	ProtocolMongo      = "mongodb"
)

Protocol identifiers.

View Source
const FileExt = ".pcapng"

FileExt is the extension used for session capture files. Captures are plain pcapng, readable by tcpdump/Wireshark/tshark without any dbbat tooling.

Variables

View Source
var ErrMissingMetadata = errors.New("capture has no dbbat session metadata")

ErrMissingMetadata is returned when a capture carries no dbbat session metadata in its Section Header Block comment.

Functions

func Anonymise

func Anonymise(inputPath, outputPath string, rewriteAddresses bool) error

Anonymise reads a capture and writes an anonymised copy.

Packet payloads and their relative timing are preserved verbatim. The session metadata carried in the pcapng Section Header Block comment is reduced to the session ID and the protocol: the connection object (database, user, service name, upstream address…) is dropped, and the capture is rebased onto the Unix epoch so the wall-clock time of the session leaks nothing.

When rewriteAddresses is true — the default for the CLI — the synthesized IPv4 addresses and TCP ports are re-generated from the fake endpoints too, since the capture's server-side addressing normally encodes the real upstream host and port. Pass false to keep the original addressing.

func CleanupOldFiles

func CleanupOldFiles(dir string, retention time.Duration) (int, error)

CleanupOldFiles deletes .pcapng capture files older than the retention period. It also reaps leftover legacyFileExt files from before the pcapng switch, since they are otherwise unreadable and invisible to this sweep. Returns the number of files deleted.

Types

type Header struct {
	SessionID  string         `json:"session_id"`
	Protocol   string         `json:"protocol"`
	StartTime  time.Time      `json:"start_time"`
	Connection map[string]any `json:"connection"`
}

Header holds the JSON-serializable session metadata. It is stored as a JSON blob in the pcapng Section Header Block comment (opt_comment).

type Packet

type Packet struct {
	RelativeNs int64  // Nanoseconds since session start
	Direction  byte   // DirClientToServer or DirServerToClient
	Data       []byte // Raw protocol bytes (TCP payload, synthesized headers stripped)
}

Packet represents a single captured application-layer payload.

type Reader

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

Reader reads application payloads back out of a pcapng capture, undoing the synthesized Ethernet/IPv4/TCP wrapping applied by Writer.

func OpenReader

func OpenReader(path string) (*Reader, error)

OpenReader opens a capture file and parses the session metadata carried in the pcapng Section Header Block comment.

func (*Reader) Close

func (r *Reader) Close() error

Close closes the underlying file.

func (*Reader) Header

func (r *Reader) Header() Header

Header returns the session metadata.

func (*Reader) ReadPacket

func (r *Reader) ReadPacket() (*Packet, error)

ReadPacket returns the next application payload. Frames without a TCP payload are skipped. Returns io.EOF at the end of the capture.

type TapConn

type TapConn struct {
	net.Conn
	// contains filtered or unexported fields
}

TapConn wraps a net.Conn and captures all read/written bytes to a Writer. Reads are tagged with one direction, writes with the other.

func NewTapConn

func NewTapConn(conn net.Conn, w *Writer, readDir, writeDir byte) *TapConn

NewTapConn creates a connection wrapper that captures traffic to a dump Writer.

func (*TapConn) Read

func (t *TapConn) Read(b []byte) (int, error)

Read reads from the underlying connection and records the data.

func (*TapConn) Write

func (t *TapConn) Write(b []byte) (int, error)

Write writes to the underlying connection and records the data.

type Writer

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

Writer writes a session capture as a pcapng file. Application payloads are wrapped in synthesized Ethernet/IPv4/TCP headers (see synth.go) and the session metadata is stored as a JSON blob in the Section Header Block comment.

func NewWriter

func NewWriter(path string, header Header, maxSize int64) (*Writer, error)

NewWriter creates a new capture file and writes the pcapng section header (carrying the session metadata) and interface description.

func (*Writer) Close

func (w *Writer) Close() error

Close flushes any buffered block and closes the file.

func (*Writer) WritePacket

func (w *Writer) WritePacket(direction byte, data []byte) error

WritePacket appends a single application payload to the capture. Thread-safe. Silently skips the packet if maxSize would be exceeded.

Jump to

Keyboard shortcuts

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