Recipes
Short, real workflows that chain the mlab binaries: from postmortem findings to CVE details, k3sec SBOMs to a vulnerability gate, a nightly domain scan, offline triage of a memory dump, and more.
Each recipe uses only the commands and fields documented in the tool pages. They assume jq is installed. Exit codes are listed in In CI pipelines.
postmortem to CVE details
Who exploits this CVE
postmortem SBOM into mlab
Cluster SBOMs, one gate
Fail on loaded KEV
Domain scan + jq
Nightly domain scan
Offline dump triage
Symbols for air-gapped hosts
Model drift check
postmortem findings to CVE details
postmortem's vulnerability findings carry the advisory id. Take them from the SARIF report (rule postmortem.known-vulnerability, the id in properties.advisory), keep the CVE ids, and look each one up on vuln.mlab.sh for its CVSS, EPSS and CISA KEV status. mlab cve needs no key.
postmortem tree . --vulns --sarif -o pm.sarif
jq -r '.runs[].results[]
| select(.ruleId == "postmortem.known-vulnerability")
| .properties.advisory' pm.sarif \
| grep '^CVE-' | sort -u \
| while read -r id; do
mlab cve detail "$id" --json \
| jq -r '[.id, .cvss_score, .epss_score, .in_kev] | @tsv'
doneThe output has one tab-separated line per CVE: id, CVSS score, EPSS probability, true when the CVE is in the KEV catalogue. Advisories without a CVE alias (GHSA-only, RUSTSEC-only) are left out by the grep. Sort on the EPSS column to patch in order of likely exploitation.
Which actors exploit a CVE
For the CVEs from the recipe above that are in KEV, ask actors.mlab.sh who is documented exploiting them (no key needed):
mlab actor by-cve CVE-2024-3094
mlab actor by-cve CVE-2024-3094 --json > actors.jsonA postmortem SBOM into mlab sbom scan
postmortem resolves the dependency graph offline and exports it as a CycloneDX 1.5 SBOM. mlab sbom scan reads CycloneDX and gates on it. That way you scan one artifact that covers every ecosystem in the repository, instead of each lockfile:
postmortem sbom . -o sbom.json
mlab sbom scan sbom.json --fail-on highExit 7 means a finding reached high. An incomplete scan exits non-zero with the reason rather than 0.
k3sec SBOMs through one vulnerability gate
On a node, k3sec inventory --sbom <dir> writes one CycloneDX SBOM per running image. Scan them all in one mlab sbom scan: --fail-on is judged once, across every file.
sudo NODE_NAME=$(hostname) k3sec inventory --sbom ./sboms --kubeconfig /etc/rancher/k3s/k3s.yaml
mlab sbom scan ./sboms/*.json --fail-on critical -o csv > node-vulns.csv-o csv writes a single table for every file, with the same columns as the web scan page's export. For loaded-code reachability, use k3sec vulns instead (next recipe). The SBOM only lists packages.
Fail when a known-exploited vulnerability is loaded
k3sec vulns has no gate of its own. Its JSON summary counts known-exploited vulnerabilities in code that is mapped in memory, and you can gate on that:
sudo k3sec vulns -o json > vulns.json
kev=$(jq '.summary.kev_loaded' vulns.json)
if [ "$kev" -gt 0 ]; then
jq -r '.images[] | .image as $i | .findings[]
| select(.kev == true and .reachability == "loaded")
| "\($i)\t\(.id)\t\(.package) \(.version)"' vulns.json
exit 1
fiAlso check .images[].unscanned_packages and .images[].error. A package the API did not answer for was not checked, so it is not clean.
jq -e '[.images[] | select(.error != null or .unscanned_packages > 0)] | length == 0' vulns.jsonjq -e exits 1 when the expression is false, so this line fails the job when coverage is incomplete.
Domain scan findings with jq
mlab scan domain launches a scan, follows it, and with --json prints the v2 report (schema: "domain-report/2") exactly as the API returns it. It needs an API key (MLAB_API_KEY).
mlab scan domain example.com --json > report.json
jq '{status, score: .score.value, grade: .score.grade}' report.json
jq -r '.findings[] | select(.severity == "critical" or .severity == "high")
| "\(.severity)\t\(.section)\t\(.title)"' report.jsonThe command gives up following after --max-wait seconds (default 900). A report whose status is failed exits 1. partial and in_progress exit 0 with a warning, so check .status before you trust the findings.
Nightly domain scan from cron
An example wrapper. Each scan domain spends quota: check what is left with mlab limits domain --raw.
#!/bin/sh
# /usr/local/bin/mlab-nightly: scan each domain, keep dated reports.
# Reads MLAB_API_KEY from the environment.
set -u
out=/var/lib/mlab-reports/$(date +%F)
mkdir -p "$out"
for d in example.com example.org; do
mlab --quiet scan domain "$d" --json > "$out/$d.json"
rc=$?
case $rc in
0) ;;
3) echo "$d: out of quota" >&2; break ;;
5) echo "$d: maintenance, retry later" >&2 ;;
*) echo "$d: scan failed (exit $rc)" >&2 ;;
esac
done# /etc/cron.d/mlab-nightly
MLAB_API_KEY=<key>
15 2 * * * reports /usr/local/bin/mlab-nightly--quiet silences progress output. Errors still go to stderr, so cron mails them. To compare two nights, diff the findings titles: jq -r '.findings[].title' a.json b.json. Keep the cron file readable by root only (chmod 600), because it holds the key.
Offline triage of a memory dump
engram works without mlab-agent or mlab.sh. On an analysis box:
# 1. Index the dump (paging files next to it as dump.mem.pagefile.sys are read too)
engram-tool analyze dump.mem -o index.json
# 2. What looks injected or hidden
jq -r '.findings[] | "\(.kind)\tpid \(.pid)\t\(.detail)"' index.json
# 3. Persistence from the registry hives in memory
jq -r '.registry.autoruns[] | "\(.kind)\t\(.key)\\\(.value)\t\(.data)"' index.json
# 4. Remote endpoints, with their owning process
jq -r '.network[] | select(.remote_addr != null and .remote_port != 0)
| "\(.remote_addr)\t\(.remote_port)\t\(.owner) (\(.pid))\t\(.state)"' index.json
# 5. YARA over the processes the findings point at
pids=$(jq -r '[.findings[].pid] | unique | map("--pid \(.)") | join(" ")' index.json)
engram-tool yara dump.mem --index index.json --rules triage.yar $pids > yara.json
jq '.matches[] | {pid, rule, va}' yara.json
# 6. Reputation of the remote addresses (mlab.sh API key)
jq -r '.network[].remote_addr // empty' index.json | sort -u \
| grep -vE '^(0\.0\.0\.0|::|127\.)' \
| while read -r ip; do mlab scan ip "$ip" --json > "ip-$ip.json"; doneStep 6 is the only one that leaves the box: it sends each IP address to mlab.sh, and each lookup counts against your ip quota (mlab limits ip). Treat a private_executable finding as triage material, not a verdict: JIT engines (.NET, JavaScript, Defender) produce it legitimately. Read a key the index points at with engram-tool reg:
engram-tool reg dump.mem --index index.json --hive SOFTWARE \
--key 'Microsoft\Windows\CurrentVersion\Run'Symbols for an air-gapped host
engram needs the kernel's PDB, which it downloads from Microsoft's symbol server. For a host that cannot reach it, build a pack on a connected machine from the dumps (or their indexes), then import it:
# Connected machine
engram-tool symbols pack index.json other-dump.mem -o pack.zip
# Air-gapped host, offline CLI
engram-tool symbols import pack.zip --into ./symbols
engram-tool analyze dump.mem -o index.json --symbols-dir ./symbols --offline
# Air-gapped host running engram under mlab-agent
sudo -u mlab-agent engram-tool symbols import pack.zip --into /etc/mlab-agent/tools/engram/symbolsFor the agent, also set symbols_offline = true in [tools.engram.settings] so the tool never tries the network.
Model drift against a known-good baseline
assay compare diffs a model's weights against a reference of the same architecture. Identical models stay silent, a uniform fine-tune shows broad, even drift, and a localized tamper shows one concentrated spike.
set -o pipefail
assay compare ./model-candidate/ ./model-known-good/ --json --fail-on high \
| tee drift.jsonExit 1 means a finding reached high. --force allows comparing across architectures, but the output is then unreliable. For a cheaper check on every build, pin the hashes from a known-good assay scan --json (hashes.manifest and hashes.file) and compare them: a changed manifest means the weights changed. A changed file with the same manifest means the bytes around the weights changed.