Security Optimization of Web Applications: A Comparative Analysis of Vulnerable vs Protected PHP Applications
Course: Software Optimization
Professor: Dr. Rand Kouatly
Institution: EU University of Applied Science
Semester: Winter 2025/26
Project Type: Final Exam Project
Both versions are deployed and ready for immediate testing:
- π΄ Vulnerable Version: https://sovulnerable.wasmer.app
- π’ Protected Version: https://soprotected.wasmer.app
Simply visit the links above to test both versions. All testing instructions in this README use these deployed URLs.
- Project Overview
- Team Information
- Project Structure
- Testing Instructions
- Security Features
- Project Deliverables
- References
This project demonstrates security optimization of web applications through a comparative analysis of two versions of a Game Development Company website:
- Vulnerable Version: Contains multiple security vulnerabilities (SQL injection, XSS, weak authentication, etc.)
- Protected Version: Implements industry-standard security practices and optimizations
Both versions are deployed and ready for testing:
- π΄ Vulnerable Version: https://sovulnerable.wasmer.app
- π’ Protected Version: https://soprotected.wasmer.app
For Evaluation: Simply visit the links above to test both versions. All testing can be performed directly on the deployed websites without any local setup.
- Identify common web application vulnerabilities
- Implement security optimizations using best practices
- Demonstrate the effectiveness of security measures through testing
- Compare vulnerable vs protected implementations
- Backend: PHP 7.4+
- Database: MySQL 5.7+
- Frontend: HTML5, CSS3, JavaScript
- Server: Apache (with .htaccess configuration)
- Security: Prepared statements, bcrypt hashing, session management
- Hosting: Wasmer.app (both versions deployed)
gamedev_site/
β
βββ README.md # This file
βββ PROJECT_EXPLANATION.md # Detailed project explanation
βββ FINAL_EXAM_REPORT.md # Academic report (15+ pages)
βββ weak_VS_protected.md # Security comparison documentation
β
βββ [Vulnerable Version - Root Files]
β βββ index.php # Home page
β βββ auth.php # Login page (vulnerable)
β βββ reg.php # Registration page (vulnerable)
β βββ user.php # User profile (vulnerable)
β βββ contacts.php # Contact form (vulnerable)
β βββ trending.php # Trending games
β βββ about.php # About page
β βββ lib/
β β βββ auth.php # Login handler (SQL injection vulnerable)
β β βββ reg.php # Registration handler (MD5 hashing)
β β βββ db.php # Database connection
β β βββ add_game.php # Add game handler
β βββ blocks/
β β βββ header.php # Navigation header
β β βββ footer.php # Footer
β βββ imgs/ # Image assets
β βββ style.css # Stylesheet
β βββ java.js # JavaScript
β βββ database.sql # Database schema
β
βββ protected_version/ # Protected/optimized version
βββ index.php # Home page (XSS protected)
βββ auth.php # Login page (secure)
βββ reg.php # Registration page (secure)
βββ user.php # User profile (session protected)
βββ contacts.php # Contact form (secure)
βββ trending.php # Trending games
βββ about.php # About page
βββ lib/
β βββ auth.php # Login handler (prepared statements)
β βββ reg.php # Registration handler (bcrypt hashing)
β βββ session_check.php # Session management (NEW)
β βββ config.php # Configuration (environment variables)
β βββ db.php # Database connection (secure)
β βββ contact.php # Contact handler (secure)
β βββ add_game.php # Add game handler (file upload security)
β βββ logout.php # Logout handler (secure)
β βββ .htaccess # Directory protection
βββ blocks/
β βββ header.php # Navigation header (session-based)
β βββ footer.php # Footer
βββ imgs/ # Image assets
βββ style.css # Stylesheet
βββ java.js # JavaScript
βββ database.sql # Database schema
βββ .htaccess # Security headers
No installation required! Both versions are live and ready for immediate testing:
-
π΄ Vulnerable Version:
- URL: https://sovulnerable.wasmer.app
- Purpose: Test SQL injection, XSS, and other vulnerabilities
- Status: Ready to use - just visit the link
-
π’ Protected Version:
- URL: https://soprotected.wasmer.app
- Purpose: Test security measures and protections
- Status: Ready to use - just visit the link
You can immediately test both versions by:
- Clicking the links above (or copy-paste into browser)
- Following the testing instructions in the Testing Instructions section
- Comparing the behavior of vulnerable vs protected versions side-by-side
β All testing can be performed on the deployed versions without any local setup or installation.
Important: All dynamic testing should be performed on the deployed versions using the links provided above. No local installation is required for testing.
- Vulnerable Version: https://sovulnerable.wasmer.app
- Protected Version: https://soprotected.wasmer.app
Vulnerable Version Code Review:
- File Location:
lib/auth.php(lines 26-27) - Vulnerability Identified: Direct string concatenation in SQL query
Vulnerable Code:
// VULNERABLE: Direct string concatenation - SQL INJECTION RISK!
$login = trim($_POST['login'] ?? '');
$password = trim($_POST['password'] ?? '');
$sql = "SELECT id FROM users WHERE login = '$login' AND password = '$password'";
$query = $pdo->query($sql);Security Issues Found:
- β User input (
$login,$password) directly inserted into SQL query - β No input sanitization or validation
- β No parameter binding
- β Vulnerable to SQL injection attacks
Attack Vector:
An attacker can input: admin' OR '1'='1' # in the login field, which modifies the SQL query to:
SELECT id FROM users WHERE login = 'admin' OR '1'='1' #' AND password = 'anything'This bypasses authentication because '1'='1' is always true.
Protected Version Code Review:
- File Location:
protected_version/lib/auth.php - Security Measure: Prepared statements with parameter binding
Protected Code:
// SECURE: Prepared statement with parameter binding
$login = trim(filter_var($_POST['login'] ?? '', FILTER_SANITIZE_SPECIAL_CHARS));
$password = $_POST['password'] ?? '';
$sql = 'SELECT id, login, password FROM users WHERE login = ?';
$query = $pdo->prepare($sql);
$query->execute([$login]);Security Measures:
- β
Prepared statements (
prepare()) - β
Parameter binding with
?placeholders - β
Input sanitization with
filter_var() - β
Parameters passed via
execute()array - β SQL injection prevented
Comparison:
| Aspect | Vulnerable Version | Protected Version |
|---|---|---|
| SQL Construction | String concatenation | Prepared statements |
| Input Handling | Direct use | Sanitized + parameterized |
| Security | β Vulnerable | β Protected |
Vulnerable Version - GET Parameter SQL Injection:
Target URL: https://sovulnerable.wasmer.app/contacts.php
Vulnerability Location: contacts.php (line 32)
- Uses
$_GET['id']parameter directly in SQL query - No input validation or sanitization
- Results displayed in browser console
Vulnerable Code:
$id = $_GET['id'];
$sql = "SELECT * FROM contacts WHERE id = $id";
$query = $pdo->query($sql);Manual Testing Steps:
-
Basic SQL Injection:
- Navigate to:
https://sovulnerable.wasmer.app/contacts.php?id=1 OR 1=1 - Expected: All contacts retrieved (vulnerability confirmed)
- Open browser console (F12) to see extracted data
- Navigate to:
-
Extract All Data:
- Navigate to:
https://sovulnerable.wasmer.app/contacts.php?id=1 OR 1=1-- - Expected: All records from contacts table displayed
- Navigate to:
-
UNION Attack:
- Navigate to:
https://sovulnerable.wasmer.app/contacts.php?id=-1 UNION SELECT 1,2,3,4,5 - Expected: Can enumerate columns and extract data
- Navigate to:
Using SQLMap (Automated Testing Tool):
SQLMap is an open-source penetration testing tool that automates SQL injection detection and exploitation.
Installation:
# Install SQLMap (requires Python)
pip install sqlmap
# Or download from: https://sqlmap.org/SQLMap Testing Commands:
-
Detect SQL Injection:
sqlmap -u "https://sovulnerable.wasmer.app/contacts.php?id=1" --batch- Expected: SQLMap detects SQL injection vulnerability
- Output: Confirms database type, injection technique, and payloads
-
Enumerate Databases:
sqlmap -u "https://sovulnerable.wasmer.app/contacts.php?id=1" --dbs --batch- Expected: Lists all available databases
- Example Output:
gamedev_php,information_schema,mysql
-
Enumerate Tables:
sqlmap -u "https://sovulnerable.wasmer.app/contacts.php?id=1" -D gamedev_php --tables --batch- Expected: Lists all tables in the database
- Example Output:
contacts,users,trending
-
Extract Table Data:
sqlmap -u "https://sovulnerable.wasmer.app/contacts.php?id=1" -D gamedev_php -T users --dump --batch- Expected: Extracts all data from users table
- Risk: All usernames and passwords exposed
-
Extract All Data:
sqlmap -u "https://sovulnerable.wasmer.app/contacts.php?id=1" -D gamedev_php --dump-all --batch- Expected: Extracts entire database content
- Severity: Complete database compromise
Protected Version Testing:
Target URL: https://soprotected.wasmer.app/contacts.php
Testing with SQLMap:
sqlmap -u "https://soprotected.wasmer.app/contacts.php?id=1" --batchExpected Results:
- β SQLMap cannot detect SQL injection
- β All injection attempts fail
- β Attack blocked by prepared statements
Protected Code:
// SECURE: Prepared statement prevents SQL injection
$id = filter_var($_GET['id'] ?? 0, FILTER_VALIDATE_INT);
$sql = 'SELECT * FROM contacts WHERE id = ?';
$query = $pdo->prepare($sql);
$query->execute([$id]);Comparison Results:
| Test | Vulnerable Version | Protected Version |
|---|---|---|
| Manual SQL Injection | β Successful | β Blocked |
| SQLMap Detection | β Vulnerability Found | β No Vulnerability |
| Data Extraction | β All data accessible | β Protected |
| Database Enumeration | β Possible | β Prevented |
Security Impact:
- Vulnerable Version: Complete database compromise possible
- Protected Version: SQL injection attacks completely prevented
Static Testing Results:
- β
SQL injection vulnerability identified in login (
lib/auth.php) - β Direct string concatenation confirmed
- β Protected version uses prepared statements
Dynamic Testing Results:
- β URL-based SQL injection confirmed in contacts page
- β SQLMap successfully extracts database data from vulnerable version
- β Protected version blocks all SQL injection attempts
- β Complete database compromise possible in vulnerable version
Complete test cases are documented in this README and FINAL_EXAM_REPORT.md:
- Static test cases (code review) - See Testing Instructions section above
- Dynamic test cases (runtime testing) - See Testing Instructions section above
- SQLMap testing procedures - See Testing Instructions section above
- Test results tables - See Testing Instructions section above
- Comparison analysis - See Security Features section and
weak_VS_protected.md
| Vulnerability | Location | Impact | Severity |
|---|---|---|---|
| SQL Injection | lib/auth.php, contacts.php |
Database compromise | Critical |
| Weak Password Hashing | lib/reg.php |
Password theft | Critical |
| XSS Vulnerability | All output pages | Script injection | High |
| Cookie-only Auth | lib/auth.php |
Session hijacking | High |
| Unsafe File Upload | lib/add_game.php |
Malware upload | High |
| No Input Validation | All forms | Data corruption | Medium |
| Security Feature | Implementation | Status |
|---|---|---|
| Prepared Statements | All SQL queries | β Implemented |
| Bcrypt Password Hashing | password_hash() |
β Implemented |
| Output Escaping | htmlspecialchars() |
β Implemented |
| Session Management | Server-side sessions | β Implemented |
| Session Timeout | 30 minutes inactivity | β Implemented |
| File Upload Security | Size, type, MIME validation | β Implemented |
| Input Validation | filter_var(), length checks |
β Implemented |
| Directory Protection | .htaccess rules |
β Implemented |
| Security Headers | X-Frame-Options, etc. | β Implemented |
| Error Handling | Secure logging | β Implemented |
- β Vulnerable version (complete application)
- β Protected version (optimized application)
- β Database schema files
- β Configuration files
- β README.md (this file)
- β
PROJECT_EXPLANATION.md- Detailed project explanation - β
FINAL_EXAM_REPORT.md- Complete academic report (15+ pages) with test cases and results - β
weak_VS_protected.md- Security comparison documentation - β Presentation Slides - 10-minute presentation
- β Static testing results
- β Dynamic testing results
- β Comparison tables
- β Test execution logs
- β Screenshots of attacks
-
OWASP Foundation. (2021). OWASP Top 10 - 2021. Retrieved from https://owasp.org/www-project-top-ten/
-
Halfond, W. G., Viegas, J., & Orso, A. (2006). A Classification of SQL-Injection Attacks and Countermeasures. Proceedings of the IEEE International Symposium on Secure Software Engineering.
-
Stuttard, D., & Pinto, M. (2011). The Web Application Hacker's Handbook: Finding and Exploiting Security Flaws. Wiley.
-
PHP.net. (2024). PHP: Prepared Statements. Retrieved from https://www.php.net/manual/en/pdo.prepared-statements.php
-
OWASP Foundation. (2024). Password Storage Cheat Sheet. Retrieved from https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html
- OWASP Application Security Verification Standard (ASVS)
- NIST Cybersecurity Framework
- ISO/IEC 27001:2013 Information Security Management
- PHP Security Best Practices: https://www.php.net/manual/en/security.php
- OWASP SQL Injection Prevention: https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html
- OWASP XSS Prevention: https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html
- Testing: Browser Developer Tools (Opera/Chrome/Firefox DevTools)
- Security Testing: Manual testing, SQLMap
- Hosting: Wasmer.app
This project is created for educational purposes as part of the Software Optimization course at UE University of Applied Science, Winter 2025/26.
- v1.0 (January 2026) - Initial release
- Vulnerable version implementation
- Protected version with security optimizations
- Complete documentation and testing
Last Updated: 13 January 2026
Project Status: β
Complete and Ready for Submission