Skip to content

Commit eadc9cc

Browse files
authored
Improve Javascript results, particularly for rand-user-agent (#925)
1 parent 46a3dd9 commit eadc9cc

147 files changed

Lines changed: 163 additions & 177 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

rules/anti-static/obfuscation/js.yara

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ private rule obfs_probably_js {
1212
$f_false = "false);"
1313
$f_function = /function\(\w{0,32}\)/
1414
$f_function2 = "function()"
15+
$f_function3 = "function ()"
16+
$f_global = "global["
1517
$f_method = "@method"
1618
$f_namespace = "@namespace"
1719
$f_Object = "Object."
@@ -48,6 +50,20 @@ private rule obfs_probably_js {
4850
filesize < 5MB and 4 of ($f*) and none of ($not*)
4951
}
5052

53+
rule js_var_misdirection: medium {
54+
meta:
55+
description = "multiple layers of variable misdirection"
56+
57+
strings:
58+
$short_mix_high = /var [a-z]{0,2}[A-Z]{1,2}[a-z]\w{1,2}\s{0,2}=\s{0,2}\w{0,2}[A-Z]\w{1,2}[\;\(\[]/
59+
$empty = /var [a-z]{1,3}[A-Z][a-z]{0,2}\s{0,2}=\s{0,2}"";/
60+
$short_mix_low = /var [a-z][A-Z]{1,6}\w{1,2}\s{0,2}=\s{0,2}\w{0,2}[A-Z]\w{1,2}[\;\(\[]/
61+
$short_low = /var [a-z]{1,3}\s{0,2}=\s{0,2}\w{0,2}[A-Z]\w{1,2}[\;\(\[]/
62+
63+
condition:
64+
obfs_probably_js and filesize < 4MB and 3 of them
65+
}
66+
5167
rule character_obfuscation: medium {
5268
meta:
5369
description = "obfuscated javascript that relies on character manipulation"
@@ -344,11 +360,59 @@ rule high_entropy_charAt: medium {
344360
description = "high entropy javascript (>5.37) that uses charAt/substr/join loops"
345361

346362
strings:
347-
$ = "charAt("
348-
$ = "substr("
349-
$ = "join("
350-
$ = "function("
351-
$ = "for("
363+
$ = "charAt("
364+
$ = "substr("
365+
$ = "join("
366+
$s_function = /function\s{0,2}\(/
367+
$s_for = /for\s{0,2}\(/
368+
369+
condition:
370+
obfs_probably_js and math.entropy(1, filesize) >= 5.37 and all of them
371+
}
372+
373+
rule charAt_long_string: medium {
374+
meta:
375+
description = "uses charAt/substr/join loops with a long variable"
376+
377+
strings:
378+
$s_charAt = "charAt("
379+
$s_substr = "substr("
380+
$s_join = "join("
381+
$s_function = /function\s{0,2}\(/
382+
$s_for = /for\s{0,2}\(/
383+
384+
$long_string = /\([\'\"]\w{32,1024}[\"\']\)/
385+
$long_garbage = /['"][\w\~\!\@\#\$\%\^\&\*\(\)\{\}\?\+\/\/\=\-\;\[\]\.><\,\`\'\"_\\:]{16,256}[\s\%\$]{1,2}[\w\~\!\@\#\$\%\^\&\*\(\)\{\}\?\+\/\/\=\-\;\[\]\.><\,\`\'\"_\\:]{0,256}/
386+
387+
condition:
388+
obfs_probably_js and all of ($s*) and any of ($long*)
389+
}
390+
391+
rule charAt_long_vars: medium {
392+
meta:
393+
description = "uses charAt/substr/join loops with long variables"
394+
395+
strings:
396+
$s_charAt = "charAt("
397+
$s_substr = "substr("
398+
$s_join = "join("
399+
$s_function = /function\s{0,2}\(/
400+
$s_for = /for\s{0,2}\(/
401+
402+
$long_string = /\([\'\"]\w{32,1024}[\"\']\)/
403+
$long_garbage = /['"][\w\~\!\@\#\$\%\^\&\*\(\)\{\}\?\+\/\/\=\-\;\[\]\.><\,\`\'\"_\\:]{16,256}[\s\%\$]{1,2}[\w\~\!\@\#\$\%\^\&\*\(\)\{\}\?\+\/\/\=\-\;\[\]\.><\,\`\'\"_\\:]{0,256}/
404+
405+
condition:
406+
obfs_probably_js and all of ($s*) and (#long_string + #long_garbage) > 3
407+
}
408+
409+
rule obfuscated_require: high {
410+
meta:
411+
description = "sets variable to the 'require' keyword"
412+
413+
strings:
414+
$ = /global\[\"\w{1,16}\"\]\s{0,2}=\s{0,2}require;/
415+
$ = /var \w{1,16}\s{0,2}=\s{0,2}require;/
352416
353417
condition:
354418
obfs_probably_js and math.entropy(1, filesize) >= 5.37 and all of them
Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,66 @@
1-
rule js_long_math: high {
2-
meta:
3-
description = "performs multiple rounds of long integer math"
4-
1+
private rule math_probably_js {
52
strings:
63
$f_function = "function"
74
$f_return = "return"
85
$f_local = "local"
6+
$f_var = "var" fullword
7+
$f_global = "global["
98
$f_end = "end" fullword
109
10+
condition:
11+
filesize < 5MB and 3 of ($f*)
12+
}
13+
14+
rule js_long_math: high {
15+
meta:
16+
description = "performs multiple rounds of long integer math"
17+
18+
strings:
1119
$d = /\d{6,14}[\+\-]\d{6,14}/ fullword
1220
1321
condition:
14-
3 of ($f*) and #d > 64
22+
math_probably_js and #d > 64
1523
}
1624

1725
rule js_long_dumb_math: critical {
1826
meta:
1927
description = "performs multiple rounds of long dumb integer math"
2028

2129
strings:
22-
$f_function = "function"
23-
$f_return = "return"
24-
$f_local = "local"
25-
$f_end = "end" fullword
26-
2730
$d = /[-\+]\([-\+]\d{6,14}[-\+]\([-\+]\d{6,14}\)\)/
2831
2932
condition:
30-
2 of ($f*) and #d > 32
33+
math_probably_js and #d > 32
34+
}
35+
36+
rule js_junk_math: medium {
37+
meta:
38+
description = "suspicious junk math"
39+
40+
strings:
41+
$charAt = "charAt"
42+
$m_subtract_var = /\s\w{1,16}\s{0,2}=\s{0,2}\d{0,8}\s{0,2}-\s{0,2}\d{1,8};/
43+
$m_var_int = /var\s{1,16}\w{0,16}\s{0,2}=\s{0,2}\d{3,16};/
44+
$m_paren_add = /\(\w{0,8}\s{0,2}\+\s{0,2}\d{1,16}\)/
45+
$m_paren_long_remainder = /\(\w{0,8}\s{0,2}%\s{0,2}\d{4,16}\)/
46+
$m_tiny_vars_long_remainder = /\w{0,2}\s{0,2}=\s{0,2}\(\w + \w\) % \d{4,16};/
47+
48+
condition:
49+
math_probably_js and $charAt and 2 of ($m*)
50+
}
51+
52+
rule js_junk_math_high: high {
53+
meta:
54+
description = "multiple examples of suspicious junk math"
55+
56+
strings:
57+
$charAt = "charAt"
58+
$m_subtract_var = /\s\w{1,16}\s{0,2}=\s{0,2}\d{0,8}\s{0,2}-\s{0,2}\d{2,8};/
59+
$m_var_int = /var\s{1,16}\w{0,16}\s{0,2}=\s{0,2}\d{3,16};/
60+
$m_paren_add = /\(\w{0,8}\s{0,2}\+\s{0,2}\d{2,16}\)/
61+
$m_paren_long_remainder = /\(\w{0,8}\s{0,2}%\s{0,2}\d{4,16}\)/
62+
$m_tiny_vars_long_remainder = /\w{0,2}\s{0,2}=\s{0,2}\(\w + \w\) % \d{4,16};/
63+
64+
condition:
65+
math_probably_js and $charAt and 3 of ($m*)
3166
}

rules/anti-static/obfuscation/python.yara

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ rule py_lib_alias_val: medium {
253253
$val
254254
}
255255

256-
rule multi_decode_3: high {
256+
rule multi_decode_3: medium {
257257
meta:
258258
description = "multiple (3+) levels of decoding"
259259
filetypes = "py"
@@ -266,6 +266,19 @@ rule multi_decode_3: high {
266266
obfs_probably_python and filesize < 10MB and all of them
267267
}
268268

269+
rule multi_decode_3_smaller_file: high {
270+
meta:
271+
description = "multiple (3+) levels of decoding"
272+
filetypes = "py"
273+
274+
strings:
275+
$return = "return"
276+
$decode_or_b64decode = /\.[b64]{0,3}decode\(.{0,256}\.[b64]{0,3}decode\(.{0,256}\.[b64]{0,3}decode/
277+
278+
condition:
279+
obfs_probably_python and filesize < 256KB and all of them
280+
}
281+
269282
rule multi_decode: medium {
270283
meta:
271284
description = "multiple (2) levels of decoding"

rules/c2/addr/url.yara

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ rule http_url_with_question: medium {
7373
$not_doku = "/doku.php?"
7474
7575
condition:
76-
filesize < 256KB and any of them
77-
// ($f*) and $ref and none of ($not*)
76+
filesize < 256KB and any of ($f*) and $ref and none of ($not*)
7877
}
7978

8079
rule binary_with_url: low {

rules/exec/remote_commands/code_eval.yara

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ private rule eval_probably_js {
1212
$f_false = "false);"
1313
$f_function = /function\(\w{0,32}\)/
1414
$f_function2 = "function()"
15+
$f_function3 = "function ()"
16+
$f_global = "global["
1517
$f_method = "@method"
1618
$f_namespace = "@namespace"
1719
$f_Object = "Object."
@@ -133,6 +135,18 @@ rule js_eval_obfuscated_fromChar: critical {
133135
eval_probably_js and filesize < 5MB and all of them and math.abs(@exec - @ref) > 384
134136
}
135137

138+
rule js_anonymous_function: medium {
139+
meta:
140+
description = "evaluates code using an anonymous function"
141+
142+
strings:
143+
$func = /\n\s{0,8}\(function\s{0,8}\(\)\s{0,8}\{/
144+
$run = /\n\s{0,8}\}\)\(\);/
145+
146+
condition:
147+
eval_probably_js and filesize < 5MB and all of them and (@run - @func) > 384
148+
}
149+
136150
rule python_exec: medium {
137151
meta:
138152
description = "evaluate code dynamically using exec()"

tests/c/clean/falco/string_visitor.ut.cpp.simple

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# c/clean/falco/string_visitor.ut.cpp: medium
2-
c2/addr/url: medium
32
credential/shell/bash_history: medium
43
fs/path/etc: low
54
fs/path/var: low

tests/c/clean/ruby_http_parser/test.c.simple

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# c/clean/ruby_http_parser/test.c: medium
2-
c2/addr/url: medium
32
c2/tool_transfer/os: low
43
crypto/openssl: medium
54
data/compression/gzip: low
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
# does-nothing/does-nothing.go: medium
2-
c2/addr/url: medium

tests/javascript/2022.an-instance.99.10.9/index.js.simple

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# javascript/2022.an-instance.99.10.9/index.js: critical
22
anti-static/obfuscation/hex: medium
3-
c2/addr/url: medium
43
data/encoding/int: low
54
data/encoding/json_encode: low
65
discover/network/interface_list: medium

0 commit comments

Comments
 (0)