datadog/writing-guarddog-rules
Author, edit, and review GuardDog YARA source-code detection rules (.yar) that follow the capability/threat/risk model. Use when adding a new detection rule, changing an existing rule's patterns or metadata, splitting capabilities from threats, debugging false positives, or writing rule test cases under guarddog/analyzer/sourcecode/.
npx skills add https://github.com/DataDog/guarddog --skill writing-guarddog-rules
GuardDog detects supply-chain malware with a two-layer model. The full reference,
including the philosophy, metadata schema, and worked examples, lives in
WRITING_RULES.md at the repository root (the skill directory is
.claude/skills/writing-guarddog-rules/, so the doc is three levels up). This
skill is the procedural layer: it captures the mental model and the workflow,
and it points to the reference for detail. Read WRITING_RULES.md when you need
the schema specifics, field definitions, or longer examples; do not duplicate it.
(requests.get(, .readFileSync(, subprocess.Popen(). Match calls, not imports.
/etc/passwd, discord.com/api/webhooks,base64.decode + exec together). Not a bare function call.
alone is benign; a threat indicator alone is often a false positive; together they are a risk.
identifies format: {type}.{category}[.{detail}] where type is capability or threat,category is one of network, filesystem, process, runtime, system, metadata.
capability.process.* only pairs withthreat.process.*. General detail matches specific (threat.network + capability.network.outbound),
but conflicting details do not (...outbound + ...inbound).
threat.runtime.* and threat.metadata.* auto-form risks without needing a capability(obfuscation, install hooks, typosquatting, maintainer compromise).
When unsure whether a pattern is a capability or threat: does it show what code *can do* (capability)
or a *suspicious indicator* (threat)? Does it stand alone without a capability (runtime/metadata threat)?
capability vs threat, then category and optional detail.Confirm the matching counterpart exists or will exist so a risk can form.
.yar). Source-code rules are YARA-only and language-agnostic(loaded for every ecosystem). Follow the best practices in WRITING_RULES.md (word boundaries \b,
match method calls not object names, require quote context for bare strings, establish context
with private rules before matching threats). Extract shared building blocks (LOLBAS, hooks) into
.meta files instead of repeating them.
identifies, severity, description. Threat rules also need asingle mitre_tactics. Optional specificity/sophistication default to medium. Also
available: max_hits, path_include. See the schema section of WRITING_RULES.md.
guarddog/analyzer/sourcecode/ as {type}-{category}-{detail}.yar..meta files (shared private rules) are {pattern-name}.meta.
WRITING_RULES.md before finishing.The harness is tests/analyzer/sourcecode/test_sourcecode_yara.py. Key points:
File capability-filesystem-read.yar must contain rule capability_filesystem_read. The
no-false-positive test filters matches to this exact name, so a mismatch silently skips coverage.
tests/analyzer/sourcecode/<rule-id>.<ext> containing code the ruleshould flag (e.g. <rule-id>.py, .js, .go, .rb). The harness asserts the rule matches it.
These are matched by filename prefix.
tests/analyzer/sourcecode/benign/<rule-id>.<ext> withlegitimate code that must NOT trigger the main rule. Every new or changed rule should have one.
.yar files must compile, including include "...meta" references resolving.Run the suite:
make test-yara-rules
# or directly:
uv run pytest tests/analyzer/sourcecode -k <rule-id>
Scan a real package or local path to sanity-check end to end (use uv run):
uv run guarddog pypi scan <package-name> --rules <rule-id>
uv run guarddog pypi scan /path/to/package --output-format json
subprocess.call(). The threat is the LOLBAS tool *inside* the hook. Pair
capability.process.hooks with threat.process.hooks (hook context + curl/wget). See the
Advanced Patterns section of WRITING_RULES.md.
lolbas-proc.meta (bash, python, node) vs lolbas-net.meta(curl, wget, nc). YARA cannot reliably use multiple private rules from one include, so keep
them separate and compose includes per rule.
with private rules rather than matching a bare keyword anywhere.
make docs.Take datadog/writing-guarddog-rules from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.