forked from chainguard-dev/malcontent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve malicious Javascript detection (chainguard-dev#572)
* Improve malicious Javascript detection * update testdata * alert tuning to reduce false positives * update testdata
- Loading branch information
1 parent
1a9783b
commit 521a7e7
Showing
105 changed files
with
662 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
rule unsigned_bitwise_math: medium { | ||
meta: | ||
description = "uses unsigned bitwise math" | ||
ref = "https://www.reversinglabs.com/blog/python-downloader-highlights-noise-problem-in-open-source-threat-detection" | ||
filetypes = "javascript" | ||
|
||
strings: | ||
$function = "function(" | ||
$charAt = /charAt\([a-zA-Z]/ | ||
$left = /[a-z]\>\>\>\d{1,3}/ | ||
$right = /[a-z]\>\>\>\d{1,3}/ | ||
condition: | ||
filesize < 5MB and $function and $charAt and (#left > 5 or #right > 5) | ||
} | ||
|
||
rule unsigned_bitwise_math_excess: high { | ||
meta: | ||
description = "uses an excessive amount of unsigned bitwise math" | ||
ref = "https://www.reversinglabs.com/blog/python-downloader-highlights-noise-problem-in-open-source-threat-detection" | ||
filetypes = "javascript" | ||
|
||
strings: | ||
$function = "function(" | ||
$charAt = /charAt\([a-zA-Z]/ | ||
$left = /[a-z]\>\>\>\d{1,3}/ | ||
$right = /[a-z]\>\>\>\d{1,3}/ | ||
condition: | ||
filesize < 5MB and $function and $charAt and (#left > 50 or #right > 50) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
rule ebe: critical { | ||
meta: | ||
description = "highly obfuscated javascript (eBe)" | ||
filetypes = "javascript" | ||
|
||
strings: | ||
$function = "function(" | ||
$charCodeAt = "charCodeAt" | ||
$ref = /eBe\(-\d{1,3}\)/ | ||
condition: | ||
filesize < 5MB and $function and $charCodeAt and #ref > 10 | ||
} | ||
|
||
rule ebe_generic: high { | ||
meta: | ||
description = "highly obfuscated javascript" | ||
filetypes = "javascript" | ||
|
||
strings: | ||
$function = "function(" | ||
$charCodeAt = "charCodeAt" | ||
$ref = /\w\[\w{1,3}\(\d{1,3}\)\]=\w{1,3}\(\d{1,3}\),e\[\w{1,3}\(\d{1,3}\)\]/ | ||
$ref2 = /\w\[\w{1,3}\(\d{1,3}\)\]\&\w{1,3}\(\d{1,3}\)\),\w\[\w{1,3}\(\d{1,3}\)\]/ | ||
$ref3 = /\>\w{1,3}\(\d{1,3}\)\);\w\[\w{1,3}\(\d{1,3}\)\]\=/ | ||
condition: | ||
filesize < 5MB and #function and $charCodeAt and (#ref > 5 or #ref2 > 5 or #ref3 > 5) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
rule over_powered_arrays: high { | ||
meta: | ||
description = "uses many powered array elements (>25)" | ||
filetypes = "javascript" | ||
|
||
strings: | ||
$function = /function\(\w,/ | ||
$charAt = /charAt\([a-zA-Z]/ | ||
$power_array = /\w\[\d{1,4}\]\^\w\[\d{1,4}\]/ | ||
condition: | ||
filesize < 5MB and $function and $charAt and #power_array > 25 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,39 @@ | ||
rule server_addr: high { | ||
rule server_addr: medium { | ||
meta: | ||
description = "may execute a shell and communicate with a server" | ||
|
||
strings: | ||
$serverAddr = "serverAddr" | ||
$server_addr = "server_addr" | ||
$exec = "exec" | ||
$sh = "sh" fullword | ||
$sh_bash = "bash" fullword | ||
$sh_zsh = "zsh" fullword | ||
$sh_script = "ShellScript" | ||
$sh_exec = "ExecShell" | ||
$sh_cmd = "cmd.exe" | ||
$serverAddr = "serverAddr" | ||
$server_addr = "server_addr" | ||
$exec = "exec" | ||
$sh = "/bin/sh" fullword | ||
$sh_bash = "/bin/bash" fullword | ||
$sh_zsh = "/bin/zsh" fullword | ||
$sh_script = "ShellScript" | ||
$sh_exec = "ExecShell" | ||
$sh_cmd = "cmd.exe" | ||
$sh_powershell = "powershell.exe" | ||
condition: | ||
filesize < 10MB and any of ($server*) and $exec and any of ($sh*) | ||
} | ||
|
||
rule server_addr_small: high { | ||
meta: | ||
description = "may execute a shell and communicate with a server" | ||
|
||
strings: | ||
$serverAddr = "serverAddr" | ||
$server_addr = "server_addr" | ||
$exec = "exec" | ||
$sh = "/bin/sh" fullword | ||
$sh_bash = "/bin/bash" fullword | ||
$sh_zsh = "/bin/zsh" fullword | ||
$sh_script = "ShellScript" | ||
$sh_exec = "ExecShell" | ||
$sh_cmd = "cmd.exe" | ||
$sh_powershell = "powershell.exe" | ||
condition: | ||
filesize < 128KB and any of ($server*) and $exec and any of ($sh*) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
rule ethereum_c2: high { | ||
meta: | ||
description = "may use Ethereum to discover command and control server" | ||
|
||
strings: | ||
$axios = "axios" | ||
$ethers = /ethers\.Contract\('0x\w{8,64}\'/ | ||
$getstring = ".getString(" | ||
condition: | ||
filesize < 128KB and all of them | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
rule chmod_777_dropper: critical { | ||
meta: | ||
description = "transfers program, uses dangerous permissions, and possibly runs a binary" | ||
filetypes = "macho,elf" | ||
|
||
strings: | ||
$chmod = /chmod [\-\w ]{0,3}777 [ \$\@\w\/\.]{0,64}/ | ||
$t_wget = "wget" fullword | ||
$t_curl = "curl" fullword | ||
$t_tftp = "tftp" fullword | ||
$o_dotslash = /\.\/[\.\$\w]{0,16}/ | ||
$o_rm = /rm -[rR]{0,1}f/ | ||
$o_tmp = "/tmp/" | ||
$o_dev = "/dev/" | ||
condition: | ||
filesize < 1KB and $chmod and any of ($t*) and any of ($o*) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.