Exploit database

GH-6b32cd982de5b90cd0d02d8d31cf1b17

try2take/cve-2026-97631-poc

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-97631

3 sources

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

Repository files5
try2take/cve-2026-97631-pocRevision 845545e947bc

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

pxe-lab-public/lab.sh

Shell · 9,633 bytes
#!/usr/bin/env bash
set -euo pipefail
ROOT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)
if [[ ${1:-} == --internal-run ]]; then
    shift
    pidfile=$1
    ackfile=$2
    shift 2
    printf '%s\n' "$$" > "$pidfile"
    for ((attempt=0; attempt<100; attempt++)); do
        if [[ -f $ackfile ]]; then exec "$@"; fi
        sleep 0.05
    done
    exit 1
fi
RUNNER="$ROOT/lab_run.sh"
if [[ ${1:-} == --help || ${1:-} == -h ]]; then
    cat <<'HELP'
Usage: ./lab.sh [lab_run.sh options]

1 — start, 2 — restart, 3 — stop, 4 — exit.
The VM console opens in a separate terminal if available.
Otherwise, output is saved to a temporary log.
Options are passed to lab_run.sh; see ./lab_run.sh --help.
HELP
    exit 0
fi
command -v setsid >/dev/null 2>&1 || { printf 'setsid is required (usually provided by util-linux).\n' >&2; exit 1; }
[[ -x $RUNNER ]] || { printf 'Executable not found: %s\n' "$RUNNER" >&2; exit 1; }
state=$(mktemp -d "${TMPDIR:-/tmp}/pxe-menu.XXXXXXXX")
pid=
stamp=
run_number=0
original_args=("$@")
terminal=()
root_console=0
console_dirs=()
if [[ -n ${DISPLAY:-} || -n ${WAYLAND_DISPLAY:-} || ( $EUID -eq 0 && -n ${SUDO_UID:-} && -S /run/user/${SUDO_UID}/bus ) ]]; then
    for candidate in ptyxis gnome-terminal kgx konsole xfce4-terminal xterm; do
        if command -v "$candidate" >/dev/null 2>&1; then
            case "$candidate" in
                ptyxis) terminal=("$candidate" --new-window --) ;;
                gnome-terminal|kgx) terminal=("$candidate" --) ;;
                konsole) terminal=("$candidate" --new-window -e) ;;
                xfce4-terminal) terminal=("$candidate" -x) ;;
                xterm) terminal=("$candidate" -e) ;;
            esac
            break
        fi
    done
