T08 · Insecure Dependencies
Warning
- Location
- scripts/wp.sh:190
- Finding
- Untrusted Python Module Loading Can Execute Attacker-Controlled Code with WordPress Credentials<![CDATA[ ## Vulnerability Details **File Location**: `scripts/wp.sh:190-199`; `scripts/wp-upload.sh:40-58`; `scripts/wp-upload.sh:86-96` **Vulnerability Type**: Untrusted dependency resolution and Python import-path hijacking **Risk Level**: Medium ### Vulnerable Code From `scripts/wp.sh:190-199`: ```bash if python3 -c "import curl_cffi" 2>/dev/null; then RESPONSE=$(WP_METHOD="$METHOD" WP_URL_FULL="$URL" WP_BODY="$BODY" \ WP_AUTH_USER="$WP_USER" WP_AUTH_PW="$WP_APP_PASSWORD" python3 - <<'PY' import os from curl_cffi import requests m=os.environ["WP_METHOD"]; url=os.environ["WP_URL_FULL"]; body=os.environ.get("WP_BODY","") auth=(os.environ["WP_AUTH_USER"], os.environ["WP_AUTH_PW"].replace(" ","")) kw=dict(impersonate="chrome", auth=auth, headers={"Content-Type":"application/json"}, timeout=60) if body and m!="GET": kw["data"]=body.encode() print(requests.request(m, url, **kw).text) PY ) ``` From `scripts/wp-upload.sh:40-58`: ```bash if python3 -c "import curl_cffi" 2>/dev/null; then RESPONSE=$(WP_FILE="$FILE_PATH" WP_NAME="$FILENAME" WP_MIME="$MIME" \ WP_URL_FULL="${WP_URL}/wp-json/wp/v2/media" \ WP_AUTH_USER="$WP_USER" WP_AUTH_PW="$WP_APP_PASSWORD" python3 - <<'PY_UP' import os from curl_cffi import requests auth = (os.environ["WP_AUTH_USER"], os.environ["WP_AUTH_PW"].replace(" ", "")) name, mime = os.environ["WP_NAME"], os.environ["WP_MIME"] r = requests.post( os.environ["WP_URL_FULL"], auth=auth, impersonate="chrome", headers={ "Content-Disposition": 'attachment; filename="%s"' % name, "Content-Type": mime, "Accept": "application/json", }, data=open(os.environ["WP_FILE"], "rb").read(), timeout=300, ) print(r.text) PY_UP ) ``` From `scripts/wp-upload.sh:86-96`: ```bash if python3 -c "import curl_cffi" 2>/dev/null; then WP_ALT="$ALT_TEXT" \ WP_URL_FULL="${WP_URL}/wp-json/wp/v2/media/${MEDIA_ID}" \ WP_AUTH_USER="$WP_USER" WP_AUTH_PW="$WP_APP_PASSWORD" python3 - <<'PY_ALT' > /dev/null impor ...[truncated 3048 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Run every Python invocation in isolated mode: ```bash python3 -I -c 'import curl_cffi' python3 -I - <<'PY' ... PY ``` 2. Remove attacker-controlled Python configuration from the subprocess environment: ```bash env -u PYTHONPATH -u PYTHONHOME -u PYTHONSTARTUP python3 -I ... ``` 3. Resolve and verify the package before using it. Refuse packages loaded from the current directory, writable temporary directories, or user-controlled project paths. 4. Pin `curl_cffi` to an audited version and installation source. Prefer a dedicated virtual environment whose directory and package files are not writable by untrusted users. 5. Avoid importing the module twice. Use one isolated Python process to perform dependency validation and the request. 6. Consider using only the existing `curl` transport. This removes the Python dependency-loading attack surface if browser impersonation is not strictly necessary. 7. Add tests that create a fake `curl_cffi.py` in the invocation directory and set a malicious `PYTHONPATH`, then verify that neither source is imported. 8. Continue using a least-privileged WordPress application-password account so that theft of the credential does not automatically grant site-administrator capabilities. ]]>
