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

Goal: 1000 CNY · Raised: 1000 CNY

100.0%

CVE-2022-22818 PoC — Django 跨站脚本漏洞

Source
Associated Vulnerability
Title:Django 跨站脚本漏洞 (CVE-2022-22818)
Description:The {% debug %} template tag in Django 2.2 before 2.2.27, 3.2 before 3.2.12, and 4.0 before 4.0.2 does not properly encode the current context. This may lead to XSS.
Description
This repo reproduce xss attack on django 4.0.1 (see CVE-2022-22818)
Readme
# Проверка у себя

Работает только на linux. На windows одна из зависимостей может вызвать ошибку.

Перед запуском необходимо установить следующие пакеты:

```bash
pip install -r requirements.txt
```

### Следует убедиться, что установились пакеты

```bash
python -m django --version  # pip install django==4.0.1
grammarinator-generate --version  # pip install git+https://github.com/renatahodovan/grammarinator.git#egg=grammarinator
```

### Подготовить фаззер

```bash
touch grammars/fuzzer/HTMLGenerator.py  # Создаём пустой файл, который будет наполнен генератом
grammarinator-process grammars/HTMLLexer.g4 grammars/HTMLParser.g4 -o grammars/fuzzer  # Заполнение файла
```

### Запуск фаззера

```bash
python runfuzz.py
```

# Ошибка

Нужно будет пропатчить один файл из django, поскольку он может вызвать ошибку шаблонизатора, что остановит процесс фаззинга:

```diff
--- /home/alex/.local/lib/python3.9/site-packages/django/template/defaultfilters.py     2023-04-26 12:47:44.387239988 +0300
+++ /home/alex/.local/lib/python3.9/site-packages/django/template/defaultfilters-fixed.py       2023-04-26 12:47:33.931039539 +0300
@@ -613,7 +613,10 @@
 @register.filter(is_safe=True)
 def random(value):
     """Return a random item from the list."""
-    return random_module.choice(value)
+    try:
+        return random_module.choice(value)
+    except IndexError:
+        return ''
 
 
 @register.filter("slice", is_safe=True)
```

Если используете venv, то путь может быть таким: `venv/lib/python3.9/site-packages/django/template/defaultfilters.py`

Если устанавливали пакеты в систему, то путь: `$HOME/.local/lib/python3.9/site-packages/django/template/defaultfilters.py`

Надо зайти во внутрь файла и найти определение тэга `random` и окружить его в try-catch блок. 

Если это не сделать, фаззер завершит свою работу при обнаружении [этого бага](https://code.djangoproject.com/ticket/34518).

# Benchmark

### Required tests count to find a bug

| Bug                | Plain fuzzer  | Fixed weights mode                       | Cooldown 0.5            |
|--------------------|---------------|------------------------------------------|-------------------------|
| debug              | 20            | 20                                       |                         |
| join-escape-filter | 1000+         | 560/3520(88s)/40/740(28s)/1800(51s)      | 20/900/220/760(530s)    |
File Snapshot

[4.0K] /data/pocs/730b89d861a334bc524af64da8b328082f51a5a7 ├── [4.8K] djangocontext.py ├── [ 105] globals.py ├── [4.0K] grammars │   ├── [4.0K] fuzzer │   │   ├── [ 15K] HTMLCustomGenerator.py │   │   ├── [1.2K] html.json │   │   ├── [1.5K] README.md │   │   ├── [ 534] weights.json │   │   └── [ 531] weights-no-debug.json │   ├── [5.5K] HTMLLexer.g4 │   └── [ 12K] HTMLParser.g4 ├── [ 662] manage.py ├── [2.6K] mylogger.py ├── [4.0K] mysite │   ├── [ 389] asgi.py │   ├── [ 0] __init__.py │   ├── [3.2K] settings.py │   ├── [ 757] urls.py │   └── [ 389] wsgi.py ├── [4.0K] polls │   ├── [ 63] admin.py │   ├── [ 142] apps.py │   ├── [ 0] __init__.py │   ├── [4.0K] migrations │   │   └── [ 0] __init__.py │   ├── [ 57] models.py │   ├── [4.0K] templates │   │   └── [4.0K] polls │   │   ├── [ 277] base.html │   │   ├── [ 131] index.html │   │   └── [ 201] inherited.html │   ├── [ 60] tests.py │   ├── [ 109] urls.py │   └── [ 318] views.py ├── [1.6K] prepareactions.py ├── [2.9K] README.md ├── [ 834] requirements.txt ├── [4.4K] runfuzz.py ├── [2.8K] selen.py ├── [4.0K] tests │   ├── [1.2K] context.py │   └── [ 186] README.md └── [ 462] tracing.py 8 directories, 35 files
Shenlong Bot has cached this for you
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 →