T03 · Remote Payload Retrieval and Execution
- Location
scripts/ensure_env.py:275- Finding
Unverified Remote Python Bootstrap Is Downloaded and Executed
- Content
View full analysis
Vulnerability Details
File Location:
scripts/ensure_env.py, lines 275–294
Vulnerability Type: Unauthenticated remote payload 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)The file also globally replaces Python's default HTTPS context at line 25:
python ssl._create_default_https_context = ssl._create_unverified_contextTechnical Analysis
The mandatory environment setup attempts to bootstrap
pipwhen neitherpipnorensurepipis available. It downloads a Python program from one of two external URLs while explicitly constructing an SSL context that does not authenticate the remote certificate. The module additionally replaces the process-wide default HTTPS context with an unverified context.After downloading the response to a predictable temporary path, the setup passes that file directly to the current Python interpreter. There is no cryptographic digest, signature, or content verification between retrieval and execution.
This creates a direct trust-boundary transition from a network response to local code execution. An attacker able to intercept the network connection, control a relevant proxy, or otherwise present an untrusted TLS endpoint can substitute arbitrary Python code for the expected bootstrap script.
This is a security defect rather than evidence that the project author intentionally supplies a malicious payload. The conf ...[truncated 1839 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove the process-wide TLS override:
python ssl._create_default_https_context = ssl._create_unverified_context - Do not create or pass an unverified SSL context. Use Python's default authenticated TLS configuration.
- Prefer failing safely with documented manual installation instructions when both
pipandensurepipare unavailable. - If automatic bootstrapping is required, retrieve the bootstrap artifact only from an authenticated canonical source.
- Pin an expected SHA-256 digest or verify a trusted digital signature before execution.
- Create the temporary file securely with a restrictive mode and remove it in a
finallyblock. - Abort installation if certificate, signature, or digest verification fails; do not silently continue to another unauthenticated execution source.
- Add tests that confirm downloads fail for expired, mismatched, self-signed, and otherwise untrusted certificates.
- Remove the process-wide TLS override:
