Rules for files and traffic: YARA and Suricata
Unit 3 of 5 in Logging and detection.
You will be able to explain what YARA and Suricata rules match and where each fits.
Lesson
Three places to look
Sigma rules read log events. Two other open rule languages cover other evidence. YARA rules describe files, so you can scan a file or folder and see which rules match. Suricata rules describe network traffic, so a sensor watching a network link can raise an alert when a packet or a stream matches.
The same behaviour can often be caught in more than one place. A defender picks the place where the evidence is easiest to collect and hardest to hide.
YARA: matching files
YARA is a multi-platform program that runs on Windows, Linux and macOS. A rule has a name and a condition, and the simplest possible rule is one whose condition is always true. You run the tool with the rule file and the file to be scanned, and it prints the name of each rule that matches. Real rules describe patterns found in a file and combine them in the condition.
Use YARA for files you already hold: a quarantined attachment, a disk image, a memory dump. Do not run it against files you are not permitted to examine.
Suricata: matching traffic
A Suricata rule has a fixed shape. Its documentation lists the parts in order: an action that says what to do on a match, a protocol, the source and destination, the ports, the direction of the traffic, and then options in parentheses that describe what to look for. Keywords exist for many protocols, including HTTP, DNS, TLS and file transfers.
A network rule can catch behaviour no host log records, such as one workstation reaching many others on the same service port, which is how worm-like spreading shows up. It is blind to what encryption hides, which is why you use it with host logs and not instead of them.
Choosing between them
Ask what the attacker cannot avoid leaving. A tool dropped to disk leaves a file, so YARA fits. A new connection pattern leaves traffic, so Suricata fits. A change in who logged in from where leaves a log event, so Sigma fits. The most reliable detections combine two of these.
Key points
- Sigma reads logs, YARA describes files, Suricata watches traffic.
- A YARA rule has a name and a condition; the tool prints the names of matching rules.
- A Suricata rule has an action, protocol, source, destination, ports, direction and options.
- Pick the place where evidence is easiest to collect and hardest to hide; combine two when you can.
Sources
- YARA documentation: Getting started
- Suricata documentation: Rules format
- Sigma documentation: Getting Started
Practice in the labs
Scan files with YARA, then set up a network sensor and read what it says.
- Write your first YARA rule to detect files by pattern: You write and run your first YARA rules on files you create.
- Set up Suricata to watch your own network (open-source IDS): You install a network sensor and see its first alerts.
Also try, in the simulators
- YARA: matching patterns in files (Detection Lab lesson): The Detection Lab course lesson on matching patterns in files.
- Network signatures with Suricata (Detection Lab lesson): The Detection Lab course lesson on network signatures with Suricata.
- Find one workstation sweeping others on the file-sharing port (Detection Lab task): You write a network rule that finds one workstation sweeping others on the file-sharing port.
Knowledge check
- Which rule language describes files? Answer: YARA. YARA rules are run against files and report which rules match.
- Name the order of the first parts of a Suricata rule. Answer: Action, protocol, source and destination, ports, direction, options. The Suricata rules format documents an action, protocol, source and destination, ports and direction, followed by options.
- Why combine network rules with host logs? Answer: Encryption hides content from the network, and hosts see what the network cannot. A network sensor cannot read encrypted content, while host logs record local actions; together they cover each other's gaps.
Back to the syllabus or see all classes.