b2KIT

YARA Rule Builder

Build YARA rules visually with string patterns, hex patterns, and conditions. Export rules for malware detection scanning.

Tested tool guide Tested browser tools Checked August 16, 2026

What YARA Rule Builder does, with a checked example

YARA is the pattern language malware scanners speak: a rule names strings - quoted text, brace-delimited hex, or slashed regexes - and adds a condition that must hold for a file to match. This tool builds that structure visually: you enter the patterns, pick the condition operators, and it exports a complete rule for YARA or yara-python. What surprises newcomers is that a rule matches whenever its condition is true, and conditions are Boolean expressions, not positional recipes - so a loose condition flags far more than the malware you had in mind.

Worked example

A concrete input and expected output from the current implementation.

Input

Text string: "password"; hex pattern: { 50 4B 03 04 }; condition: $a and $b; rule name: PkZipEmbedded

Expected output

rule PkZipEmbedded
{
    strings:
        $a = "password"
        $b = { 50 4B 03 04 }
    condition:
        $a and $b
}

In the exported rule, $a is bound to the text string and $b to the hex pattern, and the rule is emitted with the chosen condition. It matches any file containing both the ASCII text "password" and the four bytes 50 4B 03 04 (the ZIP local-file-header signature), anywhere in the file, in any order.

How the result is produced

1

String types and modifiers

Text strings match a literal byte sequence, ASCII by default, with modifiers such as wide or nocase appended. Hex strings in braces encode exact bytes, wildcard nibbles (? matches half a byte, ?? a whole byte), and jumps: [2] skips exactly two bytes, [4-6] skips four to six. Regexes in slashes cover alternatives. Each string gets an identifier like $a, and identifiers can be grouped with wildcards, as in any of $a*.

2

Conditions and matching

The condition is a Boolean expression. A bare $a means "string $a appears at least once"; combine strings with and, or, not, and count forms like 2 of them. Conditions can also test file properties: filesize, uint16(0) for bytes at an offset, the match count #a, or the first match offset @a. The rule hits when the whole expression is true; order and proximity matter only where you express them.

Good uses

  • Extract a distinctive byte sequence from a captured sample - a loader's unique API-resolution stub - build a hex pattern from it, and sweep a folder of suspicious downloads with the exported rule.
  • Screen attachments for malicious combinations - an embedded OLE object plus macro keywords - using several text strings and a 2 of them condition.
  • Produce a shareable .yar rule to hand to a team or feed a scheduled scan via the yara command or yara-python, with no one editing rule syntax by hand.

Limits and checks

  • Matching is not detection. A hit means only that your condition was true, and short strings like "password" appear in benign files. Precision is entirely up to the strings and operators you chose, so expect false positives on a loose rule.
  • Position is permissive by default: $a and $b are satisfied by matches anywhere in the file, with no ordering implied. Two strings thousands of bytes apart can satisfy the rule; use offset tests (at, in) if location matters.
  • No tool can predict which real files a rule will hit. A condition of true, or a rule with one generic string, matches almost everything, so always test an exported rule against known-clean files before relying on it.

Common questions

Will my rule still detect a sample after it is packed or obfuscated?

Often not. Packing rewrites the file's bytes, so text and hex signatures that matched the original usually vanish; a condition anchored to a header that survives, like a PE signature check, may still hit. Treat the rule as tuned to the samples you built it from, and rebuild it when a new variant appears.

Why does my rule match files that are clearly not malware?

Because YARA only evaluates your condition - it never judges what a file is. An and-condition can be satisfied by two unrelated matches, and one generic string will appear in many legitimate files. Tighten the rule: require more strings, use hex wildcards and jumps to encode structure, and add file-level tests like filesize or header bytes.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools