SOC and blue team
YARA Rules for Beginners: Examples and Cheat Sheet
YARA is a pattern-matching tool used to identify and classify malware. You describe what a file looks like in a rule, then scan files, folders or memory for matches. Analysts and threat intelligence teams share YARA rules the way they share indicators.
Install
sudo apt install yarayara --versionconfirms it.
A First Rule
Save this line as lab.yar. It looks for the text "labtest" in a file:
rule LabTest { strings: $a = "labtest" condition: $a }
A rule has a name, a strings section that lists patterns and a condition that says when it matches. Create a test file containing the word, then scan: yara lab.yar testfile.txt. YARA prints the rule name when the file matches.
Scan More
yara -r lab.yar /path/to/folderscans a folder recursively.yara -s lab.yar testfile.txtalso prints the strings that matched.- Only scan files you own or have permission to examine. Treat real malware samples with care: use an isolated VM with no network.
Better Conditions
2 of themrequires at least two of your strings, which cuts false positives.filesize < 2MBskips large files.uint16(0) == 0x5A4Dchecks for the "MZ" header at the start of a Windows executable.
Cheat Sheet
yara rules.yar targetscans a file.-rscans folders recursively.-sprints the matched strings.-mprints rule metadata.-cprints only the number of matches.2 of them,any of them,all of themare common conditions.
We ran this rule and each option above on a test file before publishing.
What YARA Cannot Do
A rule that is too loose flags harmless files; one that is too tight misses a changed sample. Attackers change strings easily. Good rules combine several stable traits, and every rule needs testing against clean files. See malware analysis for beginners for how to find those traits, and what is threat hunting for how teams use rules.
Sources and Further Reading
Want to hunt in a lab with real detection practice? Book free trial classes. Contact us or call +91 86868 92922.
Courses Mentioned in This Guide
More Guides
CyberChef for Beginners: Decode Data Like a SOC Analyst
Use CyberChef to decode Base64, hex and URL encoding, read encoded PowerShell, extract IPs and URLs, and chain steps into recipes, all in your browser.
Read the guide →Incident Response Steps Explained: From Alert to Lessons Learned
The incident response lifecycle explained: preparation, detection and analysis, containment, eradication, recovery and lessons learned, plus DFIR evidence basics.
Read the guide →Sysmon for Beginners: Install, Config and Event IDs
Install Sysmon on a Windows lab VM, apply a config, and read the key events for process creation, network connections and DNS, with PowerShell commands.
Read the guide →What Is a SIEM? Explained for Beginners
What a SIEM does: collect logs, normalize, correlate and alert. Examples such as Splunk, Wazuh and Sentinel, use cases, limits and how to practice.
Read the guide →Start Your Cyber Security Career
Talk to a counselor, choose the right course for your goals, and get the fee, syllabus and next batch dates in writing.
- Call+91 86868 92922
Open 7 days: Mon to Fri 8:30 AM to 8:30 PM IST
Sat and Sun 10 AM to 6 PM IST - Emailinfo@hackingtrainer.com
- VisitGround Floor, G-3, Sri Venkatasai Nest, Kallu Compound Road, Nagarjuna Nagar Colony, Yella Reddy Guda, Ameerpet, Hyderabad – 500073
Open in Google Maps