T07 · Tool Hijacking and Spoofing
Error
- Location
- scripts/install-openclaw-runtime-hook.sh:21
- Finding
- Persistent sudo interception through PATH modification<![CDATA[ ## Vulnerability Details **File Location**: `scripts/install-openclaw-runtime-hook.sh:21-57, 61-81` **Vulnerability Type**: Persistent tool hijacking **Risk Level**: High ### Vulnerable Code ```bash OPENCLAW_DIR="${HOME}/.openclaw" BIN_DIR="${OPENCLAW_DIR}/bin" SKILL_DIR_DEFAULT="${OPENCLAW_DIR}/workspace/skills/cyber-security-engineer" mkdir -p "${BIN_DIR}" chmod 700 "${OPENCLAW_DIR}" "${BIN_DIR}" || true WRAPPER="${BIN_DIR}/sudo" cat > "${WRAPPER}" <<EOF #!/usr/bin/env bash set -euo pipefail REAL_SUDO="\${OPENCLAW_REAL_SUDO:-${REAL_SUDO}}" SKILL_DIR="\${OPENCLAW_CYBER_SKILL_DIR:-${SKILL_DIR_DEFAULT}}" # Pass-through for sudo bookkeeping. if [[ \$# -eq 0 ]]; then exec "\${REAL_SUDO}" fi case "\${1:-}" in -h|--help|-V|--version|-v|-l|-k) exec "\${REAL_SUDO}" "\$@" ;; esac # Refuse non-interactive privilege escalation by default (safety). if [[ ! -t 0 && "\${OPENCLAW_ALLOW_NONINTERACTIVE_SUDO:-0}" != "1" ]]; then echo "[cyber-security-engineer] Refusing non-interactive sudo (set OPENCLAW_ALLOW_NONINTERACTIVE_SUDO=1 to override)." >&2 exit 2 fi REASON="\${OPENCLAW_PRIV_REASON:-OpenClaw requested privileged execution}" export OPENCLAW_REAL_SUDO="\${REAL_SUDO}" exec python3 "\${SKILL_DIR}/scripts/guarded_privileged_exec.py" \\ --reason "\${REASON}" \\ --use-sudo \\ -- "\$@" EOF chmod 755 "${WRAPPER}" log "Installed sudo shim: ${WRAPPER}" ``` ```bash if [[ "$(uname -s)" == "Darwin" ]]; then PLIST="${HOME}/Library/LaunchAgents/ai.openclaw.gateway.plist" if [[ -f "${PLIST}" ]] && command -v /usr/libexec/PlistBuddy >/dev/null 2>&1; then # Ensure EnvironmentVariables exists and prepend ~/.openclaw/bin to PATH. /usr/libexec/PlistBuddy -c "Add :EnvironmentVariables dict" "${PLIST}" 2>/dev/null || true EXISTING_PATH="$(/usr/libexec/PlistBuddy -c "Print :EnvironmentVariables:PATH" "${PLIST}" 2>/dev/null || true)" if [[ -z "${EXISTING_PATH}" ]]; then NEW_PATH="${BIN_DIR}:/usr/bin:/bin:/usr/sbin:/sbin" ...[truncated 2780 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Do not shadow the system `sudo` executable through `PATH`. - Use an explicitly named command, such as `openclaw-guarded-exec`, or a dedicated privileged broker API. - Keep the privileged broker outside a user-writable workspace and verify its ownership, permissions, and cryptographic integrity before each use. - Require explicit installation approval and display every persistent file or LaunchAgent modification before applying it. - Add a verified uninstall procedure that removes the shim and restores the original LaunchAgent `PATH`. - Resolve the real `sudo` binary to a trusted absolute system path and reject environment-based overrides in privileged contexts. - Restrict the gateway environment so untrusted processes cannot modify the wrapper, referenced Skill directory, or relevant environment variables. ]]>
