Types of SQL Injection (SQLi)
Last Updated :
08 Aug, 2022
SQL Injection is an attack that employs malicious SQL code to manipulate backend databases in order to obtain information that was not intended to be shown, The data may include sensitive corporate data, user lists, or confidential consumer details. This article contains types of SQL Injection with their examples. SQL Injections-LABS (a platform to learn SQL Injections) to showcase how you can perform each type of SQL Injections.
1. Error-Based SQL Injections:
Error-based SQL Injections obtain information about the database structure from error messages issued by the database server. In rare circumstances, an attacker may enumerate an entire database using only error-based SQL injection.
Example:
In SQL Injections labs, if you type ?id=1 in the URL and press enter, it gives you the login name and password.
But if we type ?id=1’ it gives an error.
This error will now assist us in locating the backend query.
If we remove the first and last quote from “1” LIMIT 0,1′, then it becomes ‘1” LIMIT 0,1.
1′ is our input, and a single quote after this input indicates that our input is enclosed in single quotes. This means that the query that was executed back in the database was the following:
Query:
select * from table_name where id='1
which is syntactically incorrect. Now, we will fix this query by giving input ?id=1′ –+.
–+ will comment out all that comes after it. So, our backend query would be:
Query:
select * from table_name where id='1' --+'
and again we get the login name and password.
Now we can insert a query between the quotation and -+ to retrieve data from the database.
2. Union-Based SQL Injections:
Union-based SQL Injections use the UNION SQL operator to aggregate the results of two or more SELECT queries into a single result, which is subsequently returned as part of the HTTP response.
Query:
SELECT EMP_ID, EMP_DOJ FROM EMP
UNION SELECT dept_ID, dept_Name FROM dept;
This SQL query will produce a single result set with two columns, including values from EMP columns EMP_ID and EMP_DOJ and dept columns dept_ID and dept_Name.
Two important needs must be met for a UNION query to function:
- Each query must return the same number of columns.
- The data types must be the same, i.e., it is not changed after query execution.
To determine the no of columns required in an SQL injection UNION attack, we will Inject a sequence of ORDER BY clauses and increment the provided column index until an error is encountered.
?id=1' order by 1 --+ no error
?id=1' order by 2 --+ no error
?id=1' order by 3 --+ no error
?id=1' order by 4 --+ we get error
This demonstrates that the query lacks the fourth column. So we now know that the query in the backend has three columns.
Now we will use the UNION statement in order to join two queries and to be able to discover the vulnerable columns.
Query:
id=1‘ UNION SELECT 1,2,3 --+
There is no issue, but we are obtaining the result set of the first query; to receive the result of a second select query on the screen, we must make the first query’s result set EMPTY. This may be accomplished by supplying an ID that does not exist (negative ID).
Query:
?id=-1‘ UNION SELECT 1,2,3 --+
This demonstrates that we are getting values from columns 2 and 3 as output. As a result, we can utilize these two columns to retrieve information about and from the database.
Query:
?id=-1‘ UNION SELECT 1,version(),database() --+
This will provide the database we are currently using as well as the current version of the database utilized at the backend.
3. Blind Boolean-based SQL Injections:
Boolean-based SQL Injection works by submitting a SQL query to the database and forcing the application to produce a different response depending on whether the query returns TRUE or FALSE.
Example:
In SQL Injections LABS if we type ?id=1 in the browser URL, the query that will send to the database is:
Query:
SELECT * from table_name WHERE id=1
It will output “you are in” in yellow font on the web page, as seen in the image.
When an attacker tries to use a comma (‘) ?id=1’ to break this query, he will not be able to find an error notice using any other method also. Furthermore, if the attacker attempts to inject an incorrect query, as illustrated in the figure, the yellow text will vanish.
The attacker will next use blind SQL injection to ensure that the inject query returns a true or false result.
?id=1' AND 1=1 --+
Now, the database checks if 1 is equal to 1 for the supplied condition. If the query is legitimate, it returns TRUE; as seen in the screenshot, we have the yellow color text “you are in,” indicating that our query is valid.
As a result, it confirms that the web application is vulnerable to blind SQL injection. We will get database information using true and false conditions.
Now, we will inject the following query, which will question whether the length of the database string is equal to 1, and it will respond by returning TRUE or FALSE via the text “you are in.”
?id=1' AND (length(database())) = 1 --+
As you can see in the image, the text disappears again, indicating that it has returned FALSE to respond NO the length of the database string is not equal to 1.
When we test for a string length of 8, it returns yes, and the yellow text “you are in” shows again.
4. Blind Time-Based SQL Injections:
Time-based SQL Injection works by sending a SQL query to the database and forcing it to wait for a predetermined length of time (in seconds) before answering. The response time will tell the attacker if the query result is TRUE or FALSE.
Depending on the outcome, an HTTP response will either be delayed or returned immediately. Even though no data from the database is returned, an attacker can determine if the payload used returned true or false. Because an attacker must enumerate a database character by character, this attack is often slow (particularly on big databases).
And SLEEP(10) if sleep then Vulnerable
OR SLEEP(10) if sleep then vulnerable
Similar Reads
Cyber Security Tutorial
Cyber security, also known as information technology security, refers to the practice of protecting systems, networks, and programs from digital attacks. These cyber-attacks are usually aimed at accessing, changing, or destroying sensitive information, extorting money from users, or interrupting nor
6 min read
Introduction
OSI Security Architecture
The OSI Security Architecture is internationally recognized and provides a standardized technique for deploying security measures within an organization. It focuses on three major concepts: security attacks, security mechanisms, and security services, which are critical in protecting data and commun
8 min read
Active and Passive attacks in Information Security
In Cybersecurity, there are several kinds of cyber threats you need to know these days, that can relate to computer security, network security, and information security. There are basically two forms of threats: active and passive attacks. An active attack is an attack in which attackers directly ha
9 min read
Types of Security Mechanism
A security mechanism is a method or technology that protects data and systems from unauthorized access, attacks, and other threats. Security measures provide data integrity, confidentiality, and availability, thereby protecting sensitive information and maintaining trust in digital transactions. In
3 min read
A Model for Network Security
When we send our data from the source side to the destination side we have to use some transfer method like the internet or any other communication channel by which we are able to send our message. The two parties, who are the principals in this transaction, must cooperate for the exchange to take p
2 min read
Cyber Technology
Basics of Wi-Fi
We've been studying a lot about the Wired Network. Ethernet is the most common example. Wired networks differ from wireless which uses radio waves rather than transmitting electrical signals over the cables. Wi-Fi stands for Wireless Fidelity. It is a technology for wireless local area networking wi
3 min read
The Internet and the Web
Introduction : The internet is a global network of interconnected computers and servers that allows people to communicate, share information, and access resources from anywhere in the world. It was created in the 1960s by the US Department of Defense as a way to connect computers and share informati
7 min read
What is a Website ?
A website is a collection of many web pages, and web pages are digital files that are written using HTML(HyperText Markup Language). To make your website available to every person in the world, it must be stored or hosted on a computer connected to the Internet round a clock. Such computers are know
5 min read
Cryptography and Network Security Principles
In the present-day scenario security of the system is the sole priority of any organization. The main aim of any organization is to protect their data from attackers. In cryptography, attacks are of two types: Passive attacks and Active attacks. Passive attacks are those that retrieve information fr
9 min read
Public Key Infrastructure
Public key infrastructure or PKI is the governing body behind issuing digital certificates. It helps to protect confidential data and gives unique identities to users and systems. Thus, it ensures security in communications. The public key infrastructure uses a pair of keys: the public key and the p
7 min read
What is Electronic Signature?
Electronic signature or e-signature is an electronic way of signing a document or data through electronic devices, this means that such a digital form of signing is also seen as legal and authentic like the conventional hand-written one, whereby signatory has read all contents and accepted them, the
7 min read
Identity and Access Management
In a recent study by Verizon, 63% of the confirmed data breaches are due to either weak, stolen, or default passwords used. There is a saying in the cybersecurity world that goes like this âNo matter how good your chain is itâs only as strong as your weakest link.â and exactly hackers use the weakes
11 min read
What Is Cloud Computing ? Types, Architecture, Examples and Benefits
Nowadays, Cloud computing is adopted by every company, whether it is an MNC or a startup many are still migrating towards it because of the cost-cutting, lesser maintenance, and the increased capacity of the data with the help of servers maintained by the cloud providers. Cloud Computing means stori
15 min read
Cyber Crimes
Cyber Crime
Cybercrime refers to criminal activities carried out using computers and the internet, including hacking, data theft, malware attacks, and financial fraud. With businesses, governments, and individuals relying heavily on digital platforms, cyber threats have escalated, leading to billions in financi
12 min read
Cyber Criminals and its types
Cybercriminals are people who use the internet to commit illegal activities. They hack into computers, steal personal information, or spread harmful software. Their actions can harm individuals, businesses, and organizations. Often, they aim to make money, cause disruption, or gain unauthorized acce
5 min read
Psychological Profiling in Cybersecurity
The Cybersecurity Profiling is about keeping the computer systems safe from the bad peoples who want to steal the information or can cause harm. To do this better experts study the minds of these bad peoples called the cybercriminals. This study is called the psychological profiling. It helps us to
7 min read
What is Social Engineering? Working, Types, Prevention and Impact
Social Engineering is an umbrella term for multiple malicious activities done by cyber criminal over internet through human interaction. It doesn't involve the use of technical hacking techniques. Attackers use psychology and manipulation to trick users into performing actions that could compromise
9 min read
Cyberstalking
In Cyber Stalking, a cyber criminal uses the internet to threaten somebody consistently. This crime is often done through email, social media, and other online mediums. Cyber Stalking can even occur in conjunction with the additional ancient type of stalking, wherever the bad person harasses the vic
7 min read
How to Defend Against Botnets ?
A botnet is a collection of compromised computers (called bots) residing on the internet that can be controlled by cybercriminals. Botnets are used for all sorts of nefarious purposes, from spamming to stealing confidential information from computers to launching cyber attacks on other websites. The
4 min read
Emerging Attack Vectors in Cyber Security
In Cyber Security, knowing about attack vectors is key to keeping information safe and systems secure. An attack vector is a way that cybercriminals use to break into a network, system, or application by taking advantage of weaknesses. Attack vectors refer to the various paths or methods that attack
7 min read
What is Malware? And its Types
Malware is malicious software and refers to any software that is designed to cause harm to computer systems, networks, or users. Malware can take many forms. Individuals and organizations need to be aware of the different types of malware and take steps to protect their systems, such as using antivi
8 min read
What is Phishing?
Phishing is a form of online fraud in which hackers attempt to get your private information such as passwords, credit cards, or bank account data. This is usually done by sending false emails or messages that appear to be from trusted sources like banks or well-known websites. They aim to convince y
12 min read
Cyber Crime - Identity Theft
Identity Theft also called Identity Fraud is a crime that is being committed by a huge number nowadays. Identity theft happens when someone steals your personal information to commit fraud. This theft is committed in many ways by gathering personal information such as transactional information of an
5 min read
What is Cyber Terrorism?
In the computerized age, where innovation saturates each part of day-to-day existence, the idea of digital psychological warfare has arisen as a huge danger. Digital illegal intimidation alludes to the purposeful utilization of computerized assaults to inflict any kind of damage, interruption, or dr
13 min read
Keyloggers and Spyware
Worms, Viruses and beyond !!
This article introduces some very basic types of malicious content which may harm your PC in some way or the other.. The Threat The computer systems may become a victim of virus, worm, hacking etc types of attacks. The computer systems may crash, sensitive data can be stolen and misused or driver pr
5 min read
Trojan Horse in Information Security
Any malicious software intended to harm or exploit any programmable device, service, or network is referred to as malware. Malware includes computer viruses, worms, Trojan horses, ransomware, spyware, and other malicious programs. In this article we will understand about Trojan Horse virus. What is
8 min read
Image Steganography in Cryptography
The word Steganography is derived from two Greek words- 'stegos' meaning 'to cover' and 'grayfia', meaning 'writing', thus translating to 'covered writing', or 'hidden writing'. Steganography is a method of hiding secret data, by embedding it into an audio, video, image, or text file. It is one of t
8 min read
Difference between DOS and DDOS attack
Here in the spectrum of cybersecurity, the various types of attacks should be distinguished for systems and networks to be protected. There are two categories of these; DOS, the short form for Denial of Service, and DDOS, which stands for Distributed Denial of Service. Both are meant to flood the ta
5 min read
Types of SQL Injection (SQLi)
SQL Injection is an attack that employs malicious SQL code to manipulate backend databases in order to obtain information that was not intended to be shown, The data may include sensitive corporate data, user lists, or confidential consumer details. This article contains types of SQL Injection with
6 min read
Buffer Overflow Attack with Example
A buffer is a temporary area for data storage. When more data (than was originally allocated to be stored) gets placed by a program or system process, the extra data overflows. It causes some of that data to leak out into other buffers, which can corrupt or overwrite whatever data they were holding.
3 min read
Reverse Engineering - Software Engineering
Software Reverse Engineering is a process of recovering the design, requirement specifications, and functions of a product from an analysis of its code. It builds a program database and generates information from this. This article focuses on discussing reverse engineering in detail. What is Reverse
6 min read
Difference Between Vulnerability and Exploit
The concepts of vulnerability and exploit are fundamental in Cyber Security, yet they represent different aspects of security risks. While a vulnerability refers to a weakness or flaw in a system that could potentially be exploited, an exploit is the actual method or tool used by attackers to take a
5 min read
Basic Network Attacks in Computer Network
Many people rely on the Internet for many of their professional, social and personal activities. But there are also people who attempt to damage our Internet-connected computers, violate our privacy and render inoperable the Internet services. Given the frequency and variety of existing attacks as w
7 min read
Kali Linux - Hacking Wi-Fi
These days the Wi-Fi networks are more secure than the older days, These days most wireless access points use WPA(Wi-Fi Protection Access) 2 Pre Shared Key in order to secure the network. This WPA 2 uses a stronger encryption algorithm which is known as AES which is very difficult to crack. When it
4 min read
Web Server and its Types of Attacks
Web Servers are where websites are stored. They are computers that run an operating system and are connected to a database to run multiple applications. A web server's primary responsibility is to show website content by storing, processing, and distributing web pages to users. Web servers are essen
6 min read
Types of VoIP Hacking and Countermeasures
Voice over IP or Voice over Internet Protocol (VoIP) is a collection of different technologies and practices that allows the delivery of voice communication, images, audio, video, through packet data networks over the internet protocol. This makes it very cost-efficient, flexible, and various other
4 min read
How to Spoof SMS Message in Linux ?
In this article, we will show how to spoof SMS messages in Linux using two of the following tools:- fake-smsSocial Engineering Toolkit (SET)1.) Fake-sms It is a tool written in simple script to send SMS anonymously. Features:Send sms anonymouslyFast sms deliveryInternational sms sending available.On
2 min read
Prevention and Protection
Difference Between Backup and Recovery
As technology continues to evolve, everyone uses a device for either work or entertainment, resulting in data being generated continuously. Keeping the data safe is very important. With the increase in data, ensuring its safety has become very important. Proper storage and protection of data have be
4 min read
Manual Code Review : Security Assessment
Secure Code Review is code assessment for identifying security vulnerabilities at an early stage in development lifecycle. When used together with penetration testing(automated and manual), it can significantly improve security posture of an organization. This article does not discuss a process for
3 min read
Penetration Testing - Software Engineering
In this guide, we'll explore the fundamentals of penetration testing, its importance in cybersecurity, and how it fits into the software development lifecycle (SDLC). From network security to web application security, we'll be going into various aspects of pen testing, equipping you with the knowled
9 min read
Security Testing Tools - Software Testing
Security testing tools are essential for identifying and addressing vulnerabilities in applications, systems, and networks before they can be exploited by malicious attackers. These tools play a crucial role in safeguarding sensitive data, ensuring compliance, and maintaining trust with users. In mo
8 min read
Intrusion Detection System (IDS)
Intrusion is when an attacker gets unauthorized access to a device, network, or system. Cyber criminals use advanced techniques to sneak into organizations without being detected. Intrusion Detection System (IDS) observes network traffic for malicious transactions and sends immediate alerts when it
9 min read
What is Vulnerability Assessment?
Living in a world with more and more complex threats posted by cybercriminals, it is imperative that you shield your networks. A vulnerability scanning is done to understand areas that are prone to an attack by the invader before they exploit the system. The above measures not only protect data and
6 min read
Secure coding - What is it all about?
So you think you can code? Well thatâs great to know⦠The world definitely needs more geeks and nerds like you and me⦠But, are your programs secure? This is what this whole article is all about. As a programmer, it is not only your job but also moral responsibility to ensure that your codes donât h
6 min read
Cyber Crime Investigation