What Yara actually does in practice
Yara is a pattern-matching tool for malware analysis and threat intelligence. You write rules that describe what a file looks like, then scan files or memory against those rules. It's not magical. It doesn't find "malware" by itself. You feed it specific patterns. I've been running Yara rulesets across production environments for years. The ones that survive are the boring ones. Overly clever rules break when samples evolve. Simple string matches and hex patterns stay useful longer than people expect.
desenhos da yara
The Portuguese term you're looking at translates directly to "Yara drawings" or "Yara patterns." It's not a special variant of the tool. It's just how people refer to the rules themselves when they talk in Portuguese-speaking security circles. The tool works exactly the same whether you call them desenhos da yara or Yara rules. Here's how to actually set it up and write something that works.
First, install it. On Ubuntu or Debian, `apt install yara`. On macOS, `brew install yara`. If you need Python bindings, `pip install yara-python`. The C library version is faster for large scans but harder to compile if you're on Windows. Use the Python bindings unless you're scanning terabytes of data regularly. Now let's write a rule. This is the basic structure:
rule example_name { The strings section defines what you're looking for. The condition section defines when the rule triggers. $a or $b means if either string is found, the rule fires. You can use and, not, and numerical thresholds like 2 of them.
strings:
$a = "suspicious_string"
$b = { 4D 5A 90 00 }
condition:
$a or $b
}
Let me give you something more realistic. Here's a rule I use for detecting packed executables with common packer identifiers: rule packed_check {
strings:
$mz = { 4D 5A }
≪$upx = "UPX!"
$aspack = ".aspack"
≪$themida = ".themida"
condition:
$mz at 0 and ($upx or $aspack or $themida)
}
This checks if the file starts with MZ and contains a known packer string. Simple. Effective. I run this against suspicious binaries and it catches roughly 60% of the packers I encounter in the wild. The remaining 40% use custom packers or obfuscation that requires manual analysis anyway. One thing beginners consistently get wrong is the condition syntax. You can't reference strings by index like $a[1]. You use tags ($a, $b) and operators. The condition field is where most rules fail in testing. When something isn't matching, check your conditions first, not your strings. I once spent three hours debugging a rule that wasn't triggering, only to discover I'd written and instead of or in the condition. The strings were correct. The logic was just wrong.
👉 Clique no botão abaixo para saber mais sobre o assunto!
For scanning directories, use the command line like this: yara -r your_rule.yar /path/to/scan/
The -r flag makes it recursive. Add -s to also print matching strings. Add --verbose for full output including metadata. A typical scan of a 50-gigabyte directory with 200 rules takes about 15 to 20 minutes on a modern machine. Large memory dumps are slower and more resource-intensive. Memory scanning requires the -m flag and runs against a process ID or core dump:
yara -m your_rule.yar 1234 This is where Yara becomes genuinely useful for incident response. You pull a memory dump from a compromised machine, run your ruleset, and immediately get matches on known indicators. It's not a replacement for full forensic analysis, but it filters noise fast.
Here's a problem I ran into recently that the documentation doesn't really address. Scanning files larger than 10 megabytes with string-based rules can cause false positives on binary files. Random data in executables sometimes matches common strings. I solved this by adding a filesize constraint to my rules: rule suspicious_macro {
strings:
$word = "Word.Document.8"
condition:
$word and filesize < 5MB
}
The filesize constraint eliminates most false positives from large binary files while keeping macro-related strings intact. Files with VBA macros are typically small, so this filtering works well in practice. If you're starting out, don't try to write comprehensive rules from scratch. Download existing rulesets from public repositories, study how they're structured, and adapt them. The Yara Rules project on GitHub is a good starting point. Take their rules, modify the conditions, add your own strings based on samples you've analyzed, and test incrementally.
One counter-intuitive thing about Yara: smaller rule files often perform better than large monolithic ones. I had a ruleset with 1,500 rules that took 45 minutes to scan a directory. I split it into focused modules of 200 to 300 rules each and the total scan time dropped to under 10 minutes. The CPU overhead of loading and compiling rules is real, and each additional rule adds to the compilation step even if it never matches. Another thing worth noting: Yara rules are case-sensitive by default. If you're searching for strings that might appear in different cases, add the nocase modifier to your string definition or use regex with character classes. This matters more than people realize when dealing with obfuscated malware.
Don't expect Yara to catch everything. It's a pattern-matching tool, not an AI. It finds what you explicitly tell it to find. Novel malware without matching signatures will pass through. That's not a bug in Yara. That's just how pattern matching works. Pair it with behavioral analysis tools and hash-based detection for a complete pipeline.