🇰🇷 한글 설명
optimate 프로젝트의 neural_magic_training.py 스크립트에서 _load_model() 함수가 사용자 입력 디렉토리의 module.py 파일을 검증 없이 exec()로 직접 실행하여 임의 코드 실행 취약점을 야기한다. --model 인자로 디렉토리 경로를 제공하면 그 안의 module.py 파일이 검증 없이 실행되므로 공격자가 악의적인 파일을 주입하여 프로세스 권한으로 임의 코드를 실행할 수 있다.
💡 쉬운 설명
optimate 프로젝트에서 사용자가 제공한 폴더 경로로부터 Python 파일을 아무 검사 없이 실행하는 보안 결함이 있습니다. 공격자가 악의적인 Python 코드가 담긴 파일을 만들어 놓으면 그것이 자동으로 실행되어 전체 시스템을 장악할 수 있습니다.
🇺🇸 원문 (English)
The _load_model() function in the neural_magic_training.py script of the optimate project in commit a6d302f912b481c94370811af6b11402f51d377f (2024-07-21) allows arbitrary code execution. When a user supplies a directory path via the --model command-line argument, the function reads a module.py file from that directory and executes its contents directly using Python's exec() function. This design does not validate or sanitize the file's content, allowing an attacker who controls the input directory to execute arbitrary Python code in the context of the process running the script.
📍 영향받는 시스템
optimate 프로젝트 commit a6d302f912b481c94370811af6b11402f51d377f (2024-07-21) 이전의 모든 버전
⚔️ 공격 벡터
neural_magic_training.py 스크립트 실행 시 --model 인자로 공격자가 제어 가능한 디렉토리 경로 제공
🛡️ 대응 방법
exec() 함수 제거 및 importlib 등을 통한 안전한 모듈 로딩 메커니즘 구현, 또는 모듈 파일 서명 검증 실시
🔧 검증 코드
결과에서 exec() 함수와 _load_model()의 관계가 나타나면 사용자 입력이 검증 없이 exec()에 전달될 위험성을 확인할 수 있으며, 해당 줄의 앞뒤 코드를 검토하여 입력 검증 여부를 판단
grep -r 'exec(' . --include='neural_magic_training.py' 2>/dev/null | grep -v '#' | head -1