T03 · Remote Payload Retrieval and Execution
- Location
scripts/ensure_env.py:278- Finding
Remote Python Bootstrap Is Downloaded and Executed Without TLS or Integrity Verification
- Content
View full analysis
Vulnerability Details
File Location:
scripts/ensure_env.py:278-298
Vulnerability Type: Unverified remote code retrieval and execution
Risk Level: HighVulnerable Code
python get_pip_path = os.path.join(tempfile.gettempdir(), "get-pip.py") urls = [ "https://mirrors.huaweicloud.com/repository/pypi/simple/get-pip.py", "https://bootstrap.pypa.io/get-pip.py", ] ctx = ssl._create_unverified_context() for url in urls: info(f"尝试下载 get-pip.py: {url}") try: urllib.request.urlretrieve(url, get_pip_path, context=ctx) except Exception as e: print(f" 下载失败: {e}") continue rc, out, err = run_cmd([sys.executable, get_pip_path], timeout=120) if rc == 0: ok("get-pip.py 安装 pip 成功") return TrueThe module also globally changes the default HTTPS behavior:
python ssl._create_default_https_context = ssl._create_unverified_contextTechnical Analysis
The Skill instructions require the environment-check wrapper to run before performing queries (
SKILL.md:73-80andSKILL.md:104-107). That wrapper invokesensure_env.py.If
pipis unavailable and the localensurepipattempt fails,_ensure_pip()downloadsget-pip.pyfrom an external URL. The download explicitly uses an SSL context that does not validate the remote server's certificate. The resulting file is then executed immediately usingsys.executable, without checking a cryptographic hash or signature.Consequently, possession of any certificate is sufficient to impersonate the intended download server. This converts attacker-controlled network content directly into local Python code execution. The predictable temporary filename adds local hardening concerns, but the confirmed network-to-execution path exists independently of a local race.
Attack Path
- The user invokes the Skill, whose documented workflow requires running
scripts/check_env.shorscripts/check_env.ps1. - The wrapper launches ...[truncated 1259 chars]
- The user invokes the Skill, whose documented workflow requires running
- Remediation
View remediation
Remediation Suggestions
- Remove both uses of unverified SSL contexts:
- Delete the assignment to
ssl._create_default_https_context. - Do not pass
_create_unverified_context()tourlretrieve.
- Delete the assignment to
- Use the operating system's trusted CA store and fail closed on certificate-validation errors.
- Prefer a locally provided
ensurepipinstallation path instead of downloading and executing a bootstrap script. - If a remote bootstrap is unavoidable:
- Pin an expected SHA-256 or stronger digest.
- Download to a securely created file using
tempfile.NamedTemporaryFile. - Verify the digest or a trusted digital signature before execution.
- Delete the temporary file in a
finallyblock.
- Do not automatically fall back to another executable source after a verification failure.
- Present a clear error requiring manual remediation if the verified installation process cannot continue.
- Remove both uses of unverified SSL contexts:
