Module 08 of 12
The Omega Rule Language
Omega is VeriSigma's rule language. A rule can select files by name, location, time, size, hash, type and content, or tie related files into a group, and each match becomes a database row you can verify. YARA users will recognize much of it.
Objectives
What you will be able to do
- Read and write file rules, putting each section in the required order.
- Match on exact hashes and on TLSH distance.
- Build bigger rules from clauses, private rules, pattern sets and lists.
- Write a group rule and explain the anchor and optional members.
- Run rules, interpret the result tables, and read the SQL a rule compiles to.
- Convert YARA rules and interpret the gap report.
Knowledge check
Try this before you read
Pick an answer and write one sentence on why. The explanation appears once you have. Come back to it after the key ideas and see whether your reasoning changed.
Show the answer
Answer: As a file that behaves like the staging tool; it did not match the known hash
Clauses keep their own identities, and the results record which one fired. Matching the known hash and behaving like the tool are claims of different strength. The rule's name must not lend the stronger claim to the weaker match.
Key ideas
One idea at a time
Rule files and namespaces
An Omega file is a series of declarations. Each begins with one of five keywords:
rule,patterns,list,namespaceoruse. A rule declaration isrule, optionallyprivate, thenfileorgroup, a name, and a body in braces. With an empty body it matches every file, and sections narrow it down. Every declaration sits in a namespace, and since there is no default, a file must name one before its first rule.use registry.windows.hives as hivesshortens a long prefix. Omega reads all supplied rule files before resolving references, so file order doesn't matter and a team can maintain a common library that others extend.Six sections, cheapest test first
A file rule can contain up to six sections,
meta,file_metadata,hash,signature,patternsandcondition, in that order and none twice. Getting the order wrong, or repeating one, is an error. A file must satisfy every section that is present. The order tracks cost. Metadata tests are free, a hash needs the file read once, and patterns need a full scan.metaaccepts any fields whose values are quoted strings, such as author, date, source and purpose. Since reports refer to rules by name,metais where a reader finds out what a name stands for.The six sections of an Omega file rule, in order from cheapest test to dearest. File properties and paths
file_metadatacan testfilename,filepath,dirpath,stem,extensionandfilesize, pluscreated,modifiedandaccessedwritten as quoted ISO-8601 strings. String tests arecontains,startswith,endswithandmatches. Path comparisons ignore case, because real images mixNTUSER.DATwithntuser.dat.LOG1. The exception ismatches, an unanchored regular expression that is case-sensitive unless it begins with(?i). Escape backslashes, so a folder is written"\\Temp\\". Omega warns about a pathstartswithwith no trailing separator, sinceC:\Users\Publicwould also catchC:\Users\PublicShare.Exact hashes and TLSH neighborhoods
In the
hashsection each line is one record: one or more digests of a single content, usingmd5,sha1,sha256,blake3ortlsh. A file matching any record matches, and any digest within a record is enough. Omega validates the length and characters of each digest, so pasting a truncated hash fails loudly instead of silently missing. Atlshentry describes a neighborhood, by default everything within distance 30; settlsh_distance=to widen it. That catches a tool rebuilt or slightly patched for each victim. It does not identify the tool. Tiny files, and files that are mostly shared libraries or padding, cluster together for dull reasons. Files below 50 bytes or with little byte variety have no TLSH digest and never match one.Signatures, patterns and conditions
signaturechecks the content-derived type, by name or id, and is case-sensitive. Pairingextensionnot exe, dll or sys with asignaturename of “Executable” answers a standard triage question: which executables are disguised by their names?patternsholds Lightgrep expressions, with optionalfixed,nocaseandencodings=UTF-8,UTF-16LE, plus hex strings in braces that copy straight to and from YARA.conditioncombines patterns withany(),all(),count(),count_has_hits(),offset()andlength(). Leave out the condition and a rule with patterns matches on a hit from any of them.Clauses, private rules and lists
Within one rule, sections combine with and. For or, repeat the rule name: each declaration becomes a clause, and the rule matches anything any clause matches. Clauses keep separate identities, so results show which one fired. A hash hit and a behavioral hit are different claims, and a report should never let the weaker one borrow the stronger one's name. A
privaterule runs normally but stays out of listings and reports; its job is to be referenced, usually to filter out known-good files. A top-levelpatternsset can be shared by name, and alistof strings or numbers feedsany()orall().File groups
Some evidence only makes sense as several files: a hive plus its
.LOG1and.LOG2files, or a database plus the write-ahead file beside it. Agrouprule hasmeta,membersandcondition. Each member names a file rule and is required unless marked(optional). The first required member is the anchor, and each file it matches opens a candidate group. The condition links every other member back to the anchor, for instance a log in the same directory whose stem equals the hive's file name. A hive with no logs still forms a group. Members are always drawn from one file system in one evidence item.Results you can reproduce
In a hunt, files that no rule's
file_metadatacould match are never hashed or scanned, yet the results equal a full run. Speed depends on how tight those sections are. Results go intorules,patterns,rule_matches,group_matches,search_hitsandtlsh_matches. Explain prints the SQL each clause compiles to, with its query plan. A clause's identity hashes its text, comments included, together with its qualified name. Reformatting doesn't alter it; any real edit does. So identical rules on identical data give identical rows, and a cited rule identity is tamper-evident: edit the rule and the identity no longer matches. For long lists of digests, use hash sets built withmkhashset. Inclusion sets flag files of interest. Exclusion sets skip content work on known files while still listing, hashing and recording them.Translating YARA
omega translate-yara SOURCE TARGETconverts a directory of YARA rules into.omegafiles, one per source, plus a translation report in Markdown and CSV. Conversion is strict: a rule is emitted only if each construct maps exactly, and the report lists each unsupported construct and how many rules it held back. Text and hex strings, counts, offsets, and filename and size conditions convert. YARA modules such aspeandmath,forloops, arithmetic andfullworddo not.--lossydropsfullword, which makes the translated rule match more than the original. If a finding depends on a lossy rule, say so in the citation.
Scope
Before you move on
Could you explain each item on the left to a colleague without looking back? If not, reread that idea. The right-hand list is where this module stops.
What this covers
- Rule files, namespaces and the six sections
- Matching by exact hash and by TLSH neighborhood
- Signatures, patterns and conditions
- Clauses, private rules, pattern sets and lists
- File groups, hunts, result tables and rule identity
- Translating YARA
What it does not
- Writing parsers for new artifact types
- YARA modules, loops and arithmetic, which do not translate
- Every option of the omega command line