An educational console application built with pure C# + SQL that demonstrates SQL injection vulnerabilities and defense mechanisms for learning purposes.
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
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
- .NET 8.0 SDK
- SQL Server LocalDB (included with Visual Studio)
- Windows OS (for LocalDB support)
-
Clone or download the project
git clone <repository-url> cd SQLInjectionSimulator
-
Restore NuGet packages
dotnet restore
-
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
-
Run the application
dotnet run
-
Choose option 6 from the main menu to create test users if needed
-
๐ฏ Run Full Security Simulation
- Executes a comprehensive simulation with normal and malicious attempts
- Generates real-time security analysis
- Produces detailed reports
-
๐ฌ Demonstrate SQL Injection Vulnerabilities
- Shows side-by-side comparison of vulnerable vs secure code
- Educational test suite with various attack patterns
-
๐งช Run Custom Attack Tests
- Interactive testing with custom payloads
- Real-time vulnerability analysis
-
๐ Show Real-time Security Dashboard
- Live monitoring of security events
- Activity trends and threat indicators
-
๐ Generate Comprehensive Security Report
- Detailed analysis of security events
- Export capabilities (CSV, JSON)
- 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
- 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--
- โ
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
๐ก๏ธ 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%
// 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);-- Attacker input: ' UNION SELECT username, password FROM users--
-- Resulting query attempts to extract sensitive data
-- Secure implementation prevents this with parameterizationThe 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
- Users: Secure user accounts with BCrypt password hashing
- LoginAttempts: Comprehensive logging of all authentication attempts
- Alerts: Security event tracking with severity levels
- Pattern-based injection detection
- Behavioral analysis for brute force attacks
- Real-time threat scoring
- Automated alert generation
- Efficient database indexing
- Connection pooling
- Asynchronous operations
- Memory-conscious reporting
After using this simulator, you will understand:
-
SQL Injection Mechanics
- How malicious input alters database queries
- Common attack vectors and payloads
- Business impact of successful attacks
-
Secure Development Practices
- Parameterized query implementation
- Input validation strategies
- Error handling best practices
-
Security Architecture
- Defense-in-depth principles
- Monitoring and alerting systems
- Incident response procedures
-
Risk Assessment
- Vulnerability impact analysis
- Threat pattern recognition
- Security metric interpretation
This tool is designed exclusively for educational purposes:
- Learning secure coding practices
- Understanding vulnerability concepts
- Training security professionals
- Supporting cybersecurity education
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
If you discover real vulnerabilities during your learning:
- Report them through proper channels
- Follow responsible disclosure practices
- Protect sensitive information
- Respect affected organizations
This is an educational project. If you'd like to contribute:
- Ensure all contributions maintain the educational focus
- Add comprehensive documentation for new features
- Include security considerations in all code
- Follow the existing code structure and patterns
- OWASP SQL Injection Prevention Cheat Sheet
- Microsoft Security Development Lifecycle
- NIST Cybersecurity Framework
- CWE-89: SQL Injection
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! ๐ก๏ธ