grep整个服务器的shell hacks/malware

Sin*_*tch 7 php linux security shell grep

我们在多台服务器上托管了1000个域.我们遇到大量恶意软件和phpshell的问题.许多扫描仪的使用对它们没有影响.也许我们从那些扫描仪得到10/20模糊的结果

所以我构建自己的小bash文件来查找这些脚本.它本周末发现了148个phpshells(我不擅长创建.SH文件).



我的问题 grep很慢,它会持续数天.我怎样才能使这个脚本更有效率?

array=(
    "base64_decode(" 
    "substr(md5(strrev(" 
    "cwd = @getcwd();" 
    "chr((ord(" 
    "gzinflate(base64_decode(" 
    "php_uname()" "] = chr(ord(" 
    "cwd[strlen($cwd)" 
    "ini_get('safe_mode');" 
    "=\"\x62\"" 
    "\"+ r + \"&r=\" + document.referrer;\"" 
    "if(strtoupper(substr(PHP_OS, 0, 3) ) == \"WIN\")" 
    "window.top.location.href=\"http://" 
    "@ini_get(\"disable_functions\")" 
    "$g3='';$g3.=$r;$g3.=$h;$g3.=$y"
    "hacked"
)

for value in "${array[@]}"
do
    printf "\n[$value] [start => $(date +"%T")]\n"
        grep -l -inr "$value" "/home/"
    printf "\n[end => $(date +"%T")]\n"
done
Run Code Online (Sandbox Code Playgroud)



最后结果

#!/bin/bash
LC_ALL=C grep -F -n -r -f /root/scanner/pattern.txt "/home/"
Run Code Online (Sandbox Code Playgroud)

Pattern.txt

eval($___($__));
eval(stripslashes(@$_POST[
eval(stripslashes(array_pop(
eval(base64_decode(
eval(gzinflate(str_rot13(base64_decode(
gzinflate(base64_decode(
Array(base64_decode(
sha1(base64_decode(
print(base64_decode(
wsoScandir($dir)
substr(current(array_keys(
cwd = @getcwd();
$OOO000000=urldecode(
$l___l_='base'.(32*2)
substr(md5(strrev(
cwd[strlen($cwd)
="x62
+ r + "&r=" + document.referrer;
if(strtoupper(substr(PHP_OS, 0, 3) ) == "WIN")
){if(@copy(
copy("endless.html
system("wget
symlink("/","sym/root");
@copy($_FILES['file']['tmp_name']
error_reporting(0);if(
x6C\x28\x67\x7A\x69
"/.*/e","\x28\x65\x76\x61
preg_replace("/.*/e",
Windows-1251";preg_replace(
); exit(); } if(isset(
system("$cmd"); die;}
rtrim($security_code, "/");
Run Code Online (Sandbox Code Playgroud)

web*_*ebb 7

将搜索字符串存储为单个多行字符串,并运行fgrep一次而不是循环:

values="eval(base64_decode(
gzinflate(base64_decode(
cwd = @getcwd();
chr((ord(
substr(md5(strrev(
chr(ord(
cwd[strlen(\$cwd)
ini_get('safe_mode');
=\"\x62\"
\"+ r + \"&r=\" + document.referrer;\"
if(strtoupper(substr(PHP_OS, 0, 3) ) == \"WIN\")
window.top.location.href=\"http://
@ini_get(\"disable_functions\")
){if(@copy(
eval(\$___(\$__));
copy(\"endless.html\"
system(\"wget
symlink(\"/\",\"sym/root\");
@copy(\$_FILES['file']['tmp_name']
error_reporting(0);if(
x6C\x28\x67\x7A\x69\x6E\x66\x6C\x61\x74
hacked"

LC_ALL=C fgrep -nr --include  \*.php "$values" *
Run Code Online (Sandbox Code Playgroud)

此版本的运行速度比原版快22倍(在一个相当大的网站上为0.535秒对11.817秒).非巧合的是,您有22个搜索字符串.

PS:不要忘记\"你的$"里面,或者你找不到你的第15和第19个搜索字符串.我将创建一个包含您要搜索的所有字符串的测试文件,并验证fgrep"$ values"是否成功匹配每个字符串.