🇰🇷 한글 설명
Windows 환경에서 Python 빌드 시 사용되는 VPATH 변수가 설치 디렉토리 외부의 경로를 참조하여 발생합니다. 저권한 사용자가 특정 랜드마크 파일과 Lib 폴더를 생성함으로써 권한 상승을 유도할 수 있는 취약점입니다.
💡 쉬운 설명
파이썬이 설치된 위치보다 더 높은 상위 폴더를 확인하는 과정에서 보안 허점이 발생합니다. 해커가 특정 폴더를 미리 만들어두면, 일반 사용자가 관리자 권한을 가진 프로그램처럼 동작하게 만들 수 있습니다.
🇺🇸 원문 (English)
To allow builds of Python to be run from an in-tree layout (rather than
an installed file layout), the VPATH variable is defined at build time
and used to locate certain landmarks - specifically,
Modules/setup.local. When this landmark is found relative to VPATH
relative to the executable, Python assumes it is running in a source
tree and generates a different default sys.path. This code remains in
release builds, so that release-ready builds can be built in-tree.
On Windows, since builds are written to 'PCbuild/', the value of
VPATH is set to '..\..', which results in a landmark of
'..\..\Modules\setup.local'. This path is outside the install directory
of Python, and may have different permissions, potentially allowing a
low-privilege user to create the landmark and an alternative `Lib`
folder that will be discovered by an otherwise restricted install.
Such a setup occurs with the legacy default install location for all
users (in the now superseded EXE installer), due to how Windows allows
all users to create folders in the root directory of their OS drive.
Our recommended mitigation on Windows is to migrate away from the
legacy installer and use the new [Python install
manager](https://www.python.org/downloads/latest/pymanager/) to install
for the current user. Installs where the directory two levels above the
Python installation directory have equivalent permissions are unaffected
(in general, a per-user install cannot be modified at all by other
users, removing any escalation of privilege risk, and could be directly
modified by a privileged user, making the potential tampering
irrelevant). Alternative mitigations might include preemptively creating
and restricting access to a `Modules` directory. Be aware that only 3.13
and 3.14 will receive updated legacy installers - earlier fixes are only
provided as sources.
Platforms other than Windows allow VPATH to be overridden, but as they
don't usually use a separated directory in the build for binaries, are
unlikely to have a landmark reference outside of the install directory.
The landmark detection involving VPATH is a fallback for when a more
specific landmark - .\pybuilddir.txt - is absent, and was included for
compatibility. Future releases of Python will no longer include the
fallback, and so builds will need to generate or preserve the
pybuilddir.txt file in order to work in-tree. This landmark file has
been generated on Windows since 3.11, and on other platforms for longer.
📍 영향받는 시스템
Windows 환경의 레거시 EXE 설치 프로그램을 사용하는 Python 버전 (3.13 및 3.14 업데이트 예정)
⚔️ 공격 벡터
Windows 루트 디렉토리 권한을 이용해 설치 경로 상위의 Modules/setup.local 및 Lib 폴더를 조작
🛡️ 대응 방법
레거시 설치 프로그램 대신 사용자 전용 Python 설치 관리자(PyManager)를 사용하여 설치
🔧 검증 코드
설치된 Python 버전을 확인하여 취약한 레거시 설치 방식 사용 여부를 판단합니다.