提取特征写成规则库,调用规则库查杀。基于规则,会比较快,但漏报、误报会比较明显,一般的Webshell一句话木马变形混淆会比较多。
yara规则
$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)
基于对日志数据进行分析,检测可疑的漏洞攻击行为,提取特定时间段内特定IP对应用的访问行为。
①提交数据(POST/GET)的熵
②URI的访问频率
③请求头中有/无Referer字段
④提交数据(POST/GET)中key的出现频率
⑤请求数据(POST/GET)中key关联的页面数
Webshell分析检测层,hook可疑函数
特征维度:
https://github.com/nbs-system/php-malware-finder
https://github.com/404notf0und/AI-for-Security-Learning
[1] https://www.cdxy.me/?p=788
[2] http://www.cnetsec.com/article/22593.html
[3] https://www.s0nnet.com/archives/fshell-feature-1
原文:https://www.cnblogs.com/17bdw/p/11920974.html