Applied Exploit and Hacking 5
Applied Exploit and Hacking 5
Name:
Aftab Hussain
Roll no:
Fa-21/Bs DFCS/033
Submitted by:
Aftab Hussain
Submitted to:
Saud Bin Farooq
Assignment:
Applied Exploits and Hacking
Assignment: 02
What is SQL Injection (SQLi)?
SQL Injection is a security flaw in web applications where attackers
manipulate database queries by injecting malicious SQL code through user
input. This typically occurs when input isn’t properly validated or sanitized
before being used in a query. Successful SQL injection attacks can enable an
attacker to:
In extreme cases, take full control of the underlying system (if remote
code execution is possible)
Variants:
Error-Based SQLi
Method: Exploits error messages returned by the database to extract
information.
Example Payload: ' OR 1=1 --
Injected into:
SELECT * FROM users WHERE username = '$input';
Effect: Returns all users by manipulating the condition to always be
true, or reveals database errors.
Union-Based SQLi
Method: Uses the UNION SQL operator to merge results from different
queries into a single response.
Example Payload: ' UNION SELECT username, password FROM
admin_table --
Injected into:
SELECT name, email FROM customers WHERE id = '$id';
Effect: Discloses data from other tables, such as administrator
credentials.
Variants:
$stmt->execute([$username]);
2. Stored Procedures:
Encapsulate SQL logic in predefined routines on the database. Properly
implemented, they limit SQLi exposure.