PyInstaller объединяет приложение Python и все его зависимости в единый пакет. Из-за специальной записи, добавленной в sys.path во время процесса загрузки приложения PyInstaller-замороженного, и из-за сценария загрузки, пытающегося загрузить дополнительный модуль для расшифровки байт-кода, пока эта запись все еще присутствует в sys.path, приложение, построенное с PyInstaller < 6.0.0, может быть обмануно непривилегированным злоумышленником в выполнении произвольного кода python, когда ** все условия. Во-первых, приложение построено с PyInstaller < 6.0.0; затрагиваются режимы как onedir, так и onefile.
Во-вторых, дополнительная функция шифрования байт-кода не была включена во время сборки приложения. В-третьих, злоумышленник может создавать файлы/каталоги в том же каталоге, где находится исполняемый файл. В-четвертых, файловая система поддерживает создание файлов/каталогов, которые содержат ? в своем названии (т.е. системы, не относящиеся к Windows).
В-пятых, злоумышленнику удаётся определить смещение, при котором архив PYZ встраивается в исполняемый файл. Злоумышленник может создать каталог (или zip-архив) рядом с исполняемым файлом, с именем, которое соответствует формату, используемому загрузчиком PyInstaller для передачи информации о местоположении архива PYZ в скрипт bootstrap. Если этот каталог (или zip-архив) содержит модуль python, имя которого соответствует имени, используемому дополнительной функцией шифрования байт-кода, этот модуль будет загружен и выполнен скриптом bootstrap (в отсутствие реального встроенного модуля, доступного при включении функции шифрования байт-кода).
Это приводит к произвольному выполнению кода, которое не требует изменения самого исполняемого файла. Если исполняемый файл выполняется с повышенными привилегиями (например, из-за наличия бита setuid), код в вводимом модуле также выполняется с указанными повышенными привилегиями, что приводит к локальному увеличению привилегий. PyInstaller 6.0.0 (f5adf291c8b832d5aff7632844f7e3ddf7ad4923) убрал поддержку шифрования байт-кода; это эффективно удаляет описанный вектор атаки, из-за того, что скрипт bootstrap больше не пытается загрузить дополнительный модуль для дешифрования байт-кода. PyInstaller 6.10.0 (cfd60b510f95f92cb81fc42735c399bb781a4739) переработал процесс загрузки, чтобы избежать (ab)использования sys.path для передачи местоположения архива PYZ, что дополнительно исключает возможность описанной процедуры инъекции. Если обновление PyInstaller неосуществимо, эта проблема может быть решена путем обеспечения надлежащих разрешений на каталоги, содержащие чувствительные к безопасности исполняемые файлы (т.е. исполняемые файлы с набором битов setuid), что должно смягчить проблему.
Показать оригинальное описание (EN)
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.
Характеристики атаки
Последствия
Строка CVSS v4.0