php - grep 整个服务器用于 shell 黑客/恶意软件

标签 php linux security shell grep

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

所以我构建了自己的小 bash 文件来查找这些脚本。 这个周末发现了 148 个 phpshell(我不太擅长创建 .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



最终结果

#!/bin/bash
LC_ALL=C grep -F -n -r -f /root/scanner/pattern.txt "/home/"

模式.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, "/");

最佳答案

将搜索字符串存储为单个多行字符串,并运行一次 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" *

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

PS:不要忘记在“”内加上\your $,否则你将找不到第15 和第19 个搜索字符串。我会创建一个包含您要搜索的所有字符串的测试文件,并验证 fgrep“$values”是否成功匹配了每个字符串。

关于php - grep 整个服务器用于 shell 黑客/恶意软件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22906040/

相关文章:

android - Android内核编译错误

php - mysql选择最近7天的每一天记录

php - 如何在 Wappalyzer 上隐藏网站信息

linux - 你如何在 Unix(或至少 Linux)中安全地读取内存?

php - exec 命令未在 Linux 主机上运行

linux - 以非 root 用户身份运行的系统守护进程的 PID 文件的首选位置

security - 是否可以使用两种不同的算法创建具有相同校验和的伪造文件?

wcf - WCF 端点的安全性

php - 使用通配符提供访问控制允许来源

php, invokeArgs : parameters changed, 怎么返回呢?