T03 · Remote Payload Retrieval and Execution
Error
- Location
- assets/project-tunnel.sh:521
- Finding
- Unverified Mutable Native Binary Is Downloaded and Executed<![CDATA[ ## Vulnerability Details **File Location**: `assets/project-tunnel.sh:521-554`, with execution at `assets/project-tunnel.sh:982-995` and `assets/project-tunnel.sh:1130-1133` **Vulnerability Type**: Unverified remote payload retrieval and execution **Risk Level**: Critical ### Vulnerable Code ```bash ensure_agent_binary() { local platform asset release_base url tmp platform="$(detect_platform)" AGENT_EXT="" if [[ "${platform}" == windows-* ]]; then AGENT_EXT=".exe" fi AGENT_GITHUB_REPO="${AGENT_GITHUB_REPO:-ChangfengHU/tunneling}" AGENT_VERSION="${AGENT_VERSION:-latest}" AGENT_RELEASE_BASE="${AGENT_RELEASE_BASE:-https://github.com/${AGENT_GITHUB_REPO}/releases}" AGENT_DIR="${AGENT_DIR:-${HOME}/.tunneling/bin}" mkdir -p "${AGENT_DIR}" AGENT_BIN="${AGENT_BIN:-${AGENT_DIR}/agent${AGENT_EXT}}" FORCE_AGENT_DOWNLOAD="${FORCE_AGENT_DOWNLOAD:-0}" if [[ "${FORCE_AGENT_DOWNLOAD}" != "1" && -f "${AGENT_BIN}" ]]; then if [[ "${AGENT_EXT}" == ".exe" || -x "${AGENT_BIN}" ]]; then return 0 fi fi asset="agent-${platform}${AGENT_EXT}" if [[ "${AGENT_VERSION}" == "latest" ]]; then url="${AGENT_RELEASE_BASE}/latest/download/${asset}" else url="${AGENT_RELEASE_BASE}/download/${AGENT_VERSION}/${asset}" fi echo "[agent] downloading ${asset}" tmp="${AGENT_BIN}.tmp" rm -f "${tmp}" curl -fL --retry 3 --retry-delay 1 -o "${tmp}" "${url}" mv "${tmp}" "${AGENT_BIN}" chmod +x "${AGENT_BIN}" || true echo "[agent] ready: ${AGENT_BIN}" } ``` The downloaded file is subsequently placed in a generated runner and executed: ```bash cat > "${MACHINE_AGENT_RUNNER}" <<EOF_RUNNER #!/usr/bin/env bash set -euo pipefail export PATH='${PATH_VALUE}' exec '${AGENT_BIN}' \ -server '${AGENT_SERVER}' \ -token '${ttoken}' \ -route-sync-url '${AGENT_ROUTE_SYNC_URL}' \ -tunnel-id '${tid}' \ -tunnel-token '${ttoken}' \ -admin-addr '${MACHINE_AGENT_ADMIN_ADDR}' \ -config '${MACHINE_AGENT_CONFIG}' EOF_RUNNER ch ...[truncated 1862 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Bundle an audited agent binary with the Skill where feasible. 2. Otherwise, pin an immutable release version rather than using `latest`. 3. Publish trusted SHA-256 hashes independently and verify the selected artifact before moving or executing it. 4. Prefer signed artifacts and validate the signature against a pinned publisher key. 5. Download to a securely created temporary file and reject symbolic links or unexpected file types. 6. Require explicit user approval before the first download and before replacing an installed binary. 7. Record and display the artifact version, source URL, hash, and verification result. 8. Run the tunnel agent with sandboxing and the minimum filesystem and network access required. ]]>
