Skip to content

Commit

Permalink
Merge pull request #42 from tstromberg/main
Browse files Browse the repository at this point in the history
Improve PHP/Python/NodeJS rules through BSKC analysis
  • Loading branch information
tstromberg authored Mar 9, 2024
2 parents c9f8d7a + d9a130d commit 0450e12
Show file tree
Hide file tree
Showing 41 changed files with 314 additions and 52 deletions.
10 changes: 10 additions & 0 deletions rules/admin/shutdown.yara
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

rule shutdown_s : suspicious {
meta:
description = "calls shutdown command"
strings:
$ref = /shutdown -[\w ]{0,16}/
$ref2 = "shutdown now"
condition:
any of them
}
2 changes: 1 addition & 1 deletion rules/archives/zip.yara
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

rule zip : notable {
meta:
description = "Works with zip files"
Expand All @@ -7,6 +6,7 @@ rule zip : notable {
$ref2 = "archive/zip"
$ref3 = "zip_writer" fullword
$ref4 = "ZIP archive" fullword
$ref5 = "zip file" fullword
condition:
any of them
}
34 changes: 17 additions & 17 deletions rules/combo/backdoor/generic/php.yara
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

rule php_possible_backdoor {
rule php_possible_backdoor : critical {
meta:
hash_2020_trojan_webshell_quwmldl_rfxn = "f1375cf097b3f28247762147f8ee3755e0ce26e24fbf8a785fe4e5b42c1fed05"
hash_2023_PHP_Backdoor_PHP_Goonshell_a = "42e5fafe25af2d2600691a26144cc47320ccfd07a224b72452dfa7de2e86ece3"
Expand Down Expand Up @@ -28,7 +28,7 @@ rule php_possible_backdoor {
filesize < 1048576 and $eval and 1 of ($php*) and 4 of ($f_*) and none of ($not*)
}

rule php_eval_base64_decode {
rule php_eval_base64_decode : critical {
meta:
hash_2023_0xShell = "acf556b26bb0eb193e68a3863662d9707cbf827d84c34fbc8c19d09b8ea811a1"
hash_2023_0xShell_0xObs = "6391e05c8afc30de1e7980dda872547620754ce55c36da15d4aefae2648a36e5"
Expand All @@ -44,7 +44,7 @@ rule php_eval_base64_decode {
any of them
}

rule php_executor {
rule php_executor : critical {
meta:
hash_2020_trojan_webshell_quwmldl_rfxn = "f1375cf097b3f28247762147f8ee3755e0ce26e24fbf8a785fe4e5b42c1fed05"
hash_2015_Resources_agent = "5a61246c9fe8e52347e35664e0c86ab2897d807792008680e04306e6c2104941"
Expand All @@ -62,7 +62,7 @@ rule php_executor {
filesize < 1048576 and $php and all of ($f_*)
}

rule php_bin_hashbang {
rule php_bin_hashbang : critical {
meta:
hash_2015_Resources_agent = "5a61246c9fe8e52347e35664e0c86ab2897d807792008680e04306e6c2104941"
hash_2023_UPX_0a07c056fec72668d3f05863f103987cc1aaec92e72148bf16db6cfd58308617_elf_x86_64 = "94f4de1bd8c85b8f820bab936ec16cdb7f7bc19fa60d46ea8106cada4acc79a2"
Expand All @@ -73,7 +73,7 @@ rule php_bin_hashbang {
$script and any of ($x*)
}

rule php_urlvar_recon_exec {
rule php_urlvar_recon_exec : critical {
meta:
ref = "Backdoor.PHP.Llama"
hash_2023_PHP_Backdoor_PHP_Goonshell_a = "42e5fafe25af2d2600691a26144cc47320ccfd07a224b72452dfa7de2e86ece3"
Expand Down Expand Up @@ -105,7 +105,7 @@ rule php_system_to_perl {
all of them
}

rule php_eval_gzinflate_base64_backdoor {
rule php_eval_gzinflate_base64_backdoor : critical {
meta:
ref = "xoxo"
hash_2023_0xShell_lndex = "9b073472cac7f3f8274165a575e96cfb4f4eb38471f6a8e57bb9789f3f307495"
Expand All @@ -120,7 +120,7 @@ rule php_eval_gzinflate_base64_backdoor {
}


rule php_obfuscated_with_hex_characters {
rule php_obfuscated_with_hex_characters : critical {
meta:
hash_2023_0xShell_1337 = "657bd1f3e53993cb7d600bfcd1a616c12ed3e69fa71a451061b562e5b9316649"
hash_2023_0xShell_index = "f39b16ebb3809944722d4d7674dedf627210f1fa13ca0969337b1c0dcb388603"
Expand All @@ -138,7 +138,7 @@ rule php_obfuscated_with_hex_characters {
$php and (#hex > 5 or #hex_not_mix > 5)
}

rule php_base64_eval_uname {
rule php_base64_eval_uname : critical {
meta:
hash_2023_0xShell_root = "3baa3bfaa6ed78e853828f147c3747d818590faee5eecef67748209dd3d92afb"
hash_2023_0xShell_wesoori = "bab1040a9e569d7bf693ac907948a09323c5f7e7005012f7b75b5c1b2ced10ad"
Expand All @@ -150,7 +150,7 @@ rule php_base64_eval_uname {
all of them
}

rule php_post_system {
rule php_post_system : suspicious {
meta:
hash_2023_0xShell_0xShellori = "506e12e4ce1359ffab46038c4bf83d3ab443b7c5db0d5c8f3ad05340cb09c38e"
hash_2023_0xShell_root = "3baa3bfaa6ed78e853828f147c3747d818590faee5eecef67748209dd3d92afb"
Expand All @@ -167,7 +167,7 @@ rule php_post_system {
$php and any of ($method*) and $system
}

rule php_error_reporting_disable {
rule php_error_reporting_disable : suspicious {
meta:
hash_2023_0xShell_0xShellori = "506e12e4ce1359ffab46038c4bf83d3ab443b7c5db0d5c8f3ad05340cb09c38e"
hash_2023_0xShell_untitled = "39b2fd6b4b2c11a9cbfc8efbb09fc14d502cde1344f52e1269228fc95b938621"
Expand All @@ -180,7 +180,7 @@ rule php_error_reporting_disable {
all of them
}

rule php_system_manipulation {
rule php_system_manipulation : suspicious {
meta:
hash_2023_0xShell_0xShellori = "506e12e4ce1359ffab46038c4bf83d3ab443b7c5db0d5c8f3ad05340cb09c38e"
hash_2023_0xShell_untitled = "39b2fd6b4b2c11a9cbfc8efbb09fc14d502cde1344f52e1269228fc95b938621"
Expand All @@ -198,7 +198,7 @@ rule php_system_manipulation {
$php and 80% of them
}

rule php_system_hex {
rule php_system_hex : critical {
meta:
hash_2023_0xShell_root = "3baa3bfaa6ed78e853828f147c3747d818590faee5eecef67748209dd3d92afb"
hash_2023_0xShell_untitled = "39b2fd6b4b2c11a9cbfc8efbb09fc14d502cde1344f52e1269228fc95b938621"
Expand All @@ -208,7 +208,7 @@ rule php_system_hex {
any of them
}

rule php_insecure_curl_uploader {
rule php_insecure_curl_uploader : critical {
meta:
hash_2023_0xShell_0xShellori = "506e12e4ce1359ffab46038c4bf83d3ab443b7c5db0d5c8f3ad05340cb09c38e"
hash_2023_0xShell_f = "9ce3da0322ee42e9119abb140b829efc3c94ea802df7a6f3968829645e1a5330"
Expand All @@ -221,7 +221,7 @@ rule php_insecure_curl_uploader {
$CURLOPT_SSL_VERIFYPEER and any of ($f*)
}

rule php_eval_get_contents {
rule php_eval_get_contents : critical {
meta:
hash_2023_0xShell_f = "9ce3da0322ee42e9119abb140b829efc3c94ea802df7a6f3968829645e1a5330"
strings:
Expand All @@ -233,7 +233,7 @@ rule php_eval_get_contents {
all of ($f*) and none of ($not*)
}

rule php_is_jpeg {
rule php_is_jpeg : critical {
meta:
hash_2023_0xShell_tifa_png = "1a13a6c6bb6815ba352b43971e4e961615367aec714e0a0005c28b3ebbc544c6"
strings:
Expand All @@ -244,7 +244,7 @@ rule php_is_jpeg {
all of them
}

rule php_copy_files {
rule php_copy_files : suspicious {
meta:
hash_2023_0xShell_0xShellori = "506e12e4ce1359ffab46038c4bf83d3ab443b7c5db0d5c8f3ad05340cb09c38e"
hash_2023_0xShell_tifa_png = "1a13a6c6bb6815ba352b43971e4e961615367aec714e0a0005c28b3ebbc544c6"
Expand All @@ -255,7 +255,7 @@ rule php_copy_files {
all of them
}

rule php_base64_encoded {
rule php_base64_encoded : critical {
meta:
hash_2023_0xShell_0xObs = "6391e05c8afc30de1e7980dda872547620754ce55c36da15d4aefae2648a36e5"
hash_2023_0xShell_0xShellObs = "64771788a20856c7b2a29067f41be9cb7138c11a2cf2a8d17ab4afe73516f1ed"
Expand Down
8 changes: 8 additions & 0 deletions rules/combo/backdoor/generic/ruby.yara
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
rule ruby_eval_base64_decode : critical {
meta:
description = "Evaluates base64 content"
strings:
$eval_base64_decode = "eval(Base64."
condition:
any of them
}
9 changes: 9 additions & 0 deletions rules/combo/backdoor/generic/sudo_nohup.yara
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rule sudo_nohup : suspicious {
meta:
description = "calls nohup sudo"
strings:
$nohup_sudo = /nohup sudo[ \.\/\w]{0,32}/
$sudo_nohup = /sudo nohup[ \.\/\w]{0,32}/
condition:
any of them
}
9 changes: 9 additions & 0 deletions rules/combo/backdoor/generic/timeout_eval.yara
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rule timeout_eval : critical {
meta:
description = "evaluate code dynamically using eval() after timeout"
strings:
$ref = /setTimeout\(.{0,64}eval\([\w\(\,\)\;\*\}]{0,32}/ fullword
condition:
any of them
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

rule tar_ssh_net : notable {
rule tar_ssh_net : suspicious {
strings:
$s_curl = "curl" fullword
$s_wget = "wget" fullword
Expand All @@ -9,6 +9,7 @@ rule tar_ssh_net : notable {
$z_zip = "zip" fullword
$z_tar = "tar" fullword
$z_xargs = "xargs cat"
condition:
$h and any of ($s*) and any of ($z*)
}
15 changes: 15 additions & 0 deletions rules/combo/exfil/nodejs_sysinfo_http..yara
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

rule npm_sysinfoexfil : suspicious {
meta:
description = "exfiltrate system information"
strings:
$p1 = "process.platform"
$p2 = "process.arch"
$p3 = "process.versions"
$h = "http.request"
$post = "POST"
condition:
$h and $post and any of ($p*)
}
15 changes: 15 additions & 0 deletions rules/combo/exfil/python_sysinfo_http.yara
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

rule python_sysinfo_http : suspicious {
meta:
description = "exfiltrate system information"
strings:
$r_user = "getpass.getuser"
$r_hostname = "socket.gethostname"
$r_platform = "platform.platform"
$u = /[\w\.]{0,16}urlopen/
condition:
filesize < 4096 and any of ($r*) and any of ($u*)
}

11 changes: 11 additions & 0 deletions rules/combo/exploit/overflow-shellcode.yara
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,14 @@ rule exploit: suspicious {
condition:
$shellcode and 3 of them
}

rule execute_shellcode: suspicious {
meta:
description = "Executes shell code"
strings:
$ref = "execute shellcode"
$ref2 = "exec_shellcode"
$ref3 = "execute_shellcode"
condition:
any of them
}
10 changes: 10 additions & 0 deletions rules/data/embedded-pem-test_key.yara
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
rule testing_key {
meta:
description = "Contains TESTING KEY directive"
strings:
$ref = "TESTING KEY-----"
condition:
any of them
}


1 change: 1 addition & 0 deletions rules/encoding/json-encode.yara
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ rule JSONEncode {
strings:
$jsone = "JSONEncode"
$marshal = "MarshalJSON" fullword
$npm = "JSON.stringify"
condition:
any of them
}
9 changes: 9 additions & 0 deletions rules/env/HOME.yara
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,12 @@ rule HOME {
condition:
all of them
}

rule node_HOME {
meta:
description = "Looks up the HOME directory for the current user"
strings:
$ref = "env.HOME" fullword
condition:
all of them
}
28 changes: 28 additions & 0 deletions rules/env/LANG.yara
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
rule LANG_getenv {
meta:
description = "Looks up language of current user"
strings:
$ref = "LANG" fullword
$getenv = "getenv"
condition:
all of them
}

rule LANG_node {
meta:
description = "Looks up language of current user"
strings:
$ref = "env.LANG" fullword
condition:
all of them
}


rule dollar_LANG {
meta:
description = "Looks up language of current user"
strings:
$ref = "$LANG" fullword
condition:
all of them
}
8 changes: 8 additions & 0 deletions rules/env/dump.yara
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
rule os_environ : harmless {
meta:
description = "Dump values from the environment"
strings:
$ref = "os.environ" fullword
condition:
any of them
}
9 changes: 9 additions & 0 deletions rules/evasion/hex.yara
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

rule node_hex_parse : suspicious {
meta:
description = "converts hex data to ASCII"
strings:
$ref = /Buffer\.from\(\w{0,16}, {0,2}'hex'\)/
condition:
$ref
}
2 changes: 1 addition & 1 deletion rules/exec/pipe.yara
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ rule popen : notable {
strings:
$_popen = "_popen" fullword
$_pclose = "_pclose" fullword
$os_popen = "os.popen" fullword
$os_popen = /os.popen[\(\"\'\w \$\)]{0,32}/
$pipe_glibc = "pipe@@GLIBC"
condition:
any of them
Expand Down
14 changes: 12 additions & 2 deletions rules/exec/program.yara
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ rule posix_spawn : notable {
}




rule go_exec : notable {
meta:
syscall = "posix_spawn"
Expand All @@ -89,4 +87,16 @@ rule go_exec : notable {
$ref = "exec_unix.go"
condition:
all of them
}

rule npm_exec : notable {
meta:
syscall = "posix_spawn"
pledge = "exec"
description = "spawn a process"
strings:
$child = "child_process"
$ref = /exec\(\'[\w \/\'\)]{0,64}/
condition:
all of them
}
Loading

0 comments on commit 0450e12

Please sign in to comment.