mbazaar

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package mbazaar adds an abuse.ch MalwareBazaar attachment-hash lookup to yarad: the SHA256 of each scanned buffer (a MIME attachment, as the rspamd plugin POSTs it) is checked against a locally-cached set of SHA256 hashes of known malware samples. An exact hit is a direct known-bad verdict, independent of the YARA rules.

Design mirrors the URLhaus checker (the same fail-open feed-cache infra):

  • The full MalwareBazaar CSV dump is downloaded ONCE per refresh interval (daily by default) into an in-memory set of raw 32-byte digests; lookups are pure local map hits, never a per-message remote API call.
  • A failed refresh keeps the previous set (fail-static) and is counted.
  • The dump is a ZIP (one CSV inside); a plain-CSV feed (the "recent" export or a custom URL override) is also accepted — the body is magic-sniffed.
  • Digests are held as raw [32]byte map keys (not 64-char hex) to keep the full set lean (~40 MB for ~1M samples) on a memory-limited container.

Requires an abuse.ch Auth-Key (free, https://auth.abuse.ch/ — the SAME key as URLhaus). With no key the checker is disabled (New returns nil).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Checker

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

Checker holds the cached hash set and serves lookups. The zero value is not usable; use New.

func New

func New(key string, refresh time.Duration, feedURL, cacheDir string, logf func(string, ...any)) *Checker

New builds a Checker and starts its background refresher. It returns nil when key is empty (feature disabled), so callers can guard on `c != nil`. refresh is clamped to the fair-use floor; feedURL falls back to the full dump. When cacheDir is non-empty the feed snapshot is persisted there and loaded on startup, so a restart serves from the last-good feed instead of an empty set.

func (*Checker) Check

func (c *Checker) Check(data []byte) []Hit

Check hashes data and reports a Hit when its SHA256 is a known malware sample. It returns a slice (0 or 1 hit) for symmetry with the URLhaus checker, and is safe for concurrent use.

func (*Checker) CheckDigest

func (c *Checker) CheckDigest(sum [32]byte) []Hit

CheckDigest is Check for a caller that has already computed the SHA256 of the buffer, so the (up to 8 MiB) body is not hashed a second time per scan.

func (*Checker) Close

func (c *Checker) Close()

Close stops the background refresher. Safe to call more than once and on a nil *Checker (the disabled-feature case), so shutdown code can call it unconditionally.

func (*Checker) Metrics

func (c *Checker) Metrics() Metrics

Metrics returns a snapshot for /metrics.

type Hit

type Hit struct {
	SHA256 string // hex digest of the matched buffer
}

Hit is one scanned buffer whose SHA256 matched a known malware sample.

func (Hit) Rule

func (h Hit) Rule() string

Rule returns the synthetic rule name for a hit, so the scanner can surface it as a match alongside YARA rules and the rspamd plugin can route it.

type Metrics

type Metrics struct {
	Enabled         bool
	FeedHashes      int64
	LastRefreshUnix int64
	RefreshFailures uint64
	Lookups         uint64 // buffers hashed and checked
	Hits            uint64 // buffers whose hash matched
}

Metrics is a snapshot for /metrics.

Jump to

Keyboard shortcuts

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