
This repo reproduce xss attack on django 4.0.1 (see CVE-2022-22818)
Works only on Linux. On Windows, one of the dependencies may cause an error.
Before running, you need to install the following packages:
pip install -r requirements.txt
python -m django --version # pip install django==4.0.1
grammarinator-generate --version # pip install git+https://github.com/renatahodovan/grammarinator.git#egg=grammarinator
touch grammars/fuzzer/HTMLGenerator.py # Create an empty file to be filled by the generator
grammarinator-process grammars/HTMLLexer.g4 grammars/HTMLParser.g4 -o grammars/fuzzer # Fill the file
python runfuzz.py
You need to patch one file from Django, because it can cause a template engine error, which will stop the fuzzing process:
--- /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)
If you are using venv, the path might be: venv/lib/python3.9/site-packages/django/template/defaultfilters.py
If you installed packages system-wide, the path: $HOME/.local/lib/python3.9/site-packages/django/template/defaultfilters.py
You need to go inside the file, find the definition of the random tag, and wrap it in a try-catch block.
If you don't do this, the fuzzer will terminate when it encounters this 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) |