Write and test YARA rules against a file, in the browser YARA
YARA is how analysts write detections. This runs the match in the browser, so a rule can be tried against a real, sensitive sample without the sample ever leaving the machine.
The rules
The sample
Results
How it works
What it runs, and what it does not
This reads the strings-and-condition part of YARA: text with nocase/wide/ascii/fullword/xor, hex with ?? and half-byte wildcards, ~, alternatives and jumps, regex with i/s flags, and conditions with and/or/not, any/all/N of them, #a counts and filesize. It does not implement YARA’s modules, offsets, integer reads such as uint16(0), for loops or the base64 modifier; a rule that uses one is marked as not read, with the reason, rather than matched wrongly. For those, and to sign off a finished rule, use the yara binary. Everything here stays in the browser.
Questions people ask about YARA
What is a YARA rule?
A named test for a file. It lists strings to look for, as text, hex bytes or regular expressions, and a condition that says which combination of them counts as a hit: rule dropper { strings: $a = "powershell" nocase $b = { 4D 5A } condition: $b and #a > 2 } fires on a file containing the bytes 4D 5A and more than two mentions of PowerShell in any case.
Analysts use rules to describe a family of malware or a leaked document precisely enough to find it again. Each rule here is reported as fired or not, with every string’s hit count and where its first hits are.
Which parts of YARA does it support?
Text strings with nocase, wide, ascii, fullword and xor (all keys, xor(0x20) or a range such as xor(0x01-0xff)), and the escapes \", \\, \n, \t, \r and \xHH. Hex strings with ?? and half-byte wildcards such as 4?, ~4D for any byte but that one, alternatives such as ( 4D | 5A ), and jumps written [4], [2-6], [2-] or [-]. Regular expressions with the i and s flags, and nocase or fullword after them.
In conditions: and, or, not and parentheses; $a; #a compared with a number; any of them, all of them and 2 of ($a,$b,$c), with wildcard sets such as ($s*); and filesize against a number with KB, MB or GB. Several rules can go in the box at once.
What does it not support?
Modules (pe., elf., math., hash.), reading integers such as uint16(0), offsets ($a at 0, $a in (0..100), @a[1]), for … of loops, the base64 and base64wide modifiers, and wide or xor on a regular expression.
A rule that uses one is marked as not read, with what stopped it, and is not run, so it never gives an answer the yara binary would not. Use this bench to write and test the strings, and run the finished rule through the binary before you rely on it.
What does the wide modifier do?
It looks for the string as UTF-16 little-endian, which is how Windows stores text inside programs and many documents: each character followed by a zero byte, so "cmd" becomes 63 00 6D 00 64 00. On its own, wide finds only that form; wide ascii finds either.
Here the zero byte is added after each character, which is right for ASCII text and not for characters outside it.
Why does my regular expression behave differently from yara’s?
Because it is run by the browser’s own JavaScript regular expression engine, not by YARA’s. Ordinary patterns behave the same, but the two differ at the edges, so a pattern that relies on one engine’s corner cases should be checked with the yara binary.
The sample is matched as bytes, one character per byte, and . does not match a newline unless the s flag is set. The rules run in a separate worker, and one that backtracks badly, such as /(a+)+$/ on a long run of a, is stopped after 10 seconds with a message instead of freezing the tab.
How large a sample can it test?
Strings are matched against the first 32 MB of the file; filesize is always the file’s real size. Each string counts up to 100,000 hits, and the offsets of the first 20 are listed in hex.
One sample is tested at a time, a file you open or text you paste, which is encoded as UTF-8. The rules run again as you edit them, so the result follows what you type.
Doing this often? The Sovereign Console runs detection across every file in a case, with Sigma rules and hash sets, and exports a report. On its own, US$2 a month; with everything else, US$5 a month or US$48 a year.