Skip to content

Commit f6569b2

Browse files
authored
Bump yara-x to 1.3.0; refactor slow rules to account for MAX_ATOMS_PER_REGEXP increase (#1030)
* Bump yara-x to 1.3.0 Signed-off-by: egibs <20933572+egibs@users.noreply.github.com> * Consolidate and refactor slow rules Signed-off-by: egibs <20933572+egibs@users.noreply.github.com> --------- Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
1 parent 956afc1 commit f6569b2

29 files changed

Lines changed: 153 additions & 167 deletions

.github/workflows/codeql.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
fetch-tags: true
3737
repository: virusTotal/yara-x
3838
path: yara-x
39-
ref: refs/tags/v1.2.1
39+
ref: refs/tags/v1.3.0
4040
- name: Install Rust for yara-x-capi
4141
uses: dtolnay/rust-toolchain@b3b07ba8b418998c39fb20f53e8b695cdcc8de1b
4242
with:

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
SAMPLES_REPO ?= chainguard-dev/malcontent-samples
66
SAMPLES_COMMIT ?= f948cfd0f9d2a35a2452fe43ea4d094979652103
77
YARA_X_REPO ?= virusTotal/yara-x
8-
YARA_X_COMMIT ?= 02d649bd1ff35789757a515d0fd3bbdfaf411ef3
8+
YARA_X_COMMIT ?= ad1a45957ca12397b1ebe9052ce4b50b3b55f518
99

1010
# BEGIN: lint-install ../malcontent
1111
# http://github.com/tinkerbell/lint-install
@@ -52,17 +52,17 @@ $(GOLANGCI_LINT_BIN):
5252
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LINT_ROOT)/out/linters $(GOLANGCI_LINT_VERSION)
5353
mv $(LINT_ROOT)/out/linters/golangci-lint $@
5454

