gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 00:31:36 30 4
gpt4 key购买 nike

我们在多台服务器上托管了 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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com