Repository navigation
Expand file tree
/
Copy pathjavascript.yara
More file actions
346 lines (285 loc) · 8.82 KB
/
Copy pathjavascript.yara
File metadata and controls
346 lines (285 loc) · 8.82 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
rule js_eval: alert {
strings:
$eval_plain = " eval("
$eval_encoded = /\beval\s*\(\s*["']/
$settimeout_str = /\bsetTimeout\s*\(\s*["']/
$setinterval_str = /\bsetInterval\s*\(\s*["']/
condition:
any of them
}
rule js_function_constructor: alert {
strings:
$func_call = /new\s+Function\s*\(/
condition:
any of them
}
rule js_constructor_chain: alert {
strings:
$ctor_chain = /\.constructor\s*\(/
$ctor_bracket_dq = "[\"constructor\"]"
$ctor_bracket_sq = "['constructor']"
condition:
any of them
}
rule js_global_fn_call_from_str: alert {
strings:
$gfcfs = /this\[.*\]\(/ //example: this['ev' + 'al']...
condition:
any of them
}
// to do the same trick as the constructor chain
rule js_prototype_pollution: alert {
strings:
$proto_rw = ".prototype"
$proto_assign = "__proto__["
$prototype_set = /Object\.prototype\.[A-Za-z_$'"]\w*\s*=/
$prototype_bracket = "['prototype']"
condition:
any of them
}
rule js_shell_script_exec: alert {
strings:
$wscript_shell = "WScript.Shell" nocase
$wscript_createobject = "WScript.CreateObject" nocase
$shell_application = "Shell.Application" nocase
$scripting_filesystemobject = "Scripting.FileSystemObject" nocase
condition:
any of them
}
rule js_windows_http_req: alert {
strings:
$xmlhttp = "MSXML2.XMLHTTP" nocase
$adodb = "ADODB.Stream" nocase
$winhttp = "WinHttp.WinHttpRequest" nocase
condition:
any of them
}
rule js_encoding: alert {
strings:
$charcode = /String\.fromCharCode\s*\(/
$atob = "atob("
$buffer_from_b64 = /Buffer\.from\(.+,\s*['"]base64['"]\s*\)/
$buffer_alloc_b64 = /Buffer\.alloc\(.+,.+,\s*['"]base64['"]\s*\)/
$unescape = /unescape\s*\(/
$decode_uri = /decodeURIComponent\s*\(/
$b64_blob = /[A-Za-z0-9+\/]{60,}=/
condition:
any of them
}
rule js_massive_string: alert {
strings:
$massive = /("(?:[^"\\\r\n]|\\.){256,}")|('(?:[^'\\\r\n]|\\.){256,}')/
condition:
any of them
}
rule js_node_child_process: alert {
strings:
$require_cp = /require\s*\(\s*['"]child_process['"]\s*\)/
$exec = /\bexecSync\s*\(/
$spawn = /\bspawnSync?\s*\(/
$execfile = /\bexecFileSync?\s*\(/
condition:
any of them
}
rule js_node_fs: alert {
strings:
$require_fs = /require\s*\(\s*['"]fs['"]\s*\)/
$write_file = /\bwriteFileSync?\s*\(/
$read_file = /\breadFileSync?\s*\(/
$unlink = /\bunlinkSync?\s*\(/
condition:
any of them
}
rule js_node_net_raw: alert {
strings:
$require_net = /require\s*\(\s*['"]net['"]\s*\)/
$createconn = /\bnet\.createConnection\s*\(/
condition:
any of them
}
rule js_windows_shell_cmd: alert {
strings:
$powershell = "powershell" nocase
$cmd_exe = "cmd.exe" nocase
$mshta = "mshta" nocase
$rundll32 = "rundll32" nocase
$regsvr32 = "regsvr32" nocase
$wscript_exe = "wscript.exe" nocase
$cscript_exe = "cscript.exe" nocase
condition:
any of them
}
rule js_reverse_shell_indicators: alert {
strings:
$socket_pipe = /\.pipe\s*\(\s*sock/
$stdin_socket = /process\.stdin\.pipe/
$proc_stdout = /process\.stdout\.pipe/
condition:
2 of them
}
rule js_char_escape: alert {
strings:
// \xXX
// $hex_escape = /((\\x[0-9a-fA-F]{2})\s*){4,}/
// \uXXXX or \u{XX...X} the second one can have between 1 and inf hex chars
// $unicode_escape = /(((\\u[0-9a-fA-F]{4})|(\\u\{[0-9a-fA-F]+\}))\s*){3,}/
$mixed_escape = /((\\u[0-9a-fA-F]{4})|(\\u\{[0-9a-fA-F]+\})|((\\x[0-9a-fA-F]{2})\s*)){4,}/
condition:
any of them
}
rule js_charat_in_a_for: alert {
strings:
$charat_for = /for\s*\(.*\)\s*\{[^}]*\.charAt\s*\(/
condition:
any of them
}
rule js_dynamic_funcname_via_bracket: alert {
strings:
// .substr(0, <variable>) extracting a substring of computed length
$substr_var = /\.substr\s*\(\s*0\s*,\s*[A-Za-z_$][A-Za-z0-9_$]*\s*\)/
// var x = SomeObj[decoded_var] bracket property lookup on a non-array
$bracket_dyn = /var\s+\w+\s*=\s*[A-Za-z_$][A-Za-z0-9_$]*\s*\[\s*[A-Za-z_$][A-Za-z0-9_$]+\s*\]/
// p.join('') reassembling shuffled char array
$join_empty = /\.join\s*\(\s*['"]{2}\s*\)/
condition:
$substr_var and $bracket_dyn and $join_empty
}
rule js_javascript_obfuscator_com_or_suspicious_str_operations: alert {
strings:
$charat_populate = /\[\s*\w+\s*\]\s*=\s*\w+\.charAt\s*\(\s*\w+\s*\)/ // p[w] = e.charAt(w)
$swap_pair = /\[\s*\w+\s*\]\s*=\s*\w+\s*\[\s*\w+\s*\]\s*;[^;]{0,40}\[\s*\w+\s*\]\s*=\s*\w+\s*;/ // p[t]=p[i]; p[i]=k
$join_rebuild = /\.join\s*\(\s*['"]{2}\s*\)/ // .join('')
$substr_zero = /\.substr\s*\(\s*0\s*,/ // .substr(0,
$bracket_lookup = /=\s*[A-Za-z_$]\w*\s*\[\s*[A-Za-z_$]\w+\s*\]/ // = obj[varname]
condition:
$charat_populate and $swap_pair and $join_rebuild and ($substr_zero or $bracket_lookup)
}
// https://obfuscator.io/legacy-playground (the most used)
rule js_obfuscator_io: alert {
strings:
$obfuscated_name = "_0x"
$self_defending = "(((.+)+)+)+$"
$disable_console_error = /\,\s*\'error\'\s*\,/
$disable_console_warn = /\,\s*\'warn\'\s*\,/
$disable_console_trace = /\,\s*\'trace\'\s*\,/
$disable_console_info = /\,\s*\'info\'\s*\,/
condition:
#obfuscated_name > 10 or
#self_defending > 0 or
// disable console
(#disable_console_error > 0 and #disable_console_warn > 0 and #disable_console_trace > 0 and #disable_console_info > 0)
}
// https://obfuscate.js.org
rule js_obfuscate_js_org: alert {
strings:
$dec_payload_colon_splitted = /(\d+\:){100}/
condition:
any of them
}
// https://www.freejsobfuscator.com (be aware of what you obfuscate, this is closed source and everything is sent to a server)
rule js_free_js_obfuscator_com: alert {
strings:
$illogic_operations = "+!-~~[]"
condition:
any of them
}
rule js_jsfuck : alert {
strings:
$jsfuck = /(?:[\(\)\[\]\+!]\s*){20,}/
condition:
any of them
}
rule js_windows_persistence: alert {
strings:
$run_key = /Software\\\\?Microsoft\\\\?Windows\\\\?CurrentVersion\\\\?Run/ nocase
$hkcu = "HKCU\\" nocase
$hklm = "HKLM\\" nocase
$schtasks = "schtasks" nocase
$reg_add = /\breg(\.exe)?\s+add\b/ nocase
$startup_dir = "\\Start Menu\\Programs\\Startup" nocase
$wmi_event = "__EventFilter" nocase // WMI persistence
condition:
any of them
}
rule js_defender_amsi_evasion: alert {
strings:
$amsi_buffer = "AmsiScanBuffer" nocase
$amsi_utils = "AmsiUtils" nocase
$amsi_dll = "amsi.dll" nocase
$mp_pref = "Set-MpPreference" nocase
$disable_rtmon = "DisableRealtimeMonitoring" nocase
$add_preference = "Add-MpPreference" nocase
$set_preference = "Set-MpPreference" nocase
condition:
any of them
}
// useless ?
rule js_common_exfil_endpoints: alert {
strings:
$discord_wh = /discord(app)?\.com\/api/ nocase
$telegram_api = "api.telegram.org" nocase
$pastebin_raw = "pastebin.com/raw" nocase
$gh_raw = "raw.githubusercontent.com"
$ipify = "api.ipify.org"
$ngrok = ".ngrok.io" nocase
condition:
any of them
}
rule js_stealer_paths: alert {
strings:
$chrome_userdata = /Google\\\\?Chrome\\\\?User Data/ nocase
$login_data = "Login Data" nocase
$local_state = "Local State" nocase
$cookies_db = "\\\\Cookies" nocase
$ff_profiles = /Mozilla\\\\?Firefox\\\\?Profiles/ nocase
$edge_userdata = /Edge\\\\?User Data/ nocase
condition:
any of them
}
rule js_suspicious_operations: alert {
strings:
$nonsense = /((\[\]|\'\'|\"\")\s*[\-*\/~])|([+\-*\/~!]\s*(\[\]|\'\'|\"\"))/
$xor = "^="
$boolnotnot = "!!"
$bitwisenotnot = "~~"
condition:
#nonsense + #xor + #boolnotnot + #bitwisenotnot >= 20
}
rule js_many_string_concat: alert {
strings:
$concat = /['"]\s*\+\s*['"]/
condition:
#concat >= 30
}
rule js_many_typeof: alert {
strings:
$typeof = "typeof"
condition:
#typeof >= 5
}
rule js_many_non_decimal_number: alert {
strings:
$bin = /0b[01]+/ nocase
$oct = /0o[0-7]+/ nocase
$hex = /0x[0-9a-f]+/ nocase
condition:
#bin + #oct + #hex >= 25
}
// https://jamtg.github.io/aaencode-and-aadecode/
rule js_aaencode: alert {
strings:
// jj version
$aaencode0 = "゚ω゚"
$aaencode1 = "┻━┻"
$aaencode2 = "o^_^o"
$aaencode3 = "゚Θ゚"
$aaencode4 = "゚Д゚"
// $ version
$aaencode5 = "$$$"
$aaencode6 = "(![]+\"\")[$]"
$aaencode7 = "(!\"\"+\"\")[$]"
$aaencode8 = "++$"
$aaencode9 = "$$__"
condition:
#aaencode0 + #aaencode1 + #aaencode2 + #aaencode3 + #aaencode4 + #aaencode5 + #aaencode6 + #aaencode7 + #aaencode8 + #aaencode9 >= 20
}