55-
YARA_X_VERSION ?= v1.2.1
55+
YARA_X_VERSION ?= v1.3.0
5656
YARA_X_SHA :=
5757
ifeq ($(LINT_OS),Darwin)
5858
ifeq ($(shell uname -m),arm64)
5959
LINT_ARCH = aarch64
60-
YARA_X_SHA = b85ae01e5d16f99f84613e688a05986a56b5c849148895a74ee80115cb6acdad
60+
YARA_X_SHA = 4486718b3ef6e63192a8a18a171e49bdd48e9870053c5cab5cc799c7c48579b4
6161
else
62-
YARA_X_SHA = f4fb8a75af3a82a7377758d6dc09c2d46c230d26d83991a4c27e93c17dae78e9
62+
YARA_X_SHA = d7617bd8a7b5e1f1ed6d3d82474958bd429a0f4dcebc5d05cf3be8e95d48098c
6363
endif
6464
else
65-
YARA_X_SHA = 8f018934fe80a5428bca0fcb4778e188210e77f03b1507bbbfb4b1e30af3051f
65+
YARA_X_SHA = 26b11fc4390e49752e069c6d2703a46b5c68aac8f5b2a2a81117a5d7705e6813
6666
endif
6767
YARA_X_BIN := $(LINT_ROOT)/out/linters/yr-$(YARA_X_VERSION)-$(LINT_ARCH)
6868
$(YARA_X_BIN):

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ Requirements:
123123
* [pkgconf](http://pkgconf.org/) - required by Go to find C dependencies, included in many UNIX distributions
124124
* [libssl-dev](https://packages.debian.org/buster/libssl-dev) package
125125

126-
To install yara-x, first install Rust and then run `make install-yara-x` which will clone the yara-x repository and install yara-x's dependenicies and its C API.
126+
To install yara-x, first install Rust and then run `make install-yara-x` which will clone the yara-x repository and install yara-x's dependencies and its C API.
127127

128128
### Building locally in Debian/Ubuntu
129129

@@ -132,11 +132,11 @@ To install yara-x, first install Rust and then run `make install-yara-x` which w
132132
```bash
133133
sudo apt-get install -y pkgconf libssl-dev
134134
```
135-
135+
136136
Make sure [Go](https://go.dev/doc/install) and [Rust](https://www.rust-lang.org/tools/install) are installed
137137

138138
2. Run `make install-yara-x` to build the yara-x C API. (The
139-
`yara_xcapi.pc` file will be generated under `./out/lib/pkgconfig`.
139+
`yara_xcapi.pc` file will be generated under `./out/lib/pkgconfig`.
140140
For more information about the yara-x C API, reference the documentation here: https://virustotal.github.io/yara-x/docs/api/c/c-/#building-the-c-library.).
141141

142142
3. Build the malcontent binary with:

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.24.0
55
toolchain go1.24.1
66

77
require (
8-
github.com/VirusTotal/yara-x/go v1.2.1
8+
github.com/VirusTotal/yara-x/go v1.3.0
99
github.com/agext/levenshtein v1.2.3
1010
github.com/cavaliergopher/cpio v1.0.1
1111
github.com/cavaliergopher/rpm v1.3.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/VirusTotal/yara-x/go v1.2.1 h1:eOFTHXW7GKEQ7JfvJ6XzMMYcAMDg9FqcpJBSV1EIioQ=
2-
github.com/VirusTotal/yara-x/go v1.2.1/go.mod h1:lgXP/nkYX349MVowrtTtU5hzMdCOWQLv3+wKll9+0F8=
1+
github.com/VirusTotal/yara-x/go v1.3.0 h1:A2KXaJDC4ktRc6FHn45onmFE++n9hwz4iW/5cRae3UA=
2+
github.com/VirusTotal/yara-x/go v1.3.0/go.mod h1:lgXP/nkYX349MVowrtTtU5hzMdCOWQLv3+wKll9+0F8=
33
github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=
44
github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
55
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=

rules/anti-static/obfuscation/js.yara

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -340,40 +340,43 @@ rule high_entropy_charAt: medium {
340340

341341
rule charAt_long_string: medium {
342342
meta:
343-
description = "uses charAt/substr/join loops with a long variable"
343+
description = "charAt/substr operations with long strings"
344344
filetypes = "js,ts"
345345

346346
strings:
347-
$s_charAt = "charAt("
348-
$s_substr = "substr("
349-
$s_join = "join("
350-
$s_function = /function\s{0,2}\(/
351-
$s_for = /for\s{0,2}\(/
347+
$charAt = "charAt("
348+
$substr = "substr("
349+
$join = "join("
350+
$func = "function"
351+
$for = "for"
352352
353-
$long_string = /\([\'\"]\w{32,1024}[\"\']\)/
354-
$long_garbage = /['"][\w\~\!\@\#\$\%\^\&\*\(\)\{\}\?\+\/\/\=\-\;\[\]\.><\,\`\'\"_\\:]{16,256}[\s\%\$]{1,2}[\w\~\!\@\#\$\%\^\&\*\(\)\{\}\?\+\/\/\=\-\;\[\]\.><\,\`\'\"_\\:]{0,256}/
353+
$long1 = /["'][a-zA-Z0-9]{32,}["']/
354+
$long2 = /["']\w{50,}["']/
355355
356356
condition:
357-
all of ($s*) and any of ($long*)
357+
2 of ($charAt, $substr, $join) and
358+
$func and $for and
359+
any of ($long*)
358360
}
359361

360-
rule charAt_long_vars: medium {
362+
rule charAt_multiple_suspicious: medium {
361363
meta:
362-
description = "uses charAt/substr/join loops with long variables"
364+
description = "Multiple suspicious string patterns with charAt operations"
363365
filetypes = "js,ts"
364366

365367
strings:
366-
$s_charAt = "charAt("
367-
$s_substr = "substr("
368-
$s_join = "join("
369-
$s_function = /function\s{0,2}\(/
370-
$s_for = /for\s{0,2}\(/
368+
$charAt = "charAt("
369+
$substr = "substr("
370+
$join = "join("
371371
372-
$long_string = /\([\'\"]\w{32,1024}[\"\']\)/
373-
$long_garbage = /['"][\w\~\!\@\#\$\%\^\&\*\(\)\{\}\?\+\/\/\=\-\;\[\]\.><\,\`\'\"_\\:]{16,256}[\s\%\$]{1,2}[\w\~\!\@\#\$\%\^\&\*\(\)\{\}\?\+\/\/\=\-\;\[\]\.><\,\`\'\"_\\:]{0,256}/
372+
$susp1 = /["'][a-zA-Z0-9]{32,}["']/
373+
$susp2 = /["'][!@#$%^&*(){}\[\]]{8,}["']/
374+
$susp3 = /["'][0-9a-fA-F]{32,}["']/
375+
$susp4 = /["'][a-zA-Z0-9+\/=]{50,}["']/
374376
375377
condition:
376-
all of ($s*) and (#long_string + #long_garbage) > 3
378+
2 of ($charAt, $substr, $join) and
379+
#susp1 + #susp2 + #susp3 + #susp4 > 3
377380
}
378381

379382
rule obfuscated_require: high {

rules/anti-static/obfuscation/math.yara

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,46 @@ rule js_long_dumb_math: critical {
2424

2525
rule js_junk_math: medium {
2626
meta:
27-
description = "suspicious junk math"
28-
filetypes = "js,ts"
27+
description = "suspicious junk math operations with charAt"
28+
filetypes = "js,ts"
29+
severity_note = "1-2 patterns = medium, 3+ patterns = high"
2930

3031
strings:
31-
$charAt = "charAt"
32-
$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};/
33-
$m_var_int = /var\s{1,16}\w{0,16}\s{0,2}=\s{0,2}\d{3,16};/
34-
$m_paren_add = /\(\w{0,8}\s{0,2}\+\s{0,2}\d{1,16}\)/
35-
$m_paren_long_remainder = /\(\w{0,8}\s{0,2}%\s{0,2}\d{4,16}\)/
36-
$m_tiny_vars_long_remainder = /\w{0,2}\s{0,2}=\s{0,2}\(\w + \w\) % \d{4,16};/
32+
$charAt = "charAt"
33+
34+
$m_subtract = /\s\w{1,16}\s?=\s?\d{0,8}\s?-\s?\d{2,8};/
35+
$m_var_int = /var\s+\w{1,16}\s?=\s?\d{3,16};/
36+
$m_paren_add = /\(\w{1,8}\s?\+\s?\d{2,16}\)/
37+
$m_paren_rem = /\(\w{1,8}\s?%\s?\d{4,16}\)/
38+
$m_tiny_rem = /\w{1,2}\s?=\s?\(\w\s?\+\s?\w\)\s?%\s?\d{4,16};/
3739
3840
condition:
39-
$charAt and 2 of ($m*)
41+
$charAt and any of ($m*)
4042
}
4143

42-
rule js_junk_math_high: high {
44+
rule sketchy_math_conversions: medium {
4345
meta:
44-
description = "multiple examples of suspicious junk math"
46+
description = "complex math with parseInt or fromCharCode conversions"
4547
filetypes = "js,ts"
4648

4749
strings:
48-
$charAt = "charAt"
49-
$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};/
50-
$m_var_int = /var\s{1,16}\w{0,16}\s{0,2}=\s{0,2}\d{3,16};/
51-
$m_paren_add = /\(\w{0,8}\s{0,2}\+\s{0,2}\d{2,16}\)/
52-
$m_paren_long_remainder = /\(\w{0,8}\s{0,2}%\s{0,2}\d{4,16}\)/
53-
$m_tiny_vars_long_remainder = /\w{0,2}\s{0,2}=\s{0,2}\(\w + \w\) % \d{4,16};/
50+
$f_parseInt = "parseInt"
51+
$f_fromCharCode = "fromCharCode"
52+
53+
$math1 = /\d{2,16}[\+\-\*\/]\w{1,8}/
54+
$math2 = /\w{1,8}[\+\-\*\/]\d{2,16}/
55+
56+
$xor1 = /\d{2,16}\^\w{1,8}/
57+
$xor2 = /\w{1,8}\^\d{2,16}/
58+
59+
$complex_math = /[\(\[][\w\d\s\+\-\*\/\^]{10,50}[\)\]]/
5460
5561
condition:
56-
$charAt and 3 of ($m*)
62+
filesize < 1MB and
63+
($f_parseInt or $f_fromCharCode) and
64+
(
65+
(#math1 + #math2 > 5) or
66+
(#xor1 + #xor2 > 2) or
67+
#complex_math > 3
68+
)
5769
}

rules/anti-static/obfuscation/reverse.yara

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,22 @@ rule string_reversal: medium {
1010
any of them
1111
}
1212

13-
rule function_reversal: high {
13+
rule js_function_reversal: high {
1414
meta:
15-
description = "reversed function definition"
15+
description = "reversed javascript function calls"
1616
filetypes = "js,ts"
1717

1818
strings:
19-
$ref = /n.{0,3}o.{0,3}i.{0,3}t.{0,3}c.{0,3}n.{0,3}u.{0,3}f/
19+
$function_rev1 = "noitcnuf"
20+
$function_rev2 = { 6E 6F 69 74 63 6E 75 66 }
2021
21-
condition:
22-
filesize < 1MB and any of them
23-
}
24-
25-
rule js_reversal: high {
26-
meta:
27-
description = "multiple reversed javascript calls"
28-
filetypes = "js,ts"
29-
30-
strings:
31-
$ref = /n.{0,3}o.{0,3}i.{0,3}t.{0,3}c.{0,3}n.{0,3}u.{0,3}f/
32-
$ref2 = /n.{0,3}r.{0,3}u.{0,3}t.{0,3}e.{0,3}r/
22+
$function_dots = /no\.?i\.?t\.?c\.?n\.?u\.?f/
23+
$return_rev = "nruter"
24+
$return_dots = /nr\.?u\.?t\.?e\.?r/
3325
3426
condition:
35-
filesize < 1MB and all of them
27+
filesize < 1MB and (
28+
($function_rev1 or $function_rev2) and ($return_rev or $return_dots) or
29+
($function_dots and $return_dots)
30+
)
3631
}

rules/anti-static/obfuscation/strtoi.yara

Lines changed: 0 additions & 13 deletions
This file was deleted.

rules/anti-static/obfuscation/utf16.yara

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
rule sketchy_fromCharCode_math: medium {
2-
meta:
3-
description = "complex math and utf16 code unit conversion"
4-
filetypes = "js,ts"
5-
6-
strings:
7-
$m1 = /\d{2,16}[\-\+\*\^]\w{1,8}/
8-
$m2 = /\w{1,8}[\-\+\*\^]\d{2,16}/
9-
$f_fromCharCode = "fromCharCode"
10-
11-
condition:
12-
filesize < 1MB and any of ($f*) and ((#m1 > 5) or (#m2 > 5))
13-
}
14-
151
rule static_charcode_math: high {
162
meta:
173
description = "assembles strings from character codes and static integers"

0 commit comments

Comments
 (0)