Symbolexe / CVE-2024-6387

SSH Exploit for CVE-2024-6387 : RCE in OpenSSH's server, on glibc-based Linux systems
MIT License
2 stars 3 forks source link
cve cve-2024-6387 exploit pentesting python3 redteam

CVE-2024-6387

Screenshot 2024-07-04 182931 CVE-2024-6387 is a hypothetical example, but let's assume it is a real-world vulnerability in the OpenSSH server implementation. This vulnerability could involve a buffer overflow or memory corruption issue that allows remote attackers to execute arbitrary code on the server. Here’s a high-level explanation of how such a vulnerability could be exploited:

  1. Heap Spraying: The attacker prepares the heap in a way that makes it predictable.
  2. Memory Corruption: The attacker sends specially crafted packets that cause memory corruption.
  3. Arbitrary Code Execution: The attacker places shellcode (malicious code) in a known location and redirects execution to it.

The Exploit Code

The provided Python code is an exploit designed to take advantage of CVE-2024-6387. Here's a detailed breakdown of the steps it takes: Setup Connection: Establishes a TCP connection to the target SSH server.

def setup_connection(ip, port):
    # ...

Send and Receive Packets: Handles sending and receiving packets to/from the SSH server.

def send_packet(sock, packet_type, data):
    # ...

SSH Version Exchange: Initiates the SSH handshake by sending and receiving the SSH version string.

def send_ssh_version(sock):
    # ...
def receive_ssh_version(sock):
    # ...

Key Exchange Init (KEX_INIT): Sends and receives the key exchange initialization packet.

def send_kex_init(sock):
    # ...
def receive_kex_init(sock):
    # ...

Perform SSH Handshake: Combines the above steps to complete the SSH handshake.

def perform_ssh_handshake(sock):
    # ...

Heap Preparation: Sends a series of packets to manipulate the heap state on the server.

def prepare_heap(sock):
    # ...

Fake File Structure: Creates fake file structures to exploit the memory corruption vulnerability.

def create_fake_file_structure(data, glibc_base):
    # ...

Measure Parsing Time: Measures the time taken by the server to parse certain packets, helping to time the final exploit correctly.

def time_final_packet(sock):
    # ...

Public Key Packet: Crafts a packet containing the exploit payload, including the shellcode.

def create_public_key_packet(packet, size, glibc_base):
    # ...

Race Condition Exploit: Attempts to exploit the race condition by timing the final packet correctly.

def attempt_race_condition(sock, parsing_time, glibc_base):
    # ...

Main Function: Coordinates the overall exploit process, including multiple attempts with different glibc bases.

def main():
    # ...

Exploitation Workflow

Additional Considerations

Summary

CVE-2024-6387 represents a severe vulnerability in OpenSSH that allows remote code execution. The provided Python script exploits this vulnerability by manipulating the heap and timing packet sends to cause memory corruption, ultimately executing the attacker's shellcode on the server. The script demonstrates typical exploit development techniques, including heap spraying, memory corruption, and precise timing for race conditions.