T07 · Tool Hijacking and Spoofing
Error
- Location
- source/data_visualizer.py:14
- Finding
- Arbitrary Code Execution Through an Attacker-Controlled Python Import Path<![CDATA[ ## Vulnerability Details **File Location**: `source/data_visualizer.py`, lines 14-21 **Vulnerability Type**: Python module search-path hijacking **Risk Level**: High ### Vulnerable Code ```python workspace_root = Path(__file__).resolve().parents[3] if str(workspace_root) not in sys.path: sys.path.insert(0, str(workspace_root)) try: from skills.shared.license_manager import LicenseValidator, LicenseVerificationError LICENSE_AVAILABLE = True except ImportError: ``` ### Technical Analysis The program derives a directory three levels above its own file and places that directory at the beginning of `sys.path`. In the audited deployment layout, the resulting directory is `/tmp`. Python gives the first matching location in `sys.path` precedence during module resolution. Consequently, the subsequent import of `skills.shared.license_manager` can load a module located under `/tmp/skills/shared/` rather than a trusted module distributed with the application. The imported module is not present in the audited project. Its top-level code would execute immediately when the visualization program starts. This creates a local module-hijacking condition whenever another user or process can create the expected package structure in the selected parent directory. ### Attack Path 1. An attacker obtains permission to create files under the shared `/tmp` directory. 2. The attacker creates `/tmp/skills/shared/license_manager.py` and any package files required by the active Python version. 3. The malicious module defines the names expected by the application so that the import appears successful. 4. A victim launches `source/data_visualizer.py`. 5. The application prepends `/tmp` to `sys.path`. 6. Python imports the attacker-controlled license module. 7. Top-level code in that module executes with the victim process's permissions before normal chart processing begins. ### Impact Assessment Successful exploitation provides arbitrary Python code execution ...[truncated 426 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Package the license-validation implementation inside the installed project and import it with a package-relative import. - Do not add `/tmp`, another shared writable directory, or a dynamically derived untrusted parent directory to `sys.path`. - Install the application as a proper Python package in an isolated virtual environment. - If an external shared module is unavoidable, resolve it from a fixed, administrator-controlled directory and verify ownership and permissions before loading it. - Consider launching Python with isolated-path protections where operationally appropriate. - Add a startup test that rejects module origins outside an explicit allowlist. After importing, the application can inspect the module's resolved file path and terminate if it is outside the trusted installation directory. ]]>
