HackBlue

Labs / YARA triage

YARA rule builder

Pick strings and write a condition that matches five builds of one loader and none of five clean files, including an antivirus signature database.

  • Interactive lab
  • Advanced
  • 5 steps
  • 0 of 5 solved

What you’re looking at

Pick strings and write a condition that matches five builds of one loader and none of five clean files, including an antivirus signature database.

Your goal: Build a rule that matches all five loader builds and none of the five clean files.

Candidate strings
the strings on the left, each with a switch and a note on what it is. Switched-on strings go into the rule.
condition
the text box under the strings. The buttons insert words like and, 2 of, and the MZ header check.
Sample set
the table on the right. One row per file with whether it is a Windows executable (MZ), its size, which strings it contains, and whether the rule matched.
Walkthrough
the numbered path beside the workbench (below it on a phone). Each step says what to do and what you should see. Hints open one at a time.

Words you will meet

YARA
a rule language for finding patterns in files

Start with step 1 in the walkthrough. Every step says what to do and what you should see. The whole thing takes about 2 min to talk through.

Briefing

Incident response pulled five builds of the same loader from three hosts. You also have five clean files from those hosts that a good rule must leave alone, including an antivirus signature database.

Choose which candidate strings go into the rule, write the condition, and scan the set. The rule is ready when it matches every loader and nothing else. Samples are modelled by the strings they contain; no binaries are involved.

Candidate strings

  • Mutex name the loader creates
  • Config block marker “QX7CFG”
  • Drop path for the second stage
  • User agent used for check-in
  • Shell command prefix
  • Windows system library name

5 of 5 loaders matched · 4 false positives · 0 missed

rule QX7_Loader
{
    meta:
        description = "QX7 loader family, lab sample set"
        author = "HackBlue lab"
    strings:
        $mutex = "Global\\qx7-sync" ascii wide
        $cfg = { 51 58 37 43 46 47 ?? 01 }
        $ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" ascii
        $k32 = "kernel32.dll" ascii nocase
    condition:
        any of them
}
Sample setyara -s qx7.yar samples/
FileMZSizeContainsMatchTruth
loader_a.exeyes210 KB$mutex $cfg $path $ua $cmd $k32 matchloader
loader_b.exeyes198 KB$mutex $cfg $path $ua $k32 matchloader
loader_c.dllyes240 KB$mutex $cfg $ua $cmd $k32 matchloader
loader_d.exePacked build, mutex name is generated at run timeyes205 KB$cfg $path $ua $k32 matchloader
loader_e.exeNewest build, config marker changedyes221 KB$mutex $path $ua $k32 matchloader
setup.exeSigned installer for a PDF readeryes3.1 MB$cmd $k32 $ua matchclean (false positive)
browser_helper.exeyes1.2 MB$ua $k32 matchclean (false positive)
notepad.exeyes200 KB$k32 matchclean (false positive)
av-defs.binAntivirus signature database that lists these indicatorsno8.4 MB$mutex $cfg $path matchclean (false positive)
cleanup.ps1Admin scriptno4 KB$cmd no matchclean

The whole walkthrough

Every step in order, written to be read aloud: 291 words, about 2 min. It gives away every answer, so try the steps first.