利用raw_exec配置不当实现Nomad容器编排系统入侵

本文详细分析了HashiCorp Nomad容器编排工具中raw_exec驱动器的安全风险。通过实际演示如何检测和利用默认禁用的raw_exec功能,展示了攻击者如何通过特制任务文件在Nomad主机上执行任意命令并获取反向Shell,同时提供了ACL安全加固建议。

Devoops: 启用raw_exec的Nomad漏洞利用

“Nomad是一种灵活的容器编排工具,使组织能够使用单一统一工作流轻松部署和管理任何容器化或传统应用程序。Nomad可以运行各种工作负载,包括Docker、非容器化、微服务和批处理应用程序,通常为开发人员和运维人员提供以下好处……”

来自:https://www.nomadproject.io/intro/index.html

要了解它在HashiCorp生态系统中的定位,请查看以下图示:

我要感谢Will Butler允许我在观察他攻破该系统后撰写本文。

您可以使用以下教程搭建开发环境: https://www.nomadproject.io/intro/getting-started/install.html

教程指导您以开发环境模式运行,该模式不会绑定到0.0.0.0,因此在Vagrant启动后,您需要以下服务器和客户端文件来搭建适当的环境。

服务器:https://gist.github.com/carnal0wnage/ce4296137414bd16fcca0818208b39b7 客户端1:https://gist.github.com/carnal0wnage/4abde0ee31f4d730019e6fa04ef6d3b6 客户端2:https://gist.github.com/carnal0wnage/a4399019a943862e57283c29994ce5da

如果一切正常运行,您应该能够连接到4646端口上的UI并查看示例作业

1
2
3
4
5
6
7
8
9
$ nomad job run example.nomad

==> Monitoring evaluation "ac9b4b08"
    Evaluation triggered by job "example"
    Evaluation within deployment: "8a7dfe0f"
    Allocation "57e65abe" created: node "a15034e5", group "cache"
    Evaluation status changed: "pending" -> "complete"

==> Evaluation "ac9b4b08" finished with status "complete"

Nomad UI中的作业:

Nomad UI中的服务器:

Nomad UI中的客户端:

利用配置错误

Nomad默认禁用了raw_exec选项。

参考:https://www.nomadproject.io/docs/drivers/raw_exec.html

raw_exec选项允许您在Nomad主机上无隔离地运行命令。

“raw_exec驱动程序可以在所有支持的操作系统上运行。出于安全原因,默认情况下它是禁用的。要启用raw_exec,Nomad客户端配置必须在客户端的选项中显式启用raw_exec驱动程序:”

如何检查客户端上是否启用了raw_exec模块?

您可以在UI中查看:

或通过访问API端点:

开始利用

我们需要创建一个包含命令的作业hcl文件。这是一个简单的示例:

https://gist.github.com/carnal0wnage/25b391126dadefe0a9523fb421bf8f33

启动服务:

我们的作业结果:

UI中的作业:

停止作业:

强制运行垃圾回收:

验证作业已被删除:

获取反向Shell

我使用了以下hcl文件: https://gist.github.com/carnal0wnage/4a436a8dc0dcb142a8c836e48916dd71

反向Shell作业:

从Nomad获取的Shell:

通过ACL保护Nomad的信息: https://www.nomadproject.io/guides/security/acl.html

comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计