Summary
A SQL injection flaw in the /edit_exam2.php endpoint of the Class and Exam Timetabling System allows untrusted ID parameters to be embedded directly into database queries.
A remote attacker can manipulate the ID argument to alter or access backend data, which becomes especially risky when the application runs with elevated database privileges and exposes this endpoint publicly.
Affected context
The vulnerability exists in deployments of SourceCodester Class and Exam Timetabling System that expose the /edit_exam2.php functionality over a network.
It appears when user-controlled parameters (such as the ID argument) are interpolated into SQL statements without adequate validation or parameterization.
Typical environments include shared hosting or institutional servers where the application connects to a relational database with broad permissions.
Exploit preconditions
- Attack surface: HTTP interface to /edit_exam2.php
- Required access: Network access to the web application; no special privileges are necessarily required if the endpoint is publicly reachable
- Trigger point: Supplying crafted values in the ID parameter of requests that reach the vulnerable SQL query
- Why exploitation is possible: The application likely concatenates the ID value directly into SQL, without using prepared statements, escaping, or strict input validation, allowing attackers to alter query structure
Why this happens
This issue stems from constructing SQL statements by directly embedding user-supplied input into query strings.
Instead of using parameterized queries or prepared statements, the code path in /edit_exam2.php likely concatenates the ID argument into the WHERE clause or similar, making the query structure dependent on untrusted data.
This aligns with CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') and also touches on CWE-74, where output to an interpreter is not properly neutralized before use.
Potential impact
- Unauthorized reading of exam schedules, class assignments, or related records
- Modification or deletion of timetable data, impacting system integrity
- Extraction of additional sensitive data stored in the same database, depending on schema and permissions
- Escalation to wider database compromise if the application account has broad privileges
- Potential pivoting to other systems through stored credentials or database-level features
General mitigation guidance
Effective mitigation focuses on isolating SQL logic from untrusted input and constraining what the database can do on behalf of the application.
Common defensive patterns include:
- Using prepared statements or parameterized queries for all database operations involving user input
- Applying strict validation and type enforcement on identifiers such as ID (e.g., ensuring they are numeric and within expected ranges)
- Centralizing database access through a safe data access layer that standardizes secure query construction
- Limiting database account privileges to only the minimal operations required by the application
- Applying generic input-handling policies that treat all external data as untrusted and avoid direct concatenation into interpreter contexts
How teams detect issues like this
Organizations can uncover this class of issue through:
- Static analysis rules that flag string-built SQL queries and direct concatenation of request parameters into query strings
- Code review checklists that highlight database-access layers and require parameterization for all dynamic queries
- Runtime monitoring and web application firewalls configured to detect and log suspicious patterns typical of SQL injection attempts
- Periodic security testing, including automated scanners and targeted manual tests, focused on parameters like ID that influence record selection

