A Beginner’s Introduction To SQL Injections.
What is SQL and a Database
SQL (Structured Query Language) is a language for managing data inside a database.
It’s only used for talking to databases. You won’t be using SQL to write an application but instead you will use it to interact with the database that powers the application.
A Database is an organized collection of structured information, or data, typically stored electronically. Those structured set of data held in a computer like SQlite store data as a table. Think of a table in a database a lot like you would think of a table in Excel. We define specific columns in our table, and then store information as rows in our database. For instance, you can imagine a structure like this for a table called “People”. Each column has a name, and each row contains the corresponding information about a person.
What is an SQL Injection?
SQL injection is a web security vulnerability that allows an attacker to alter the SQL queries made to manage the database. This attack can be used to retrieve sensitive information, like the structure of the database: tables, columns and their underlying data. Allowing the attacker to change the identity of the user, tamper with existing data, or for example void transactions and change balances. An SQL injection can allow the complete disclosure of all data on a system and can give the ability to destroy the data or make it otherwise unavailable.
How an SQL injection occurs
To make an SQL Injection attack, an attacker must first find vulnerable code that the developer inputs within the web page or web application.
Vulnerable SQL:
These input fields are vulnerable to an SQL Injection. An attacker can use SQL commands in the above code in a way that would alter the SQL statement executed by the database.
Suppose an attacker gives the SQL command as ‘ ‘ OR ‘1’=’1' in both fields.
As a result, the database server runs the following SQL query:
This query results as true, and thus, the user gets logged in. Now the attacker has bypassed authentication. This example is the most basic type of SQL injection.
Some common SQL injection examples include
· Retrieving hidden data, where the attacker is able to modify an SQL query to return additional results.
· Subverting application logic, where the attacker can change a query to access and interfere with the application’s logic.
· UNION attacks, where the attacker can retrieve data from different joined database tables.
· Examining the database, where the attacker can extract information about the version and structure of the database.
Large scale damage
SQL injections can be disastrous, providing unlimited database access for any attacker skilled enough to successfully execute it .
Imagine a database containing payment card and social security information.
Imagine the major ramifications of an attack towards an organization and their customers.
Because the damage from SQL injection attacks can be so immense, it’s critical that our Government has adequate cyber security in place to minimize their risk towards other countries like China, Russia and Iran.
Be cautious and prevent and SQL injection
There are many ways to prevent an SQL injection, for example the developer should never construct a query directly using a user’s sensitive information. Instead, the developer should use Parameterized Statements, sanitize the user input, and do proper input validation.