Skip to content
Documentation

Features

This page is published from the ml repository. Edit on GitHub View source

Each module in synthaea_ml/features/ defines one feature vector: its values, their order and their names (FEATURE_NAMES). Each one is the reference for a Rust twin in the agent's crates/ml, and both sides test against the same golden file. Changing a definition here without changing the Rust side, regenerating the golden and retraining, silently breaks every model trained on the old definition.

ModuleWidthScoresUsed byGolden
cmdline9One command lineT0, T1, site modelsfeatures_golden.jsonl
correlation8One pid's event windowT2, T1capture_correlation_golden.jsonl
t117One process incarnationT1t1_golden.jsonl
lineage6The parent of an execLineage-gain measurement onlylineage_golden.jsonl
rarity2The executed image against the fleet's common settrain_site_rarityrarity_golden.jsonl
behavior9One pid's window, for likelihood-ratio calibrationcalibrate_llrbehavior_golden.jsonl
combined14Correlation + lineageTests onlynone

Python computes in float64 and the agent in float32; the Rust golden tests compare with a relative tolerance of 1e-4.

Command line

extract_features(cmdline) takes the canonical command line (argv tokens each followed by \0 on Linux, the flat string on Windows):

#NameDefinition
0lengthCharacters, NUL separators included
1entropyShannon entropy over characters, in bits
2suspicious_token_countHow many entries of SUSPICIOUS_TOKENS occur as substrings (each counted once)
3token_countNon-empty NUL-separated tokens
4max_token_lengthLength of the longest token
5shell_metachar_countOccurrences of any of |;&$`()<>
6digit_ratioASCII digits 0-9 over length; Unicode digits do not count, as in Rust's is_ascii_digit
7is_suspicious_win_path1.0 if a SUSPICIOUS_WIN_PATHS entry occurs, case-insensitively (\AppData\, \Temp\, \Downloads\, %temp%, ...)
8is_legit_win_path1.0 if a LEGIT_WIN_PATHS entry occurs, case-insensitively (\Windows\System32\, \Program Files\, ...)

The token lists are matched as plain substrings of the whole string, without tokenizing, to stay identical to Rust's str::contains. They are a known weakness, as any static list is: an attacker who reads them can avoid them.

Correlation

extract_features(events, pid, generation=None) takes every flattened event of a correlation window and filters it to one process itself, so the caller passes the window, not the pid's events:

#NameDefinition
0spawn_countexec events
1connect_countconnect events only
2filewrite_countfileopen events with write intent
3unique_daddr_countDistinct destinations over connect and network_flow
4unique_dport_countDistinct destination ports over connect and network_flow
5has_full_chain1.0 if spawn_count, connect_count and filewrite_count are all at least 1
6span_sLast minus first event time, in seconds
7event_countEvents of the process in the window
  • Write intent mirrors the agent's schema::has_write_intent: the 2-bit access mode (flags & O_ACCMODE) is O_WRONLY or O_RDWR, or O_CREAT or O_TRUNC is set (O_RDONLY | O_TRUNC empties the file on Linux, agent#233). The invalid access mode 0o3 is not a write; the kernel refuses it.
  • Incarnations. same_generation mirrors the correlator: two known, different process_generation stamps never mix; a missing stamp on either side cannot disprove identity, so captures without stamps behave as pid-only.
  • Event types. Only the four types flatten_wire_event keeps contribute, so span_s and event_count are computed over the same subset the agent counts.

T1

The T1 vector is the 9 command-line features of an exec record followed by the 8 correlation features carried on the record as correlation_features (features/t1.py). A record without correlation_features scores as an empty window (eight zeros), which keeps the context fixed when a mutation test rewrites only the command line. A context of the wrong length raises ValueError.

There is no lineage block in the shipped T1 vector. Six lineage columns were measured on lab captures with the lineage-gain evaluation: they raised detection of attacks with an unusual parent and lowered it for the large majority whose lineage is ordinary, because an Isolation Forest spends random splits on columns that do not separate (a paired AUC change of about -0.08, worse on every split). The agent judges the parent with rules instead. The lineage extractor stays, parity-tested, so the measurement can be repeated on better data.

Lineage

extract_features(event) reads parent_comm and parent_image_path from an exec record:

#NameDefinition
0has_parent_lineageEither field is present
1parent_comm_is_shellBasename of parent_comm equals a SHELL_COMMS entry, case-insensitively
2parent_comm_is_webserverSame, against WEBSERVER_COMMS (nginx, httpd, w3wp.exe, node, java, ...)
3parent_comm_is_officeSame, against OFFICE_COMMS
4parent_path_is_systemparent_image_path contains a SYSTEM_PATHS entry, case-insensitively
5parent_path_is_suspiciousSame, against SUSPICIOUS_PATHS (/tmp/, /dev/shm/, \AppData\, ...)

Name matches compare the whole basename (cmd.exe matches C:\Windows\System32\cmd.exe, cmd does not); path matches are substrings. features/combined.py concatenates the correlation and lineage vectors (14 values), taking the lineage from the latest exec of the same incarnation; nothing in the trainers uses it.

Rarity

The rarity feature asks whether the executed image is on the fleet's common set: the image hashes executed on at least K hosts of the tenant, published by the control plane as a snapshot. A device can test membership in a snapshot but cannot count hosts, so the model input is derived from the snapshot, never from a host count:

#NameDefinition
0rarity_known1.0 when a snapshot exists, it covers at least min_hosts hosts, and the event carries a valid SHA-256 (64 hex characters, case-insensitive)
1image_in_common_set1.0 when known and the hash is in the common set; 0.0 when known means rare or new on this fleet

Without rarity_known, every binary on a freshly enrolled fleet, whose snapshot is empty, would look rare. When the evidence is withheld both values are 0. For training, the snapshot in force at each event is rebuilt from the corpus (datasets.md). The agent has a Rust extractor pinned to this one, but no agent scorer loads an 11-feature model yet.

Behavior

features/behavior.py mirrors the agent correlator's BehaviorVector, the per-pid vector behind its Bayesian belief. It is not a model input: it is the vector calibrate_llr bins to estimate likelihood ratios (calibration.md).

#NameDefinition
0-2has_exec, has_connect, has_filewrite1.0 if at least one such event (write intent as above)
3time_exec_to_connect_msFirst connect minus first exec, in ms, floored at 0; 0 if either is absent
4time_exec_to_filewrite_msSame for the first write
5is_suspicious_pathThe first exec's image (its first NUL token) contains appdata, \temp\, downloads, desktop or \public\, case-insensitively
6connect_countconnect events
7distinct_dportsDistinct destination ports of connect events
8dest_is_external1.0 if an IPv4 destination is outside 10/8, 172.16/12, 192.168/16 and 127/8

An empty window yields nine zeros.

Sanity samples

features/sanity_samples.py holds a few fixed command lines per platform (benign ones from the baseline, a short malicious base64 -d, and a known false positive on Linux, a container health check with curl). The T0 trainers print their scikit-learn scores after fitting, and verify_onnx scores them through onnxruntime. They are a sniff test and the ONNX oracle input, not a quality gate.

Changing a feature

  1. Change the Python definition and its Rust twin together.
  2. Regenerate the golden with its generator in tests/fixtures/generators/ and open the matching pull request on the agent (testing.md).
  3. Retrain every model that uses the vector: its recorded feature names and bounds no longer describe what the extractor produces.

Never regenerate a golden to make a failing parity test pass; the failure is the drift.