CpS 401 Notes

SQL Injection


Introduction

SQL Injection occurs when an attacker is able to modify a SQL query at execution time by "injecting" additional code.

Demo: http://csunix.cs.bju.edu/cps401/examples/php/sqlinject.php

This results in the following SQL:


SELECT * from USAGE_LOG WHERE ID = '' or 1=1 -- '


Some databases allow multiple SQL statements to be executed in a single API call. Attackers can abuse that to "piggyback" additional queries and execute any code that the database user has privilege to perform.


Examples:





Preventing SQL Injection