彻底移除阿里云盾 (AliYunDun):手动清除指南

5 min

如果你租用了阿里云的 VPS,你得到的不仅仅是一台服务器,还有附赠的“监控服务”——阿里云盾(AliYunDun / Aegis)。官方宣称它是为了安全,但对于每一个不仅想要“使用”系统,更想要“掌控”系统的工程师来说,这种内核级别的驻留进程是不可接受的。

当你试图删除它时,你会发现:

  1. kill 杀不死,进程会自动复活。
  2. rm 删不掉,文件被加上了 i (immutable) 属性,甚至被内核模块锁定。
  3. 官方提供的卸载脚本不仅跑不通,甚至清理不干净。

Talk is cheap. Show me the code. 以下是彻底剥离阿里云盾的完整手术记录。

1. 现状确认 (Reconnaissance)

首先,看看你的系统里到底有多少垃圾进程在跑。

ps -aux | grep -E 'aliyun|AliYunDun' | grep -v grep

你会看到类似这样的输出:

root     1038792  0.1  0.6 ... /usr/local/aegis/aegis_update/AliYunDunUpdate
root     2660270  0.7  1.3 ... /usr/local/aegis/aegis_client/aegis_12_81/AliYunDun
root     3887577  2.0  3.9 ... /usr/local/aegis/aegis_client/aegis_12_81/AliYunDunMonitor

不仅如此,检查内核模块:

lsmod | grep Ali

如果有 AliSecGuard,说明它已经嵌入内核,锁死了相关文件。这时候你无论怎么 rm 都会提示 Operation not permitted

2. 官方卸载脚本 (The “Official” Way)

虽然我很想直接手动删除,但先运行官方脚本可以省去停止部分服务的时间。不要指望它能完成工作,它只是第一步。

wget -q http://update.aegis.aliyun.com/download/uninstall.sh && chmod +x uninstall.sh && ./uninstall.sh
wget -q http://update.aegis.aliyun.com/download/quartz_uninstall.sh && chmod +x quartz_uninstall.sh && ./quartz_uninstall.sh

运行后,你会发现进程可能还在,文件依然删不掉。这是预期内的。

3. 切断通信 (The Kill Switch)

如果无法立即杀死它,就先饿死它。阿里云盾需要向控制端发送心跳和数据。我们在防火墙层阻断这些通信。

这是最关键的一步。即便进程还在,它也变成了瞎子和哑巴。

# 屏蔽阿里云盾常见的通信 IP 段
iptables -I INPUT -s 140.205.201.0/28 -j DROP
iptables -I INPUT -s 140.205.201.16/29 -j DROP
iptables -I INPUT -s 140.205.201.32/28 -j DROP
iptables -I INPUT -s 140.205.225.192/29 -j DROP
iptables -I INPUT -s 140.205.225.200/30 -j DROP
iptables -I INPUT -s 140.205.225.184/29 -j DROP
iptables -I INPUT -s 140.205.225.183/32 -j DROP
iptables -I INPUT -s 140.205.225.206/32 -j DROP
iptables -I INPUT -s 140.205.225.205/32 -j DROP
iptables -I INPUT -s 140.205.225.195/32 -j DROP
iptables -I INPUT -s 140.205.225.204/32 -j DROP

# 持久化规则 (Debian/Ubuntu)
apt-get install -y iptables-persistent netfilter-persistent
netfilter-persistent save

验证规则是否生效:

iptables -L INPUT -n

4. 停止服务与清理启动项

在重启之前,尽可能禁用它的启动项,防止它在下一次启动时加载内核模块。

systemctl stop aliyun
systemctl stop aegis
systemctl disable aliyun
systemctl disable aegis

# 尝试删除服务文件(如果被锁定,这步会失败,留到重启后)
rm -f /etc/systemd/system/aliyun.service
rm -f /etc/systemd/system/aegis.service
rm -f /etc/systemd/system/multi-user.target.wants/aliyun.service
rm -f /etc/systemd/system/multi-user.target.wants/aegis.service
systemctl daemon-reload

5. 重启 (The Reboot)

你无法在 AliSecGuard 模块加载时删除受保护的文件。你必须重启系统。

由于我们在第4步禁用了服务,且在第3步切断了网络,重启后内核模块应该不会被加载,或者即使加载也无法联网更新/自我修复。

reboot

6. 最终清理 (Surgical Removal)

系统重新上线后,再次检查:

lsmod | grep Ali

如果输出为空,恭喜,护盾已卸下。现在你可以像切除坏死组织一样清理残留文件了。

# 强制清理所有残留进程
pkill -9 AliYunDun
pkill -9 AliYunDunUpdate
pkill -9 aliyun-service

# 删除目录
rm -rf /usr/local/aegis*

# 清理残留的 systemd 服务文件
rm -f /usr/sbin/aliyun-service
rm -f /lib/systemd/system/aliyun.service
rm -f /etc/systemd/system/aegis.service

7. 验证 (Verify, Don’t Trust)

不要假设它走了。确认它走了。

  1. 检查进程ps -aux | grep aegis 应为空。
  2. 检查模块lsmod | grep Ali 应为空。
  3. 检查文件/usr/local/aegis 应不存在。
  4. 检查防火墙iptables -L INPUT -n 确认 DROP 规则依然存在。

总结

控制权不是别人给的,是抢回来的。 对于生产环境,我不建议使用任何预装了监控 Agent 的镜像。如果必须使用,请确保你清楚地知道系统中运行的每一行代码是做什么的。

防火墙是你的最后一道防线。Keep it tight.