Skip to content

arhadnane/SQL-Injection-Cybersecurity-Simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ›ก๏ธ SQL Injection Cybersecurity Simulator

An educational console application built with pure C# + SQL that demonstrates SQL injection vulnerabilities and defense mechanisms for learning purposes.

โš ๏ธ FOR EDUCATIONAL USE ONLY - DO NOT USE AGAINST REAL SYSTEMS

๐ŸŽฏ Project Overview

This simulator provides a safe, controlled environment to:

  • Learn how SQL injection vulnerabilities work
  • Understand the impact of improper input handling
  • Practice implementing secure coding techniques
  • Analyze attack patterns and defense mechanisms
  • Generate comprehensive security reports

๐Ÿ“‚ Project Structure

SQLInjectionSimulator/
โ”œโ”€โ”€ Program.cs                      # Main application entry point
โ”œโ”€โ”€ SQLInjectionSimulator.csproj    # Project configuration
โ”œโ”€โ”€ appsettings.json                # Application configuration
โ”œโ”€โ”€ copilot-instruction.md          # Comprehensive development guide
โ”œโ”€โ”€ Database/
โ”‚   โ”œโ”€โ”€ schema.sql                  # Database table definitions
โ”‚   โ””โ”€โ”€ seed.sql                    # Initial test data
โ”œโ”€โ”€ Modules/
โ”‚   โ”œโ”€โ”€ UserManager.cs              # Secure user management
โ”‚   โ”œโ”€โ”€ LoginSimulator.cs           # Attack simulation
โ”‚   โ”œโ”€โ”€ InjectionTester.cs          # Vulnerability demonstration
โ”‚   โ”œโ”€โ”€ DefenseEngine.cs            # Threat detection & analysis
โ”‚   โ””โ”€โ”€ Reporter.cs                 # Security reporting & analytics
โ””โ”€โ”€ README.md                       # This file

๐Ÿš€ Quick Start

Prerequisites

  • .NET 8.0 SDK
  • SQL Server LocalDB (included with Visual Studio)
  • Windows OS (for LocalDB support)

Installation & Setup

  1. Clone or download the project

    git clone <repository-url>
    cd SQLInjectionSimulator
  2. Restore NuGet packages

    dotnet restore
  3. Initialize the database

    # Execute the SQL scripts in order:
    # 1. Run Database/schema.sql in SQL Server Management Studio or VS Code
    # 2. Run Database/seed.sql to populate with test data
  4. Run the application

    dotnet run
  5. Choose option 6 from the main menu to create test users if needed

๐ŸŽฎ How to Use

Main Menu Options

  1. ๐ŸŽฏ Run Full Security Simulation

    • Executes a comprehensive simulation with normal and malicious attempts
    • Generates real-time security analysis
    • Produces detailed reports
  2. ๐Ÿ”ฌ Demonstrate SQL Injection Vulnerabilities

    • Shows side-by-side comparison of vulnerable vs secure code
    • Educational test suite with various attack patterns
  3. ๐Ÿงช Run Custom Attack Tests

    • Interactive testing with custom payloads
    • Real-time vulnerability analysis
  4. ๐Ÿ“Š Show Real-time Security Dashboard

    • Live monitoring of security events
    • Activity trends and threat indicators
  5. ๐Ÿ“ˆ Generate Comprehensive Security Report

    • Detailed analysis of security events
    • Export capabilities (CSV, JSON)

Educational Features

  • Safe Learning Environment: All attacks are contained within the simulator
  • Comparative Analysis: See vulnerable vs secure implementations side-by-side
  • Pattern Recognition: Learn to identify common attack signatures
  • Defense Mechanisms: Understand how proper security measures work

๐Ÿ”’ Security Features Demonstrated

Attack Patterns Covered

  • Boolean-based injection: ' OR '1'='1
  • Comment injection: admin'--
  • Union-based attacks: ' UNION SELECT username, password FROM users--
  • Time-based blind injection: '; WAITFOR DELAY '00:00:05'--
  • Error-based injection: ' AND (SELECT COUNT(*) FROM sysobjects) > 0--
  • Destructive commands: '; DROP TABLE Users--

Defense Techniques Implemented

  • โœ… Parameterized Queries using SqlCommand.Parameters
  • โœ… Input Validation with pattern detection
  • โœ… Least Privilege database access
  • โœ… Real-time Monitoring and alerting
  • โœ… Brute Force Detection with IP blocking
  • โœ… Comprehensive Logging for audit trails

๐Ÿ“Š Sample Output

