🇰🇷 한글 설명
PyInstaller < 6.0.0에서 bootstrap 과정 중 sys.path 조작으로 인해 임의의 Python 코드가 실행될 수 있습니다. 공격자가 실행 파일 디렉토리에 특정 형식의 디렉토리/파일을 생성하여 악의적 모듈을 로드하도록 유도할 수 있으며, setuid 비트가 설정된 경우 권한 상승이 가능합니다.
💡 쉬운 설명
PyInstaller로 만든 프로그램이 프로그램이 있는 폴더에서 플러그인을 찾을 때 가짜 파일을 실행할 수 있습니다. 공격자가 폴더에 특별한 이름의 파일을 놓으면 프로그램이 실행할 수 있습니다.
🇺🇸 원문 (English)
PyInstaller bundles a Python application and all its dependencies into a single package. Due to a special entry being appended to `sys.path` during the bootstrap process of a PyInstaller-frozen application, and due to the bootstrap script attempting to load an optional module for bytecode decryption while this entry is still present in `sys.path`, an application built with PyInstaller < 6.0.0 may be tricked by an unprivileged attacker into executing arbitrary python code when **all** of the following conditions are met. First, the application is built with PyInstaller < 6.0.0; both onedir and onefile mode are affected. Second, the optional bytecode encryption code feature was not enabled during the application build. Third, the attacker can create files/directories in the same directory where the executable is located. Fourth, the filesystem supports creation of files/directories that contain `?` in their name (i.e., non-Windows systems). Fifth, the attacker is able to determine the offset at which the PYZ archive is embedded in the executable. The attacker can create a directory (or a zip archive) next to the executable, with the name that matches the format used by PyInstaller's bootloader to transmit information about the location of PYZ archive to the bootstrap script. If this directory (or zip archive) contains a python module whose name matches the name used by the optional bytecode encryption feature, this module will be loaded and executed by the bootstrap script (in the absence of the real, built-in module that is available when the bytecode-encryption feature is enabled). This results in arbitrary code execution that requires no modification of the executable itself. If the executable is running with elevated privileges (for example, due to having the `setuid` bit set), the code in the injected module is also executed with the said elevated privileges, resulting in a local privilege escalation. PyInstaller 6.0.0 (f5adf291c8b832d5aff7632844f7e3ddf7ad4923) removed support for bytecode encryption; this effectively removes the described attack vector, due to the bootstrap script not attempting to load the optional module for bytecode-decryption anymore. PyInstaller 6.10.0 (cfd60b510f95f92cb81fc42735c399bb781a4739) reworked the bootstrap process to avoid (ab)using `sys.path` for transmitting location of the PYZ archive, which further eliminates the possibility of described injection procedure. If upgrading PyInstaller is not feasible, this issue can be worked around by ensuring proper permissions on directories containing security-sensitive executables (i.e., executables with `setuid` bit set) should mitigate the issue.
📍 영향받는 시스템
PyInstaller < 6.0.0 (onedir/onefile 모드, bytecode 암호화 미적용)
⚔️ 공격 벡터
실행 파일 디렉토리에 PYZ 아카이브 위치 정보 형식의 디렉토리/zip 생성 후 악성 Python 모듈 주입
🛡️ 대응 방법
PyInstaller를 6.10.0 이상으로 업그레이드하거나 setuid 실행 파일의 디렉토리 권한 제한
🔧 검증 코드
6.10.0 이상: 안전, 6.0.0~6.10.0 미만: 부분 취약, 6.0.0 미만: 완전 취약
pip show pyinstaller 2>/dev/null | grep Version || python -c "import PyInstaller; print(PyInstaller.__version__)" 2>/dev/null