SQL Injection
SQL Injection
PREPARED BY :
Overview
This report highlights vulnerabilities identified in a user management application due to
improper handling of SQL queries. The vulnerabilities include Classic SQL Injection
(Tautology-Based) and Union-Based SQL Injection, both of which exploit unsafe query
construction and enable attackers to manipulate or retrieve unauthorized data from the
database.
Description:
Union-based SQL injection combines the results of two or more queries. An attacker can
leverage this technique to retrieve sensitive data from unrelated database tables by
merging it with the results of a legitimate query.
Observed Behavior:
The query attempts to merge data from the users table with data from another table
containing sensitive fields (username and password).
If the database structure and permissions allow it, this query may expose sensitive
information such as usernames and passwords.
Impact:
Potential data breach exposing credentials and other sensitive user information.
Could allow attackers to gain unauthorized access to the system.
Risk Level: Critical
URL:
URL:
Observed Behavior:
For 1=1, the query executes successfully and returns results.
For 1=2, the query executes but returns no results.
Impact: This allows attackers to infer application logic and determine whether an
injection attempt is succeeding or failing.
Risk Level: Medium
5. Time-Based Blind SQL Injection
Description:
This technique sends queries that force the database to pause for a certain period,
allowing attackers to infer vulnerabilities based on response delays.
URL:
SELECT u FROM User u WHERE u.name = ''; IF(1=1) WAITFOR DELAY '00:00:05'--
Test Result:
Observed Behavior:
The query causes the database to pause for 5 seconds before responding. If this delay
occurs, the application is vulnerable to time-based blind SQL injection.
Impact: Attackers can use this to extract sensitive data through a series of logical tests
and time delays.
Risk Level: High
URL:
http://localhost:8089/api/users
Body:
{
"name": "'; DROP TABLE users;--",
"email": "[email protected]"
}
Expected SQL Query:
INSERT INTO users (name, email) VALUES ('; DROP TABLE users;--',
'[email protected]')
Test Result:
Observed Behavior:
If the application is vulnerable, the injected query drops the users table, resulting in
irreversible data loss.
If the database rejects stacked queries, an error will occur, but the vulnerability still
exists.
Impact: Attackers can execute multiple malicious queries, such as deleting tables, altering
schema, or creating unauthorized users.
Risk Level: Critical
URL:
Observed Behavior:
The query executes a system command (nslookup) that attempts to resolve attacker.com,
sending data to the attacker's server.
If the database allows system commands, this can be exploited to extract sensitive data or
compromise the server.
Impact: Attackers can extract data without directly viewing responses in the application,
making detection harder.
Risk Level: Critical
General Recommendations
1. Use Parameterized Queries or ORM Frameworks:
Avoid direct string concatenation in SQL queries. Use prepared statements or ORM
frameworks like JPA or Hibernate, which automatically handle input sanitization.
Example:
@Query("SELECT u FROM User u WHERE u.name = :name")
List<User> findUsersByName(@Param("name") String name);
2. Input Validation and Sanitization:
Validate and sanitize all user inputs before processing. Reject inputs containing SQL
keywords, special characters, or patterns likely to be malicious.
3. Least Privilege Principle:
Limit the database user’s permissions. For example, the database user should not have
permissions to execute DROP TABLE or access unrelated tables.
4. Error Handling:
Avoid exposing detailed error messages to the user. Use a generic error message and log
the details for internal debugging.
5. Use Web Application Firewalls (WAF):
Employ a WAF to monitor and block malicious requests targeting SQL injection
vulnerabilities.
Conclusion
The vulnerabilities identified in this application are severe and can lead to unauthorized
data access, credential leaks, and potentially complete database compromise. Immediate
steps should be taken to remediate these vulnerabilities by implementing secure coding
practices, validating user inputs, and employing parameterized queries.