Web Applications and Databases
- Modern web applications typically use a database backend.
- Databases store and retrieve application data (e.g., content, user info).
- Applications dynamically query databases in real-time as HTTP(S) requests are received.
Three-Tier Architecture
- Tier I: Client application (user-facing).
- Tier II: Application server.
- Tier III: Database Management System (DBMS).
SQL Injection (SQLi)
- Occurs when user input is used to construct a SQL query insecurely.
- Exploits input fields to change or add SQL code to backend queries.
- Specific to relational databases (e.g., MySQL); NoSQL injection applies to non-relational DBs.
Attack Process
- Inject SQL code outside normal input (e.g., using
' or ").
- Subvert the application logic (e.g., change or stack queries).
- Retrieve output via the application's frontend.
SQL Injection Techniques
- Stacked Queries: Executes multiple SQL queries.
- Union Queries: Merges results of the injected query with the original.
Impacts
- Data Breach: Access to sensitive info (passwords, credit cards).
- Logic Subversion: Login bypass, unauthorized admin access.
- Server Control: File manipulation, backdoor insertion, full system takeover.
Prevention
- Use secure coding practices.
- Sanitize and validate all user inputs.
- Apply least-privilege access control on the DB and server side.