VeriSigma
Menu

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

  1. Read and write file rules, putting each section in the required order.
  2. Match on exact hashes and on TLSH distance.
  3. Build bigger rules from clauses, private rules, pattern sets and lists.
  4. Write a group rule and explain the anchor and optional members.
  5. Run rules, interpret the result tables, and read the SQL a rule compiles to.
  6. 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.

A rule named staging_tool has two clauses: an exact MD5, and a behavioral clause (file size plus a command-line pattern). A file matches only the behavioral clause. How should the report describe it?

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

  1. Rule files and namespaces

    An Omega file is a series of declarations. Each begins with one of five keywords: rule, patterns, list, namespace or use. A rule declaration is rule, optionally private, then file or group, 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 hives shortens 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.

  2. Six sections, cheapest test first

    A file rule can contain up to six sections, meta, file_metadata, hash, signature, patterns and condition, 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. meta accepts any fields whose values are quoted strings, such as author, date, source and purpose. Since reports refer to rules by name, meta is where a reader finds out what a name stands for.

    The six sections of an Omega file rule, in order from cheapest test to dearest1metanotes about the rule2file_metadataname, place, size, times3hashcontent digests4signaturefile type, read from content5patternswhat to search for in content6conditionhow patterns and rules combinefreeone reada scanEach section at most once, in this order. Everysection present must match.
    The six sections of an Omega file rule, in order from cheapest test to dearest.
  3. File properties and paths

    file_metadata can test filename, filepath, dirpath, stem, extension and filesize, plus created, modified and accessed written as quoted ISO-8601 strings. String tests are contains, startswith, endswith and matches. Path comparisons ignore case, because real images mix NTUSER.DAT with ntuser.dat.LOG1. The exception is matches, 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 path startswith with no trailing separator, since C:\Users\Public would also catch C:\Users\PublicShare.

  4. Exact hashes and TLSH neighborhoods

    In the hash section each line is one record: one or more digests of a single content, using md5, sha1, sha256, blake3 or tlsh. 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. A tlsh entry describes a neighborhood, by default everything within distance 30; set tlsh_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.

  5. Signatures, patterns and conditions

    signature checks the content-derived type, by name or id, and is case-sensitive. Pairing extension not exe, dll or sys with a signature name of “Executable” answers a standard triage question: which executables are disguised by their names? patterns holds Lightgrep expressions, with optional fixed, nocase and encodings=UTF-8,UTF-16LE, plus hex strings in braces that copy straight to and from YARA. condition combines patterns with any(), all(), count(), count_has_hits(), offset() and length(). Leave out the condition and a rule with patterns matches on a hit from any of them.

  6. 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 private rule runs normally but stays out of listings and reports; its job is to be referenced, usually to filter out known-good files. A top-level patterns set can be shared by name, and a list of strings or numbers feeds any() or all().

  7. File groups

    Some evidence only makes sense as several files: a hive plus its .LOG1 and .LOG2 files, or a database plus the write-ahead file beside it. A group rule has meta, members and condition. 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.

  8. Results you can reproduce

    In a hunt, files that no rule's file_metadata could match are never hashed or scanned, yet the results equal a full run. Speed depends on how tight those sections are. Results go into rules, patterns, rule_matches, group_matches, search_hits and tlsh_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 with mkhashset. Inclusion sets flag files of interest. Exclusion sets skip content work on known files while still listing, hashing and recording them.

  9. Translating YARA

    omega translate-yara SOURCE TARGET converts a directory of YARA rules into .omega files, 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 as pe and math, for loops, arithmetic and fullword do not. --lossy drops fullword, 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

Have a matter that turns on evidence like this? VeriSigma examinations are quoted at a fixed fee.

Request a fixed-fee quote