๐Ÿ›ก๏ธ SQL INJECTION CYBERSECURITY SIMULATOR - SECURITY REPORT
================================================================================
Report Generated: 2024-01-15 14:30:22
Analysis Period: 1.0 hours (2024-01-15 13:30 to 2024-01-15 14:30)

๐Ÿ“Š SECURITY OVERVIEW
--------------------------------------------------
Total Login Attempts: 30
โ”œโ”€โ”€ Successful Logins: 8 (26.7%)
โ”œโ”€โ”€ Failed Attempts: 22 (73.3%)
โ””โ”€โ”€ Injection Attempts: 12 (40.0%)

๐Ÿ” THREAT DETECTION
--------------------------------------------------
Security Alerts: 15
โ”œโ”€โ”€ Critical: 3 ๐Ÿ”ด
โ”œโ”€โ”€ High: 5 ๐ŸŸ 
โ”œโ”€โ”€ Medium: 4 ๐ŸŸก
โ””โ”€โ”€ Low: 3 ๐ŸŸข

Detection Effectiveness: 95.2%

๐Ÿงช Educational Scenarios

Scenario 1: Basic Authentication Bypass

// VULNERABLE (DON'T DO THIS):
string query = $"SELECT * FROM Users WHERE Username = '{username}' AND Password = '{password}'";

// Input: username = "admin' OR '1'='1'--"
// Result: Bypasses authentication

// SECURE (CORRECT APPROACH):
string query = "SELECT * FROM Users WHERE Username = @username AND Password = @password";
command.Parameters.AddWithValue("@username", username);
command.Parameters.AddWithValue("@password", password);

Scenario 2: Data Extraction Attack

-- Attacker input: ' UNION SELECT username, password FROM users--
-- Resulting query attempts to extract sensitive data
-- Secure implementation prevents this with parameterization

๐Ÿ“ˆ Reporting & Analytics

The simulator generates comprehensive reports including:

  • Attack attempt statistics
  • Top attack patterns and frequencies
  • Source IP analysis
  • Security alert summaries
  • Performance metrics
  • Actionable security recommendations

Reports can be exported to:

  • CSV format for spreadsheet analysis
  • JSON format for programmatic processing
  • Console output for immediate review

๐Ÿ› ๏ธ Technical Implementation

Database Schema

  • Users: Secure user accounts with BCrypt password hashing
  • LoginAttempts: Comprehensive logging of all authentication attempts
  • Alerts: Security event tracking with severity levels

Security Analysis Engine

  • Pattern-based injection detection
  • Behavioral analysis for brute force attacks
  • Real-time threat scoring
  • Automated alert generation

Performance Considerations

  • Efficient database indexing
  • Connection pooling
  • Asynchronous operations
  • Memory-conscious reporting

๐ŸŽ“ Learning Outcomes

After using this simulator, you will understand:

  1. SQL Injection Mechanics

    • How malicious input alters database queries
    • Common attack vectors and payloads
    • Business impact of successful attacks
  2. Secure Development Practices

    • Parameterized query implementation
    • Input validation strategies
    • Error handling best practices
  3. Security Architecture

    • Defense-in-depth principles
    • Monitoring and alerting systems
    • Incident response procedures
  4. Risk Assessment

    • Vulnerability impact analysis
    • Threat pattern recognition
    • Security metric interpretation

โš ๏ธ Important Disclaimers

Educational Use Only

This tool is designed exclusively for educational purposes:

  • Learning secure coding practices
  • Understanding vulnerability concepts
  • Training security professionals
  • Supporting cybersecurity education

Prohibited Uses

DO NOT use this simulator to:

  • Attack real systems or applications
  • Test security without explicit permission
  • Harm individuals, organizations, or systems
  • Violate any laws or regulations

Responsible Disclosure

If you discover real vulnerabilities during your learning:

  • Report them through proper channels
  • Follow responsible disclosure practices
  • Protect sensitive information
  • Respect affected organizations

๐Ÿค Contributing

This is an educational project. If you'd like to contribute:

  1. Ensure all contributions maintain the educational focus
  2. Add comprehensive documentation for new features
  3. Include security considerations in all code
  4. Follow the existing code structure and patterns

๐Ÿ“š Additional Resources

๐Ÿ“ License

This educational project is provided as-is for learning purposes. Please use responsibly and ethically.


Remember: The best defense against SQL injection is to never concatenate user input directly into SQL queries. Always use parameterized queries and validate all inputs! ๐Ÿ›ก๏ธ