Skip to content

Commit

Permalink
Leverage yr scan --profile to tune slowest rules (#708)
Browse files Browse the repository at this point in the history
* Leverage yr scan --profile to tune slowest rules

Signed-off-by: egibs <[email protected]>

* Ignore compiled rules

Signed-off-by: egibs <[email protected]>

* Run make yara-x-fmt

Signed-off-by: egibs <[email protected]>

* Address PR comments

Signed-off-by: egibs <[email protected]>

* Merge b64decode + long_str strings

Signed-off-by: egibs <[email protected]>

* Run make yara-x-fmt

Signed-off-by: egibs <[email protected]>

---------

Signed-off-by: egibs <[email protected]>
  • Loading branch information
egibs authored Dec 16, 2024
1 parent e7e22d4 commit 3903332
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ profiles/

# Malcontent samples (obsolete)
samples/

# Compiled rules
*.yarc
25 changes: 12 additions & 13 deletions rules/anti-static/obfuscation/python.yara
Original file line number Diff line number Diff line change
Expand Up @@ -440,19 +440,18 @@ rule decompress_base64_entropy: high {
description = "hidden base64-encoded compressed content"

strings:
$k_lzma = "lzma"
$k_gzip = "gzip"
$k_zlib = "zlib"
$b64decode = "b64decode("
$f_bytes = "bytes("
$f_decode = "decode("
$f_decompress = "decompress("
$f_eval = "eval("
$f_exec = "exec("
$long_str = /[\'\"][\+\w\/]{96}/
condition:
filesize < 10MB and any of ($k*) and $b64decode and $long_str and any of ($f*)
$k_lzma = "lzma"
$k_gzip = "gzip"
$k_zlib = "zlib"
$f_bytes = "bytes("
$f_decode = "decode("
$f_decompress = "decompress("
$f_eval = "eval("
$f_exec = "exec("
$b64decode_long = /b64decode\(\"[\+\=\w\/]{96}/
condition:
filesize < 10MB and any of ($k*) and $b64decode_long and any of ($f*)
}

rule join: low {
Expand Down
5 changes: 2 additions & 3 deletions rules/c2/tool_transfer/download.yara
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ rule http_archive_url: medium {
description = "accesses hardcoded archive file endpoint"

strings:
$ref = /https*:\/\/[\w\.]{0,160}[:\/\w\_\-\?\@=]{6,160}\.(zip|tar|tgz|gz|xz)/ fullword
$ref = /https{0,1}:\/\/[\w\.]{0,160}[:\/\w\_\-\?\@=]{6,160}\.(zip|tar|tgz|gz|xz)/ fullword
$not_foo_bar = "http://foo/bar.tar"
condition:
Expand All @@ -93,10 +93,9 @@ rule http_archive_url_higher: high {
description = "accesses hardcoded archive file endpoint"

strings:
$ref = /https*:\/\/[\w\.]{0,160}[:\/\w\_\-\?\@=]{6,160}\.(zip|tar|tgz|gz|xz)/ fullword
$ref = /https{0,1}:\/\/[\w\.]{0,160}[:\/\w\_\-\?\@=]{6,160}\.(zip|tar|tgz|gz|xz)/ fullword
$not_foo_bar = "http://foo/bar.tar"
condition:
smallerBinary and any of ($ref*) and none of ($not*)
}

5 changes: 2 additions & 3 deletions rules/impact/degrade/app.yara
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ rule osascript_window_closer: medium {
$c_osascript = "osascript" fullword
$c_tell = "tell" fullword
$c_application = "application" fullword
$c_app_name = /\"\w[\.\w ]{0,24}\w\"/ fullword
$c_app_name = /\"\w[\.\w]{3,24}\w\"/ fullword

Check warning on line 9 in rules/impact/degrade/app.yara

View check run for this annotation

VirusTotal YARA-CI / Rules Analysis

rules/impact/degrade/app.yara#L9

rule "osascript_window_closer": string "$c_app_name" may slow down scanning
$c_to = "to" fullword
$c_close = "close" fullword
$c_window = "window" fullword
Expand All @@ -23,11 +23,10 @@ rule osascript_quitter: medium {
$c_osascript = "osascript" fullword
$c_tell = "tell" fullword
$c_application = "application" fullword
$c_app_name = /\"\w[\.\w ]{0,24}\w\"/ fullword
$c_app_name = /\"\w[\.\w]{3,24}\w\"/ fullword

Check warning on line 26 in rules/impact/degrade/app.yara

View check run for this annotation

VirusTotal YARA-CI / Rules Analysis

rules/impact/degrade/app.yara#L26

rule "osascript_quitter": string "$c_app_name" may slow down scanning
$c_to = "to" fullword
$c_quit = "quit" fullword
condition:
filesize < 256KB and all of ($c*)
}

0 comments on commit 3903332

Please sign in to comment.