Summary
The login endpoint in SourceCodester Pharmacy Sales and Inventory System 1.0 is vulnerable to SQL injection via the Username parameter in /ajax.php?action=login.
A remote attacker can manipulate this parameter to alter backend SQL queries, potentially bypassing authentication and accessing or modifying sensitive data.
Affected context
This vulnerability affects deployments of the Pharmacy Sales and Inventory System 1.0 that expose the /ajax.php?action=login endpoint over a network.
It manifests when user-supplied values from the Username field are included directly in SQL statements without robust parameterization or sanitization.
Typical installations running on common LAMP/WAMP stacks with default configurations and no additional web application firewalling are more likely to be impacted.
Exploit preconditions
- Attack surface: Public or internal web interface at
/ajax.php?action=login - Required access: Network access to the login AJAX endpoint (no prior authentication needed)
- Trigger point: Submission of crafted input in the
Usernameparameter during the login request - Why exploitation is possible: The application appears to concatenate the
Usernamevalue into SQL queries without using prepared statements or proper escaping, allowing attackers to inject arbitrary SQL fragments
Why this happens
The core issue is improper neutralization of special elements used in SQL commands, mapping directly to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
The login logic likely builds SQL queries by string concatenation, embedding raw Username input into the query text.
This pattern treats user input as trusted, executable query syntax rather than as data, enabling attackers to break out of the intended query structure and supply their own conditions or operations.
CWE-74 (Improper Neutralization of Special Elements in Output) is also relevant, as untrusted data is not being safely handled when incorporated into backend command contexts.
Potential impact
- Bypass of login authentication using crafted
Usernamevalues - Unauthorized access to user or administrative accounts
- Reading sensitive information from the database, such as customer, inventory, or transaction records
- Modification or deletion of pharmacy sales and inventory data
- Creation of backdoor accounts or manipulation of billing and stock information
- Potential pivot to underlying host if database-level features or stored procedures are abused
General mitigation guidance
Effective mitigation focuses on eliminating direct string-based query construction and reducing the trust placed in user input entering database contexts.
Recommended patterns include:
- Using parameterized queries or prepared statements for all database interactions, especially authentication logic
- Centralizing data access in a minimal, well-reviewed database abstraction layer that enforces safe query patterns
- Applying input validation for authentication fields, such as restricting
Usernameto expected character sets and lengths - Separating application and database privileges so that the application account has only the minimal rights necessary (no schema changes, no unnecessary administrative privileges)
- Implementing secure-by-default coding standards that prohibit ad hoc SQL string concatenation
- Considering deployment of a Web Application Firewall (WAF) with rules tuned to detect and block common SQL injection patterns as a compensating control
How teams detect issues like this
Organizations can identify this class of vulnerability using a combination of static and dynamic approaches:
- Static analysis rules that flag SQL query construction using string concatenation or interpolation with user-controlled variables (e.g., direct use of
$_POST['Username']in SQL strings) - Code review checklists that explicitly require verification of prepared statement usage for all authentication-related queries
- Database activity monitoring configured to alert on anomalous queries containing tautologies, UNION-based exfiltration, or unexpected metadata access
- Dynamic application security testing (DAST) that systematically probes input parameters like
Usernamewith SQL metacharacters and payloads to observe abnormal responses - Continuous integration hooks that block merges when unsafe database access patterns are detected by automated tools

