Help us shape the future of Go! Take the 2026 Go Developer Survey

detection

package
v7.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeTopologySimilarity

func ComputeTopologySimilarity(topo *topology.FunctionTopology, sig Signature) float64

func ExtractStringPatterns

func ExtractStringPatterns(literals []string) []string

func GenerateTopologyHash

func GenerateTopologyHash(topo *topology.FunctionTopology) string

func HasReconnectLogic

func HasReconnectLogic(topo *topology.FunctionTopology) bool

func MatchCalls

func MatchCalls(topo *topology.FunctionTopology, required []string) (score float64, matched, missing []string)

func MatchStrings

func MatchStrings(topo *topology.FunctionTopology, patterns []string) (score float64, matched []string)

Types

type ControlFlowHints

type ControlFlowHints struct {
	HasInfiniteLoop   bool `json:"has_infinite_loop,omitempty"`
	HasReconnectLogic bool `json:"has_reconnect_logic,omitempty"`
}

ControlFlowHints captures control flow patterns.

type IdentifyingFeatures

type IdentifyingFeatures struct {
	RequiredCalls  []string          `json:"required_calls,omitempty"`
	OptionalCalls  []string          `json:"optional_calls,omitempty"`
	StringPatterns []string          `json:"string_patterns,omitempty"`
	ControlFlow    *ControlFlowHints `json:"control_flow,omitempty"`
}

IdentifyingFeatures captures behavioral markers for detection.

type MatchDetails

type MatchDetails struct {
	TopologyMatch      bool     `json:"topology_match"`
	EntropyMatch       bool     `json:"entropy_match"`
	CallsMatched       []string `json:"calls_matched"`
	CallsMissing       []string `json:"calls_missing"`
	StringsMatched     []string `json:"strings_matched"`
	TopologySimilarity float64  `json:"topology_similarity"`
	EntropyDistance    float64  `json:"entropy_distance"`

	// Obfuscation evidence carried into the alert for analyst visibility.
	ObfuscationScore   float64  `json:"obfuscation_score,omitempty"`
	ObfuscationClass   string   `json:"obfuscation_class,omitempty"`
	ObfuscationSignals []string `json:"obfuscation_signals,omitempty"`
}

MatchDetails provides granular information about the match.

type Matcher

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

Matcher checks one function topology against signatures, computing its topology hash once rather than for every signature. The topology must not change while the Matcher is in use: the hash would no longer describe it.

func NewMatcher

func NewMatcher(topo *topology.FunctionTopology, funcName string) Matcher

NewMatcher returns a Matcher for topo, reporting matches as funcName.

func (Matcher) Hash

func (m Matcher) Hash() string

Hash is GenerateTopologyHash of the matcher's topology.

func (Matcher) Match

func (m Matcher) Match(sig Signature, entropyTolerance float64) ScanResult

Match is MatchSignature for the matcher's topology.

type ScanResult

type ScanResult struct {
	SignatureID     string       `json:"signature_id"`
	SignatureName   string       `json:"signature_name"`
	Severity        string       `json:"severity"`
	MatchedFunction string       `json:"matched_function"`
	Confidence      float64      `json:"confidence"` // 0.0 to 1.0
	MatchDetails    MatchDetails `json:"match_details"`
}

ScanResult represents a match between analyzed code and a signature.

func MatchSignature

func MatchSignature(topo *topology.FunctionTopology, funcName string, sig Signature, entropyTolerance float64) ScanResult

MatchSignature checks a function topology against a signature. To check one topology against many signatures, use a Matcher.

type Signature

type Signature struct {
	ID                  string              `json:"id"`
	Name                string              `json:"name"`
	Description         string              `json:"description"`
	Severity            string              `json:"severity"`
	Category            string              `json:"category"`
	TopologyHash        string              `json:"topology_hash"`
	FuzzyHash           string              `json:"fuzzy_hash,omitempty"`
	EntropyScore        float64             `json:"entropy_score"`
	EntropyTolerance    float64             `json:"entropy_tolerance"`
	NodeCount           int                 `json:"node_count"`
	LoopDepth           int                 `json:"loop_depth"` // loop count (FunctionTopology.LoopCount), not nesting depth; gob and JSON databases key the field by this name
	IdentifyingFeatures IdentifyingFeatures `json:"identifying_features"`
	Metadata            SignatureMetadata   `json:"metadata"`

	// ObfuscationScore is the indexed function's aggregate obfuscation score
	// (0..1) at signature-creation time, for triage and threshold tuning.
	ObfuscationScore float64 `json:"obfuscation_score,omitempty"`
}

Signature represents a single malware signature entry.

func IndexFunction

func IndexFunction(topo *topology.FunctionTopology, name, description, severity, category string) Signature

func (Signature) Clone

func (s Signature) Clone() Signature

Clone returns a copy of s that shares no slice or pointer with it.

type SignatureDatabase

type SignatureDatabase struct {
	Version     string      `json:"version"`
	Description string      `json:"description"`
	Signatures  []Signature `json:"signatures"`
}

SignatureDatabase represents the malware signature database.

type SignatureMetadata

type SignatureMetadata struct {
	Author     string   `json:"author"`
	Created    string   `json:"created"`
	References []string `json:"references,omitempty"`
}

SignatureMetadata contains provenance information.

Jump to

Keyboard shortcuts

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