Days 76–77 · 3 min read
YARA Rule-Writing Philosophy
Balancing accessibility, simplicity, and redundancy across four detection facets: strings, metadata, code, and techniques.
On this page (3)
Day 76 - Greg’s Challenge: Introduction
Greg Lesnewich (@greglesnewich) put out a challenge to write some YARA rules for a collection of samples: https://twitter.com/greglesnewich/status/1630615467776786458
As I had seen that other’s had picked Hikit and Reductor, I’ve decided to go for AcidBox.
Palo Alto’s Unit42 released a great blog on this malware family in 2020, which is nicely laid out, and shows a variety of samples as part of the framework: https://unit42.paloaltonetworks.com/acidbox-rare-malware/
Over the next set of posts, I will dive into how I’ve written some rules for this malware family!
Rule writing philosophy
Before I start writing some rules however, I think its worth discussing my general ideal approach/“philosophy” I have when writing rules for malware, which follow three ideas:
- Accessibility - make you rules as easy to understand and read as possible, and provide as much context as you can
- Simplicity - this doesn’t mean the logic of the rule needs to be simple, but as complexity increases consider breaking out ideas into smaller rules to keep the main idea of the rule simple
- Redundancy - write rules for multiple facets of the malware you’re trying to signature to have more of a chance of continuing to track it
I believe these three ideas combined can lead to rules being very context rich, clear, and effective. As such, I will be writing small, but clear rules over the next few posts.
Day 77 - Aside - Facets to Signature
When we write YARA rules, there are several different categories/facets that we can focus on. In roughly increasing order of complexity, I think these can fall into the following categories:
- Strings - plaintext (or encoded) strings seen within a sample
- Meta features - metadata associated with the file itself (such as headers or artefacts left in compiled samples)
- Code - signaturing the code of the sample itself (whether compiled, or the plaintext code that will be interpreted later on)
- Techniques - abstracting away from any of the previous facets to focus on having a signature for a technique being used
It may not always be possible to write rules for a sample covering all of these features; a packed sample may not have any plaintext strings to work with, or a webshell may not have enough unique code to make a reliable rule. However, if you can cover a variety of these categories, you’re already building in redundancy into your rules to cover a malware family, especially if you can cover a technique well.
The tools you use to analyse these facets can vary a lot depending on the sample! Sometimes you can get away with just a text editor if you’re looking at scripting languages like PowerShell, VBScript, or JavaScript. But for compiled languages, you may have to use more specific tooling.
While there are many commercial options available, you can use a mixture of the following free tools to do the analysis needed for writing rules:
- strings2 - extracts plaintext ASCII and unicode strings (alternatives like FLOSS are great for dumping out encoded strings, but I like to see what I have to work with in plaintext first)
- Detect It Easy - determines file types, and shows meta features of them
- Ghidra - a reverse engineering framework for a variety of processor types
- HxD - a great, free hex editor for copying/editing the hex representations of files