This repository was archived by the owner on Sep 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathexample.yara
More file actions
179 lines (136 loc) · 2.72 KB
/
Copy pathexample.yara
File metadata and controls
179 lines (136 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
* This will match any file containing "hello" anywhere.
*/
rule AsciiExample {
strings:
// A string to match -- default is ascii
$ascii_string = "hello"
condition:
// The condition to match
$ascii_string
}
/*
* This will match any file containing unicode "hello" anywhere.
*/
rule UnicodeExample {
strings:
// The 'wide' keyword indicates the string is unicode
$unicode_string = "hello" wide
condition:
$unicode_string
}
/*
* Match any file containing the 01 23 45 67 89 AB CD EF byte sequence.
*/
rule HexExample {
strings:
// A few hex definitions demonstrating
$hex_string1 = { 0123456789ABCDEF }
$hex_string2 = { 0123456789abcdef }
$hex_string3 = { 01 23 45 67 89 ab cd ef }
condition:
// Match any file containing
$hex_string1 or $hex_string2 or $hex_string3
}
/*
* Match any file containing the 01 23 45 ?? ?? AB CD EF byte sequence.
*/
rule WildcardHexExample {
strings:
// A few hex definitions demonstrating
$hex_string1 = { 012345????ABCDEF }
$hex_string2 = { 012345????abcdef }
$hex_string3 = { 01 23 45 ?? ?? ab cd ef }
condition:
// Match any file containing
$hex_string1 or $hex_string2 or $hex_string3
}
/*
* Match any file containing "MZ" (not zero terminated) at offset 0.
*/
rule OffsetExample {
strings:
$mz = "MZ"
condition:
$mz at 0
}
/*
* Match any file containing "PE" anywhere between offsets 32-100 (decimal)
*/
rule RangeExample {
strings:
$pe = "PE"
condition:
$pe in (32..100)
}
/*
* Match any file with "PE" within 0x200 bytes (decimal) of the first occurrence of "MZ"
*/
rule RelativeOffsetExample {
strings:
$mz = "MZ"
$pe = "PE"
condition:
$mz at 0 and $pe in (@mz[0]..0x200)
}
/*
* Match any PE file as defined by MZ and PE signatures at required locations.
*/
rule IsPeFile {
strings:
$mz = "MZ"
condition:
$mz at 0 and uint32(uint32(0x3C)) == 0x4550
}
/*
* Match any file with 55 8B EC (push ebp; mov ebp, esp) at the entry point.
*/
rule EntryPointExample {
strings:
$ep = { 55 8b ec }
condition:
$ep at entrypoint
}
/*
* This will match any file containing "hello" anywhere.
*/
rule ConditionsExample {
strings:
$string1 = "hello"
$string2 = "hello"
$string3 = "hello"
condition:
any of them
/*
all of them
1 of them
any of ($string*)
2 of ($string*)
1 of ($string1,$string2)
*/
}
/*
* Any file containing at least 5 hello strings
*/
rule NumberStringsExample {
strings:
$hello = "hello"
condition:
#hello >= 5
}
/*
* Match any file containing hello that is also a PE file
*/
rule RuleReference {
strings:
$hello = "hello"
condition:
$hello and IsPeFile
}
/*
* Make YARA test only files less than 2MB for ALL rules.
*/
global rule GlobalRuleExample {
condition:
filesize < 2MB
}