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

Goal

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

Steps

  1. 01Build a rule that matches all five loader samples and none of the five clean files.

    Do this in the workbench above. This step completes itself when the condition is met.

  2. 02How many clean files does the starter rule (any of them, with four strings) match?

  3. 03Why does av-defs.bin match strings from the loader?

  4. 04The rule uint16(0) == 0x5A4D and $cfg matches four loaders. What does it miss, and what does that teach?

  5. 05Would filesize < 1MB work instead of the MZ header check here?