From 48936efa96ae17295be4e0a71be3294f0ec6aef8 Mon Sep 17 00:00:00 2001 From: Mathieu Deous Date: Mon, 2 May 2022 20:18:23 +0200 Subject: Make application go-install-able and create a docker image --- data/php.yar | 374 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 374 insertions(+) create mode 100644 data/php.yar (limited to 'data/php.yar') diff --git a/data/php.yar b/data/php.yar new file mode 100644 index 0000000..4470e1b --- /dev/null +++ b/data/php.yar @@ -0,0 +1,374 @@ +import "hash" +include "whitelist.yar" + +/* + Detect: + - phpencode.org + - http://www.pipsomania.com/best_php_obfuscator.do + - http://atomiku.com/online-php-code-obfuscator/ + - http://www.webtoolsvn.com/en-decode/ + - http://obfuscator.uk/example/ + - http://w3webtools.com/encode-php-online/ + - http://www.joeswebtools.com/security/php-obfuscator/ + - https://github.com/epinna/weevely3 + - http://cipherdesign.co.uk/service/php-obfuscator + - http://sysadmin.cyklodev.com/online-php-obfuscator/ + - http://mohssen.org/SpinObf.php + - https://code.google.com/p/carbylamine/ + - https://github.com/tennc/webshell + + - https://github.com/wireghoul/htshells + + Thanks to: + - https://stackoverflow.com/questions/3115559/exploitable-php-functions +*/ + +global private rule IsPhp +{ + strings: + $php = /<\?[^x]/ + + condition: + $php and filesize < 5MB +} + +rule NonPrintableChars +{ + strings: + /* + Searching only for non-printable characters completely kills the perf, + so we have to use atoms (https://gist.github.com/Neo23x0/e3d4e316d7441d9143c7) + to get an acceptable speed. + */ + $non_printables = /(function|return|base64_decode).{,256}[^\x09-\x0d\x20-\x7E]{3}/ + + condition: + (any of them) and not IsWhitelisted +} + + +rule PasswordProtection +{ + strings: + $md5 = /md5\s*\(\s*\$_(GET|REQUEST|POST|COOKIE|SERVER)[^)]+\)\s*===?\s*['"][0-9a-f]{32}['"]/ nocase + $sha1 = /sha1\s*\(\s*\$_(GET|REQUEST|POST|COOKIE|SERVER)[^)]+\)\s*===?\s*['"][0-9a-f]{40}['"]/ nocase + condition: + (any of them) and not IsWhitelisted +} + +rule ObfuscatedPhp +{ + strings: + $eval = /(<\?php|[;{}])[ \t]*@?(eval|preg_replace|system|assert|passthru|(pcntl_)?exec|shell_exec|call_user_func(_array)?)\s*\(/ nocase // ;eval( <- this is dodgy + $eval_comment = /(eval|preg_replace|system|assert|passthru|(pcntl_)?exec|shell_exec|call_user_func(_array)?)\/\*[^\*]*\*\/\(/ nocase // eval/*lol*/( <- this is dodgy + $b374k = "'ev'.'al'" + $align = /(\$\w+=[^;]*)*;\$\w+=@?\$\w+\(/ //b374k + $weevely3 = /\$\w=\$[a-zA-Z]\('',\$\w\);\$\w\(\);/ // weevely3 launcher + $c99_launcher = /;\$\w+\(\$\w+(,\s?\$\w+)+\);/ // http://bartblaze.blogspot.fr/2015/03/c99shell-not-dead.html + $nano = /\$[a-z0-9-_]+\[[^]]+\]\(/ //https://github.com/UltimateHackers/nano + $ninja = /base64_decode[^;]+getallheaders/ //https://github.com/UltimateHackers/nano + $variable_variable = /\${\$[0-9a-zA-z]+}/ + $too_many_chr = /(chr\([\d]+\)\.){8}/ // concatenation of more than eight `chr()` + $concat = /(\$[^\n\r]+\.){5}/ // concatenation of more than 5 words + $concat_with_spaces = /(\$[^\n\r]+\. ){5}/ // concatenation of more than 5 words, with spaces + $var_as_func = /\$_(GET|POST|COOKIE|REQUEST|SERVER)\s*\[[^\]]+\]\s*\(/ + $comment = /\/\*([^*]|\*[^\/])*\*\/\s*\(/ // eval /* comment */ (php_code) +condition: + (any of them) and not IsWhitelisted +} + +rule DodgyPhp +{ + strings: + $basedir_bypass = /curl_init\s*\(\s*["']file:\/\// nocase + $basedir_bypass2 = "file:file:///" // https://www.intelligentexploit.com/view-details.html?id=8719 + $disable_magic_quotes = /set_magic_quotes_runtime\s*\(\s*0/ nocase + + $execution = /\b(popen|eval|assert|passthru|exec|include|system|pcntl_exec|shell_exec|base64_decode|`|array_map|ob_start|call_user_func(_array)?)\s*\(\s*(base64_decode|php:\/\/input|str_rot13|gz(inflate|uncompress)|getenv|pack|\\?\$_(GET|REQUEST|POST|COOKIE|SERVER))/ nocase // function that takes a callback as 1st parameter + $execution2 = /\b(array_filter|array_reduce|array_walk(_recursive)?|array_walk|assert_options|uasort|uksort|usort|preg_replace_callback|iterator_apply)\s*\(\s*[^,]+,\s*(base64_decode|php:\/\/input|str_rot13|gz(inflate|uncompress)|getenv|pack|\\?\$_(GET|REQUEST|POST|COOKIE|SERVER))/ nocase // functions that takes a callback as 2nd parameter + $execution3 = /\b(array_(diff|intersect)_u(key|assoc)|array_udiff)\s*\(\s*([^,]+\s*,?)+\s*(base64_decode|php:\/\/input|str_rot13|gz(inflate|uncompress)|getenv|pack|\\?\$_(GET|REQUEST|POST|COOKIE|SERVER))\s*\[[^]]+\]\s*\)+\s*;/ nocase // functions that takes a callback as 2nd parameter + + $htaccess = "SetHandler application/x-httpd-php" + $iis_com = /IIS:\/\/localhost\/w3svc/ + $include = /include\s*\(\s*[^\.]+\.(png|jpg|gif|bmp)/ // Clever includes + $ini_get = /ini_(get|set|restore)\s*\(\s*['"](safe_mode|open_basedir|disable_(function|classe)s|safe_mode_exec_dir|safe_mode_include_dir|register_globals|allow_url_include)/ nocase + $pr = /(preg_replace(_callback)?|mb_ereg_replace|preg_filter)\s*\([^)]*(\/|\\x2f)(e|\\x65)['"]/ nocase // http://php.net/manual/en/function.preg-replace.php + $register_function = /register_[a-z]+_function\s*\(\s*['"]\s*(eval|assert|passthru|exec|include|system|shell_exec|`)/ // https://github.com/nbs-system/php-malware-finder/issues/41 + $safemode_bypass = /\x00\/\.\.\/|LD_PRELOAD/ + $shellshock = /\(\)\s*{\s*[a-z:]\s*;\s*}\s*;/ + $udp_dos = /fsockopen\s*\(\s*['"]udp:\/\// nocase + $various = "