diff options
| author | Julien (jvoisin) Voisin | 2016-02-24 10:26:05 +0100 |
|---|---|---|
| committer | Julien (jvoisin) Voisin | 2016-02-24 10:26:05 +0100 |
| commit | 97564364b082aace0adcf306446bdff97f539ed2 (patch) | |
| tree | 7e1218dcfee64c1aa30017427f5585d59e5f0b35 | |
| parent | efefe633e1d5e0b42f12e2c4bc0e15c186d9e6fb (diff) | |
Even more tests for the testsuite!
| -rw-r--r-- | php-malware-finder/malwares.yara | 21 | ||||
| -rw-r--r-- | php-malware-finder/samples/artificial/dodgy.php | 18 | ||||
| -rwxr-xr-x | php-malware-finder/tests.sh | 25 |
3 files changed, 49 insertions, 15 deletions
diff --git a/php-malware-finder/malwares.yara b/php-malware-finder/malwares.yara index 8fe7b15..bfc4d7a 100644 --- a/php-malware-finder/malwares.yara +++ b/php-malware-finder/malwares.yara | |||
| @@ -108,14 +108,12 @@ rule DodgyPhp | |||
| 108 | $execution = /(eval|assert|passthru|exec|system|win_shell_execute|base64_decode)\s*\(\s*(base64_decode|php:\/\/input|str_rot13|gz(inflate|uncompress)|getenv|pack|\\?\$_(GET|REQUEST|POST|COOKIE))/ | 108 | $execution = /(eval|assert|passthru|exec|system|win_shell_execute|base64_decode)\s*\(\s*(base64_decode|php:\/\/input|str_rot13|gz(inflate|uncompress)|getenv|pack|\\?\$_(GET|REQUEST|POST|COOKIE))/ |
| 109 | $htaccess = "SetHandler application/x-httpd-php" | 109 | $htaccess = "SetHandler application/x-httpd-php" |
| 110 | $iis_com = /IIS:\/\/localhost\/w3svc/ | 110 | $iis_com = /IIS:\/\/localhost\/w3svc/ |
| 111 | $include = /include\([^\.]+\.(png|jpg|gif|bmp)/ // Clever includes | 111 | $include = /include\s*\(\s*[^\.]+\.(png|jpg|gif|bmp)/ // Clever includes |
| 112 | $ini_get = /ini_get\(['"](safe_mode|open_basedir|disable_function|safe_mode_exec_dir|safe_mode_include_dir|register_globals)['"]\)/ | 112 | $ini_get = /ini_(get|set|restore)\s*\(\s*['"](safe_mode|open_basedir|disable_function|safe_mode_exec_dir|safe_mode_include_dir|register_globals|allow_url_include)/ |
| 113 | $iniset_urlinclude = /ini_set\('allow_url_include,\ * 1'\)/ | 113 | $pr = /(preg_replace(_callback)?|mb_ereg_replace|preg_filter)\s*\(\s*['"]\/[^\/]*\/e/ // http://php.net/manual/en/function.preg-replace.php |
| 114 | $pr = /(preg_replace(_callback)?|mb_ereg_replace|preg_filter)\s*\(['"]\/[^\/]*\/e['"]/ // http://php.net/manual/en/function.preg-replace.php | ||
| 115 | $restore_bypass = /ini_restore\(['"](safe_mode|open_basedir|disable_function|safe_mode_exec_dir|safe_mode_include_dir|register_globals)['"]\)/ | ||
| 116 | $safemode_bypass = /\x00\/\.\.\/|LD_PRELOAD/ | 114 | $safemode_bypass = /\x00\/\.\.\/|LD_PRELOAD/ |
| 117 | $shellshock = /putenv\(["']PHP_[^=]=\(\) { [^}] };/ | 115 | $shellshock = /\(\)\s*{\s*:\s*;\s*}\s*;/ |
| 118 | $udp_dos = /sockopen\s*\(['"]udp:\/\// | 116 | $udp_dos = /fsockopen\s*\(\s*['"]udp:\/\// |
| 119 | $user_function = /(call_user_func|create_function)/ | 117 | $user_function = /(call_user_func|create_function)/ |
| 120 | $various = "<!--#exec cmd=" //http://www.w3.org/Jigsaw/Doc/User/SSI.html#exec | 118 | $various = "<!--#exec cmd=" //http://www.w3.org/Jigsaw/Doc/User/SSI.html#exec |
| 121 | 119 | ||
| @@ -138,6 +136,7 @@ rule DangerousPhp | |||
| 138 | $ = "fsockopen" fullword | 136 | $ = "fsockopen" fullword |
| 139 | $ = "function_exists" fullword | 137 | $ = "function_exists" fullword |
| 140 | $ = "getmygid" fullword | 138 | $ = "getmygid" fullword |
| 139 | $ = "shmop_open" fullword | ||
| 141 | $ = "mb_ereg_replace_callback" fullword | 140 | $ = "mb_ereg_replace_callback" fullword |
| 142 | $ = "passthru" fullword | 141 | $ = "passthru" fullword |
| 143 | $ = "pcntl_exec" fullword | 142 | $ = "pcntl_exec" fullword |
| @@ -183,10 +182,9 @@ rule DangerousPhp | |||
| 183 | rule DodgyStrings | 182 | rule DodgyStrings |
| 184 | { | 183 | { |
| 185 | strings: | 184 | strings: |
| 186 | $ = ".ssh/authorized_keys" | ||
| 187 | $ = ".bash_history" | 185 | $ = ".bash_history" |
| 188 | $ = ".mysql_history" | 186 | $ = ".mysql_history" |
| 189 | $ = /-perm -0[24]000/ // find setuid files | 187 | $ = ".ssh/authorized_keys" |
| 190 | $ = "/(.*)/e" // preg_replace code execution | 188 | $ = "/(.*)/e" // preg_replace code execution |
| 191 | $ = "/../../../" | 189 | $ = "/../../../" |
| 192 | $ = "/etc/passwd" | 190 | $ = "/etc/passwd" |
| @@ -195,8 +193,9 @@ rule DodgyStrings | |||
| 195 | $ = "/etc/shadow" | 193 | $ = "/etc/shadow" |
| 196 | $ = "/etc/syslog.conf" | 194 | $ = "/etc/syslog.conf" |
| 197 | $ = "/proc/cpuinfo" fullword | 195 | $ = "/proc/cpuinfo" fullword |
| 198 | $ = "/windows/system32/" | ||
| 199 | $ = "/var/log/lastlog" | 196 | $ = "/var/log/lastlog" |
| 197 | $ = "/windows/system32/" | ||
| 198 | $ = "LOAD DATA LOCAL INFILE" nocase | ||
| 200 | $ = "WScript.Shell" | 199 | $ = "WScript.Shell" |
| 201 | $ = "WinExec" | 200 | $ = "WinExec" |
| 202 | $ = "b374k" fullword nocase | 201 | $ = "b374k" fullword nocase |
| @@ -210,6 +209,7 @@ rule DodgyStrings | |||
| 210 | $ = "hashcrack" nocase | 209 | $ = "hashcrack" nocase |
| 211 | $ = "id_rsa" fullword | 210 | $ = "id_rsa" fullword |
| 212 | $ = "ipconfig" fullword nocase | 211 | $ = "ipconfig" fullword nocase |
| 212 | $ = "kernel32.dll" fullword nocase | ||
| 213 | $ = "kingdefacer" nocase | 213 | $ = "kingdefacer" nocase |
| 214 | $ = "libpcprofile" // CVE-2010-3856 local root | 214 | $ = "libpcprofile" // CVE-2010-3856 local root |
| 215 | $ = "locus7s" nocase | 215 | $ = "locus7s" nocase |
| @@ -224,6 +224,7 @@ rule DodgyStrings | |||
| 224 | $ = "uname -a" fullword | 224 | $ = "uname -a" fullword |
| 225 | $ = "warez" fullword nocase | 225 | $ = "warez" fullword nocase |
| 226 | $ = /(reverse|web)\s*shell/ nocase | 226 | $ = /(reverse|web)\s*shell/ nocase |
| 227 | $ = /-perm -0[24]000/ // find setuid files | ||
| 227 | $ = /\/bin\/(ba)?sh/ fullword | 228 | $ = /\/bin\/(ba)?sh/ fullword |
| 228 | $ = /hack(ing|er)/ nocase | 229 | $ = /hack(ing|er)/ nocase |
| 229 | $ = /xp_(execresultset|regenumkeys|cmdshell|filelist)/ | 230 | $ = /xp_(execresultset|regenumkeys|cmdshell|filelist)/ |
diff --git a/php-malware-finder/samples/artificial/dodgy.php b/php-malware-finder/samples/artificial/dodgy.php new file mode 100644 index 0000000..1c85f39 --- /dev/null +++ b/php-malware-finder/samples/artificial/dodgy.php | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | curl_init ( "file:///etc/parla"); | ||
| 4 | curl_setopt($ch, CURLOPT_URL, "file:file:////etc/passwd"); | ||
| 5 | set_magic_quotes_runtime ( 0); | ||
| 6 | eval(base64_decode($_GET['lol'])); | ||
| 7 | $a= "SetHandler application/x-httpd-php"; | ||
| 8 | $b = "IIS://localhost/w3svc"; | ||
| 9 | include ( 'lol.png'); | ||
| 10 | ini_get ( 'disable_function'); | ||
| 11 | ini_set("disable_function", ""); | ||
| 12 | ini_restore("allow_url_include"); | ||
| 13 | preg_replace ("/*/e"); | ||
| 14 | $c = "env x='() { :;}; echo vulnerable' bash -c 'echo this is a test'"; | ||
| 15 | fsockopen ( 'udp://'); | ||
| 16 | call_user_func('LOL'); | ||
| 17 | $d = "<!--#exec cmd="; | ||
| 18 | |||
diff --git a/php-malware-finder/tests.sh b/php-malware-finder/tests.sh index b73184a..a0885fd 100755 --- a/php-malware-finder/tests.sh +++ b/php-malware-finder/tests.sh | |||
| @@ -27,9 +27,9 @@ run_test classic/ajaxshell.php 'DodgyStrings' | |||
| 27 | run_test classic/ajaxshell.php 'Websites' | 27 | run_test classic/ajaxshell.php 'Websites' |
| 28 | run_test classic/ajaxshell.php '0x23e2:$: shell_exec' | 28 | run_test classic/ajaxshell.php '0x23e2:$: shell_exec' |
| 29 | run_test classic/ajaxshell.php '0x2380:$eval: {\\x0A\\x09\\x09\\x09\\x09\\x09system(' | 29 | run_test classic/ajaxshell.php '0x2380:$eval: {\\x0A\\x09\\x09\\x09\\x09\\x09system(' |
| 30 | run_test classic/ajaxshell.php "0x16e0:\$ini_get: ini_get('safe_mode')" | 30 | run_test classic/ajaxshell.php "0x16e0:\$ini_get: ini_get('safe_mode" |
| 31 | run_test classic/ajaxshell.php "0x17f1:\$ini_get: ini_get('open_basedir')" | 31 | run_test classic/ajaxshell.php "0x17f1:\$ini_get: ini_get('open_basedir" |
| 32 | run_test classic/angel.php '0x1d:\$disable_magic_quotes: set_magic_quotes_runtime(0)' | 32 | run_test classic/angel.php '0x1d:$disable_magic_quotes:' |
| 33 | run_test classic/b374k.php 'ObfuscatedPhp' | 33 | run_test classic/b374k.php 'ObfuscatedPhp' |
| 34 | run_test classic/b374k.php "0xe9:\$b374k: 'ev'.'al'" | 34 | run_test classic/b374k.php "0xe9:\$b374k: 'ev'.'al'" |
| 35 | run_test classic/b374k.php '0xb3:$align: $func="cr"."eat"."e_fun"."cti"."on";$b374k=$func(' | 35 | run_test classic/b374k.php '0xb3:$align: $func="cr"."eat"."e_fun"."cti"."on";$b374k=$func(' |
| @@ -38,7 +38,7 @@ run_test classic/b374k.php '0x43:$: github.com/b374k/b374k' | |||
| 38 | run_test classic/sosyete.php '0x1a0a:$execution: exec($_POST' | 38 | run_test classic/sosyete.php '0x1a0a:$execution: exec($_POST' |
| 39 | run_test classic/simattacker.php '0x16e:$: fpassthru' | 39 | run_test classic/simattacker.php '0x16e:$: fpassthru' |
| 40 | run_test classic/r57.php '0x149da:$: xp_cmdshell' | 40 | run_test classic/r57.php '0x149da:$: xp_cmdshell' |
| 41 | run_test classic/cyb3rsh3ll.php '0x164d:$udp_dos: sockopen("udp://' | 41 | run_test classic/cyb3rsh3ll.php '0x23323:$udp_dos: fsockopen("udp://' |
| 42 | run_test classic/c99.php '0x3d56:$eval: {exec(' | 42 | run_test classic/c99.php '0x3d56:$eval: {exec(' |
| 43 | run_test classic/c100.php '0x4f8d:$eval: {eval(' | 43 | run_test classic/c100.php '0x4f8d:$eval: {eval(' |
| 44 | 44 | ||
| @@ -46,7 +46,7 @@ run_test classic/c100.php '0x4f8d:$eval: {eval(' | |||
| 46 | run_test obfuscators/cipher_design.php '0x124:$execution: eval(base64_decode' | 46 | run_test obfuscators/cipher_design.php '0x124:$execution: eval(base64_decode' |
| 47 | run_test obfuscators/cipher_design.php '0x123:$eval: ;eval(' | 47 | run_test obfuscators/cipher_design.php '0x123:$eval: ;eval(' |
| 48 | run_test obfuscators/online_php_obfuscator.php '0x51:$eval: ;preg_replace(' | 48 | run_test obfuscators/online_php_obfuscator.php '0x51:$eval: ;preg_replace(' |
| 49 | run_test obfuscators/online_php_obfuscator.php "0x52:\$pr: preg_replace('/.*/e'" | 49 | run_test obfuscators/online_php_obfuscator.php "0x52:\$pr: preg_replace('/.*/e" |
| 50 | run_test obfuscators/online_php_obfuscator.php "SuspiciousEncoding" | 50 | run_test obfuscators/online_php_obfuscator.php "SuspiciousEncoding" |
| 51 | run_test obfuscators/phpencode.php "ObfuscatedPhp" | 51 | run_test obfuscators/phpencode.php "ObfuscatedPhp" |
| 52 | run_test obfuscators/phpencode.php "DodgyPhp" | 52 | run_test obfuscators/phpencode.php "DodgyPhp" |
| @@ -58,6 +58,21 @@ run_test artificial/obfuscated.php '0xd1:$align: ;$b374k=$func(' | |||
| 58 | run_test artificial/obfuscated.php '0xf0:$weevely3:' | 58 | run_test artificial/obfuscated.php '0xf0:$weevely3:' |
| 59 | run_test artificial/obfuscated.php '0x103:$c99_launcher:' | 59 | run_test artificial/obfuscated.php '0x103:$c99_launcher:' |
| 60 | run_test artificial/obfuscated.php '0x117:$variable_variable:' | 60 | run_test artificial/obfuscated.php '0x117:$variable_variable:' |
| 61 | run_test artificial/dodgy.php '$basedir_bypass:' | ||
| 62 | run_test artificial/dodgy.php '$basedir_bypass2:' | ||
| 63 | run_test artificial/dodgy.php '$disable_magic_quotes:' | ||
| 64 | run_test artificial/dodgy.php '$execution: eval(base64_decode' | ||
| 65 | run_test artificial/dodgy.php '$execution: base64_decode($_GET' | ||
| 66 | run_test artificial/dodgy.php '$htaccess:' | ||
| 67 | run_test artificial/dodgy.php '0xd7:$iis_com: IIS://localhost/w3svc' | ||
| 68 | run_test artificial/dodgy.php "0xef:\$include: include ( 'lol.png" | ||
| 69 | run_test artificial/dodgy.php "0x106:\$ini_get: ini_get ( 'disable_function" | ||
| 70 | run_test artificial/dodgy.php '0x126:$ini_get: ini_set("disable_function' | ||
| 71 | run_test artificial/dodgy.php '0x147:$ini_get: ini_restore("allow_url_include' | ||
| 72 | run_test artificial/dodgy.php '0x18d:$shellshock: () { :;};' | ||
| 73 | run_test artificial/dodgy.php '0x169:$pr: preg_replace ("/\*/e' | ||
| 74 | run_test artificial/dodgy.php '0x1e0:$user_function: call_user_func' | ||
| 75 | run_test artificial/dodgy.php '0x1fd:$various: <!--#exec cmd=' | ||
| 61 | 76 | ||
| 62 | 77 | ||
| 63 | echo "[+] Congratz, the $CPT tests succeeded!" | 78 | echo "[+] Congratz, the $CPT tests succeeded!" |
