An SQL injection (also known as SQLi) is a technique for the “injection” of SQL commands by attackers to access and manipulate databases. Using SQL code via user input that a web application (eg, web form) sends to its database server, attackers can gain access to information, which could include sensitive data or personal customer information.
SQL injection is a common issue with database-driven websites. Given the prevalence of such websites, this flaw is easily detected and easily exploited, and any website can be subject to an SQL injection attack.
The Open Web Application Security Project (OWASP) has noted injections as part of its OWASP Top Ten Web Application Risks.
SQL (Structured Query Language) is a programming language used to manage online databases such as MySQL, Microsoft SQL Server, IBM db2, and PostgreSQL. A standardized language, it is used to manipulate databases in order to build and create customizable data views. For a user to access database information, SQL statements are used in the input fields.
SQL statements are used by run commands, such as accessing data, modifying entries (add/remove/update) or record removal. Meanwhile, an SQL query is a term used in the industry to describe “SQL statements that return result sets.”
SQL databases used by businesses increasingly contain more sensitive and valuable data such as usernames and passwords, credit card information, and other important information. In practice, an SQL statement is often inputted using a web application, which can then be exploited by attackers via SQL injections by entering malicious code into these HTML forms. A web page or web application that has an SQL injection vulnerability uses user input directly in an SQL query.
SQL injection attacks have been around for years and are common due to a few reasons:
In addition, SQL injections are common with PHP and ASP applications due to the prevalence of older functional interfaces.
A type of attack vector, SQL injections can be classified based on the methods that attackers use to access backend data, and fall under three broad categories: In-band SQL Injection, Blind SQL Injection, and Out-of-band SQL Injection.
It is worth noting that due to the differences between the common databases, techniques for SQL injection might differ based on the specific databases. This includes syntax for string concatenation, error messages, batched queries (resulting in batched SQL injections separated by semicolons), and platform-specific APIs.
SQL injection can happen if you offer the website visitors the ability to initiate an SQL query without applying validation of the input. SQL injection attacks allow attackers to access data, unauthorised viewing of user lists, tamper with existing data, deletion of data sets, disclose all the data in the system, destroy the data or in certain cases, they can gain administrative rights to a database which can be damaging to any business. Attackers can go around authentication of a web page or web application and retrieve the content of the SQL database.
In one of the biggest data breaches in history, Heartland Payments Systems announced that the computers they use to process payment card transactions had been breached in 2008. The data compromised included information required to produce counterfeit credit cards, including the data coded on the card’s magnetic strip. The attackers exploited a known vulnerability to perform a SQL injection attack.
The data breach started with an SQL injection in 2007 that compromised Heartland’s database. Heartland reported that the code modified was on a web application login page that had been deployed 8 years earlier, but this was the first time the vulnerability had been exploited. This is an example of poorly coded web application software that is vulnerable to SQL injection attacks, and here the hackers managed to introduce malicious code into the company’s systems through user input.
The hackers then spent 8 months accessing the payment processing system while avoiding detection from several different antivirus systems and eventually installed a spyware program called a “sniffer” that captured the card data as payments were processed.
This real life example is over ten years old, but there are still web applications believed to contain SQL injection vulnerabilities, making SQL injection attacks a common method of cyber attack.
The company paid an estimated $145 million in compensation for fraudulent payments.
There are a number of prevention actions that users can to do prevent SQL injection attacks:
For a comprehensive list of how to secure SQL, check out our 11 steps to secure SQL. If you are on MySQL, check out our top tips to improve your MySQL security: https://www.upguard.com/blog/top-11-ways-to-improve-mysql-security
SQL injection of one of the Top 20 OWASP Vulnerabilities, and we cover how to fix them here.