fi
if [[ $EUID -eq 0 ]]; then
    if ((${#terminal[@]})) && [[ ${SUDO_UID:-} =~ ^[0-9]+$ && ${SUDO_GID:-} =~ ^[0-9]+$ && -n ${SUDO_USER:-} ]] && command -v runuser >/dev/null && command -v socat >/dev/null && [[ $(id -u "$SUDO_USER" 2>/dev/null || true) == "$SUDO_UID" ]]; then
        root_console=1
    else
        terminal=()
    fi
fi

process_stamp() {
    local line rest
    if [[ ! -r /proc/$1/stat ]]; then
        ps -o lstart= -p "$1" 2>/dev/null
        return
    fi
    IFS= read -r line < "/proc/$1/stat" || return 1
    rest=${line##*) }
    set -- $rest
    (($# >= 20)) || return 1
    shift 19
    printf '%s' "$1"
}
is_running() {
    [[ -n $pid && -n $stamp ]] || return 1
    [[ $(process_stamp "$pid" 2>/dev/null || true) == "$stamp" ]] || return 1
    kill -0 "$pid" 2>/dev/null || return 1
    [[ $(ps -o stat= -p "$pid" 2>/dev/null || true) != *Z* ]]
}
stop_lab() {
    if ! is_running; then
        pid=; stamp=
        printf 'Lab stopped.\n'
        return 0
    fi
    printf 'Stopping lab (PID %s)…\n' "$pid"
    kill -TERM -- "-$pid" 2>/dev/null || true
    local count
    for ((count=0; count<100; count++)); do
        if ! is_running; then
            pid=; stamp=
            printf 'Lab stopped.\n'
            return 0
        fi
        sleep 0.05
    done
    printf 'Process is still running; try stopping it again.\n' >&2
    return 1
}
cleanup() {
    if [[ -n $pid ]]; then stop_lab || true; fi
    local dir
    for dir in "${console_dirs[@]}"; do
        rm -f -- "$dir/console.sock"
        rmdir -- "$dir" 2>/dev/null || true
    done
    rm -rf -- "$state"
}
trap cleanup EXIT
trap 'exit 130' INT
trap 'exit 143' TERM
trap 'exit 129' HUP

start_lab() {
    if is_running; then printf 'Lab is already running (PID %s).\n' "$pid"; return; fi
    pid=; stamp=
    run_number=$((run_number + 1))
    local pidfile="$state/pid-$run_number" output="$state/console-$run_number.log"
    local -a args=("${original_args[@]}")
    local i target suffix
    if ((run_number > 1)); then
        for ((i=0; i<${#args[@]}; i++)); do
            if [[ ${args[i]} == --pcap && $((i + 1)) -lt ${#args[@]} ]]; then
                target=${args[i+1]}; suffix=$run_number
                while [[ -e $target.$suffix || -L $target.$suffix ]]; do suffix=$((suffix + 1)); done
                args[i+1]="$target.$suffix"
                printf 'Capture: %s\n' "${args[i+1]}"
                break
            fi
        done
    fi
    local console_dir= console_socket=
    local -a runner=("$RUNNER" "${args[@]}")
    if ((root_console)); then
        console_dir=$(mktemp -d "${TMPDIR:-/tmp}/pxe-console.XXXXXXXX")
        console_dirs+=("$console_dir")
        if ! chown "$SUDO_UID:$SUDO_GID" "$console_dir"; then
            printf 'Could not prepare the console directory.\n' >&2
            return
        fi
        console_socket="$console_dir/console.sock"
        runner=(env "LAB_CONSOLE_SOCKET=$console_socket" "$RUNNER" "${args[@]}")
    fi
    local -a command=(setsid --wait "$ROOT/lab.sh" --internal-run "$pidfile" "$pidfile.ok" "${runner[@]}")
    if ((${#terminal[@]})) && (( !root_console )); then
        "${terminal[@]}" "${command[@]}" </dev/null >/dev/null 2>&1 &
        printf 'Opening VM terminal.\n'
    else
        "${command[@]}" </dev/null >"$output" 2>&1 &
        if ((root_console)); then
            printf 'Startup log: %s\n' "$output"
        else
            printf 'Separate terminal unavailable; output: %s\n' "$output"
        fi
        if [[ $EUID -eq 0 ]]; then
            printf 'View in another terminal: sudo tail -f %q\n' "$output"
        else
            printf 'View in another terminal: tail -f %q\n' "$output"
        fi
    fi
    local count
    for ((count=0; count<100; count++)); do
        if [[ -s $pidfile ]]; then
            IFS= read -r pid < "$pidfile" || true
            if [[ $pid =~ ^[0-9]+$ ]]; then
                stamp=$(process_stamp "$pid" 2>/dev/null || true)
                if is_running; then
                    : > "$pidfile.ok"
                    if [[ $EUID -eq 0 ]]; then
                        local bridge_mode=0
                        for ((i=0; i+1<${#args[@]}; i++)); do
                            if [[ ${args[i]} == --network && ${args[i+1]} == bridge ]]; then bridge_mode=1; fi
                        done
                        if ((bridge_mode)); then
                            printf 'Waiting for network namespace setup…\n'
                            for ((count=0; count<200; count++)); do
                                if grep -Fq 'PXE lab: namespace ' "$output"; then break; fi
                                if ! is_running; then
                                    printf 'Lab startup failed:\n' >&2
                                    cat "$output" >&2
                                    pid=; stamp=
                                    return
                                fi
                                sleep 0.05
                            done
                            if ! grep -Fq 'PXE lab: namespace ' "$output"; then
                                printf 'Network setup timed out after 10 seconds. Log: %s\n' "$output" >&2
                                stop_lab || true
                                return
                            fi
                        fi
                    fi
                    if ((root_console)); then
                        for ((count=0; count<200; count++)); do
                            if [[ -S $console_socket ]]; then break; fi
                            if ! is_running; then break; fi
                            sleep 0.05
                        done
                        if [[ -S $console_socket ]]; then
                            local runtime=/run/user/$SUDO_UID desktop_pid
                            if [[ ! -S $runtime/bus ]]; then runtime=${XDG_RUNTIME_DIR:-$runtime}; fi
                            runuser -u "$SUDO_USER" -- env \
                                XDG_RUNTIME_DIR="$runtime" DBUS_SESSION_BUS_ADDRESS="unix:path=$runtime/bus" \
                                DISPLAY="${DISPLAY:-:0}" WAYLAND_DISPLAY="${WAYLAND_DISPLAY:-wayland-0}" \
                                "${terminal[@]}" socat -,raw,echo=0 "UNIX-CONNECT:$console_socket" \
                                </dev/null >>"$output" 2>&1 &
                            desktop_pid=$!
                            sleep 0.3
                            if ! kill -0 "$desktop_pid" 2>/dev/null; then
                                if wait "$desktop_pid"; then
                                    printf 'Opening QEMU console terminal.\n'
                                else
                                    printf 'Could not open terminal. Details: %s\n' "$output" >&2
                                fi
                            else
                                printf 'Opening QEMU console terminal.\n'
                            fi
                        else
                            printf 'Console socket did not appear; check log %s.\n' "$output" >&2
                        fi
                    fi
                    printf 'Lab started (PID %s).\n' "$pid"
                    return
                fi
            fi
            break
        fi
        sleep 0.05
    done
    pid=; stamp=
    printf 'Could not start lab. Check the terminal and dependencies.\n' >&2
}

printf 'PXE lab control\n'
while :; do
    if is_running; then status="running, PID $pid"; else status='stopped'; fi
    printf '\nStatus: %s\n1. Start\n2. Restart\n3. Stop\n4. Exit\nChoice: ' "$status"
    if ! IFS= read -r choice; then printf '\n'; break; fi
    case "$choice" in
        1) start_lab ;;
        2) if stop_lab; then start_lab; fi ;;
        3) stop_lab || true ;;
        4) if stop_lab; then break; fi ;;
        *) printf 'Enter 1, 2, 3 or 4.\n' ;;
    esac
done