Starting off with some simple utility rules.
There are multiple ways to determine what file format we are dealing with, but one of the simple ones is to check the “magic bytes” at the beginning of the file, for Windows PEs we are looking for 0x4D5A. As YARA works in little-endian by default, we reverse this to 0x5A4D.
rule file_pe_header {
meta:
description = "Finds PE file MZ header as uint16"
last_modified = "2024-01-01"
author = "@petermstewart"
DaysofYara = "1/100"
condition:
uint16(0) == 0x5a4d
}
Find the rest of my 100DaysofYARA posts here, and the rules themselves on my Github repository.