What Is a YARA Rule?

A YARA rule describes what a file looks like on the inside, as named patterns plus a condition, so you can find files that no hash list would catch.

A YARA rule is a short, readable description of what a file looks like on the inside. You list the pieces of content you expect to find, such as a distinctive text string or a specific sequence of bytes, then write a condition saying which combination of them counts as a match. Stairwell runs the rule against files and tells you which ones satisfy it. YARA is an open, industry-standard language, so the rule a vendor publishes in a report, the rule a colleague shares on GitHub, and the rule you write in Stairwell are all the same kind of artifact.

Why match on file contents instead of a hash?

Because a hash identifies exactly one file and says nothing about any other. A hash is a fingerprint of the precise bytes: change one of them and the fingerprint is entirely different. That is a useful property for proving two files are identical and a fatal one for hunting, because changing a byte is the cheapest thing an attacker can do. Recompile the same source, repack the same payload, pad the file, swap a hardcoded address, and every hash-based block list in the world stops recognizing it while the tool keeps working exactly as before.

A YARA rule describes the file at a level the author cannot change as cheaply. The embedded command-and-control hostname, the unusual mutex name, the odd decryption constant, the format of the strings the malware prints when it fails, the specific combination of imported functions: these are the things a family carries from build to build, because they are what the code does rather than what the compiler happened to emit. Match on those and you catch the next build, the sibling, and the repack, not only the one sample somebody happened to submit.

That is the whole argument for pattern matching over exact matching, and it is why threat intelligence is increasingly published as rules rather than as hash lists. A hash tells you about a sample. A rule tells you about a family.

What is a YARA rule made of?

Conceptually, two parts, plus a label.

Strings are the patterns to look for, each given a name. A pattern can be literal text, a sequence of raw bytes written in hexadecimal, or a regular expression. Naming them matters more than it looks: the names are what let the condition talk about them, and they are what tells the next analyst why the pattern is there.

The condition is a single logical expression that decides whether the file matches. It can require all of the strings, any two of them, one of them at a specific place in the file, or none of them at all. It can also test properties of the file itself, such as its size or whether it is a Windows executable, which is how a rule author keeps a rule from wandering into file types it was never meant for.

Metadata carries the name, the author, a description, and often the malware family and a reference link. It has no effect on whether a file matches. It is there so a human reading the rule six months later knows what it claims and who to ask.

Reading a rule, then, is a matter of asking what the condition actually requires. A rule that asks for three specific strings in a Windows executable under 500 KB is making a narrow, checkable claim. A rule that asks for any one of three common strings is making a very broad one. You do not need to write YARA to see the difference, and seeing the difference is most of what reading a rule is for. When you are ready to write and manage your own, see YARA rules.

Is a YARA hit a detection?

No. A hit is evidence, and evidence is not a verdict. A rule that matches a legitimate administration tool has produced a match, not a detection. This distinction is worth holding onto, because rules are written by people making judgment calls about which patterns are distinctive, and a pattern that seemed distinctive can turn out to be common in software the rule author never saw.

So a hit is a starting point. Read what the rule claims, then weigh the file against the things a rule cannot know: how rare the file is (see Prevalence), what the automated verdict says, which of your assets have seen it, and whether your team has already reached a conclusion about it. Dual-use software is the common case here. Remote administration tools, packers, credential utilities, and penetration-testing frameworks match malware rules because attackers use exactly those tools.

Stairwell reduces the blast radius of a broad rule rather than trusting it. A new rule is measured against known-good files before it scans anything of yours, and a rule that matches too many of them is excluded from scanning and marked in the Rules list. That means you can be aggressive with a detection idea without gambling on an alert storm, and the platform tells you the condition is too broad before your team finds out the hard way.

What do I do with a YARA rule?

  • Read a rule someone else published and decide whether it is worth running: what it claims, how narrow the condition is, and whether the strings look like the malware's fingerprint or like something ordinary software also contains.
  • Run it across your history, not only against what arrives next. A rule in Stairwell is a question you can ask of the past, which is what turns intelligence published this morning into an answer about last spring.
  • Read the matches as a pivot, not a conclusion. From a matched file, look at its rarity, its variants, and the assets that saw it.
  • Tighten it when it is noisy. A rule matching your own build tooling is a rule with the wrong strings in it, and the fix is a narrower condition rather than a muted alert.
  • Keep the metadata honest. A rule with a description and a family name is a rule the next analyst can act on without finding you first.

Where do I see YARA rules in Stairwell?

  • The YARA Rules section, where your rules live, alongside rules from any rule sets you subscribe to. The editor reports compile errors inline as you type, so a rule that will not run tells you why before you save it.
  • The YARA section of the object panel, which lists the rules that matched the file you are looking at, with a count in the section header.
  • Threat report panels, because a report can ship YARA rules as indicators in the same way it ships hashes and domains.
  • Your notifications, when a rule match satisfies a trigger you have configured.

What should I read next?

  • YARA rules for creating, editing, and organizing rules in your environment.
  • Variants, the other answer to the problem of hashes changing, and the one that needs no rule at all.
  • What is a threat report?, since rules arrive most often as part of published intelligence.

Did this page help you?