YARAのstring・conditionと記録1 / 2
Ruleの構成
Rule名、meta、stringsとconditionを定義する。metaは説明/作者/版等の資料化、stringsはtext/hex/regexの候補、conditionは一致条件である。Stringは既定でcase-sensitiveで、nocase/ascii/wide等のmodifierを用途へ合わせる。stringの組合せは、conditionに指定した条件で評価する。
rule Shirureka_MZ_Marker {
meta:
description = "MZ header and demonstration marker"
version = "1"
strings:
$marker = "SHIRUREKA_SAMPLE" ascii
$tag = { 54 52 49 41 47 45 }
condition:
uint16(0) == 0x5A4D and filesize < 1MB and all of them
}
先頭MZ、1MiB未満、markerとTRIAGEのbyteが両方あるfileへ一致する。MZだけで有効なWindows PE全体を検証したことにはならない。little-endianのuint16(0)とbyte順に注意する。all of themをany of themへ変えるとstring条件が緩くなる。