StackZero
  • Homepage
  • Cryptography and Privacy
  • Ethical Hacking
  • Reverse Engineering
  • Contacts
  • About Me
No Result
View All Result
StackZero
No Result
View All Result

SQL Injection: What You Need to Know

July 12, 2022
in Ethical Hacking
0 0
SQL Injection: What You Need to Know
0
SHARES
838
VIEWS
Share on FacebookShare on Twitter

Table of Contents

Toggle
  • What is SQL injection?
    • In-Band SQL injection
    • Blind SQL injection
  • What are the different types of SQLi?
  • A general idea about the SQLi
  • How to prevent SQL injection?
  • How dangerous can it be?
  • Conclusion

What is SQL injection?

SQL injection (SQLi) is an attack on a web application (among the most known along with XSS) that exploits a security vulnerability in a target software, in particular, it allows the attacker to do some operations on the vulnerable database.

On the basis of past experiences, this kind of attack can be disastrous to those who experience it.


Just to better understand let’s list what can lead to a potential SQLi

  • Dynamic SQL queries: This means that the user has a kind of control over the query and can insert some parameters. The general rule is that everything that can be determined at the design time has to be static. However it’s not always possible, so this is the parameter with less control among the three.
  • Error revelation: Errors can give the attackers some extra information such as database or table names. Even in this case, we can rely on the general rule that, in a production environment, we must show ONLY the information the final user has to see.
  •  Insufficient input validation: The application has to sanitize external inputs every time it receives them. Do always that and you will prevent a lot of trouble.

    The combination of these elements could allow an attacker to execute malicious SQL statements that could manipulate data, compromise the security of the website, or even gain access to the server.

Here is the list of all the articles about SQL injection for quick navigation:

In-Band SQL injection

  • SQL Injection: What You Need to Know
  • Learn SQL injection in practice by hacking vulnerable application!
  • How To Hack With SQL Injection Attacks! DVWA low security
  • Hack With SQL Injection Attacks! DVWA medium security
  • Hack With SQL Injection Attacks! DVWA high security
  • Mastering SQL Injection on DVWA Low Security with Burp Suite: A Comprehensive Guide
  • Mastering DVWA SQL Injection: Medium Security with Burp Suite

Blind SQL injection

  • Blind SQL injection: How To Hack DVWA With Python (Low Security)
  • Blind SQL Injection: How To Hack DVWA With Python (Medium Security)
  • Blind SQL Injection: How To Hack DVWA With Python (High Security)

What are the different types of SQLi?

Even if you can find online many different classifications of the SQLi vulnerability, it doesn’t really matter and they are all equivalent.

However, I want to show you the classification I prefer among the ones I found, and I’m sure it can help you to understand better.

Anyway before explaining that, could be useful to have a visual overview, so I prepared this essential schema:

sql injection types

Now we can go a bit deeper and see what this chart represents:

  • In-band SQLi: An in-band SQL injection is where the attacker is able to use the same channel to inject the malicious SQL code and relay the results of the code execution back.
    • Union-based It uses the UNION SQL operator that can merge multiple SELECT queries. It can be useful because allows getting data from tables that differ from the one to which the query belongs.
    • Error-based: As we discussed in the introduction an attacker can force some errors in order to get extra information from the DB.
  • Inferential (Blind) SQLi: In this case, the attacker sends his exploit and then analyzes the response. The name “Blind” is because the application doesn’t show information to the attacker but he has to infer them from the application’s behavior.
    • Time-based The attacker crafts the payload making the application wait some seconds only if a particular condition is verified. What it has to do is just measure the response time and infer the data.
    • Boolean-Based: This attack takes advantage of an application behavior depending on a condition. The result can let the attacker deduce some useful information.
  • Out-of-band SQLi: In this type of SQLi the attacker can use some out-of-band channel to exfiltrate data from the database or to execute arbitrary commands on the server. For example, the attacker can trigger some DNS or HTTP requests.

A general idea about the SQLi

Even if this is just an introductory article, I’d like to show you a practical example, in order to better solidify the fundamental concepts.

Let’s imagine a website that takes the unsanitized username and password from the login form and put it inside the query: something like this.

SELECT * FROM users WHERE username = '$username' AND password = '$password'

In this case, the attacker has complete control of the input and can insert a crafted password value in a way to make the query always True.
Let’s see how:
Imagine that the attacker inserts as a password the string shown below:

' OR 1=1 --

In some DBMS (Database Management System) like MariaDB and MySQL, everything to the right of the string “–“ is considered a comment.
So, the final query that the software passes to the DBMS is:

SELECT * FROM users WHERE username = '$username' AND password = '' OR 1=1 --'

The query above would return all rows from the “users” table since the WHERE clause would always evaluate to true. This would allow the user to log in without a valid password.

Probably it’s enough to have a general idea of what SQL injection is.

Just to stress the concept, the attacker can concatenate to the query whatever he wants like list private entries, guess passwords, drop tables, and much more, depending on the entity of the vulnerability.

How to prevent SQL injection?

There are a number of ways to prevent SQL Injection, including:

  • Parameterized queries: A parameterized query is a query in which applications use placeholders for one or more user input values.
  • Stored procedures: A stored procedure is a set of SQL statements that an application can execute on a database server.
  • White-list input validation: White-list input validation is a method of data validation. With this validation technique, the application can enter into a system only data that meets certain criteria.
  • Escaping all user input: Input escaping is the process of transforming special characters in input so that the target system will interpret them literally.
  • Using an object-relational mapper (ORM): An object-relational mapper (ORM) is a code library that automates the transfer of data stored in relational databases tables into objects. It usually provides a set of functions with prebuild security checks. Some of the best-known ORMs are:
    • Hibernate
    • SQLAlchemy
    • MyBatis
  • Using a Web Application Firewall: A web application firewall (WAF) is a type of firewall that filters traffic to and from a web application. It can run as a network appliance, server plugin, or service. A WAF inspects web traffic to and from a web application and filters out malicious traffic, so it can detect an SQLi.

How dangerous can it be?

In order to understand the potential damage of such vulnerability, we can just remember two of the most famous attacks that exploited SQLi.

  • The most harmful SQLi attack in history was the 2017 Equifax data breach, which affected 145 million people. The attackers were able to exploit a vulnerability in Equifax’s website to gain access to sensitive information including social security numbers, dates of birth, and addresses.
  • Another famous event was in 2015, the Ashley Madison data breach, in which hackers gained access to the personal information of over 30 million users of the Ashley Madison website. The data leaked included sensitive information such as user names, email addresses, and credit card numbers.

Conclusion

SQL injection is a serious security vulnerability that can lead to sensitive data being leaked or even servers being taken over. We have seen in the previous paragraph how dangerous it can be, so don’t underestimate that.
It is important to take the discussed measures to prevent SQLi, you cannot save on cybersecurity, the potential damages are enormous. So the advice is always to rely on a real professional in the field to put in place security measures.

Tags: injectionsqlsql injectionweb security
Previous Post

How to Install FlareVM on VirtualBox (Step-by-Step Tutorial)

Next Post

Learn SQL injection in practice by hacking vulnerable application!

Next Post
Learn SQL injection in practice by hacking vulnerable application!

Learn SQL injection in practice by hacking vulnerable application!

You might also like

Cryptographic functions

Cryptographic Hash Functions in Python: Secure Your Data Easily

November 3, 2024
Malware Obfuscation Techniques: All That You Need To Know

Malware Obfuscation Techniques: All That You Need To Know

March 25, 2024
How To Do Process Enumeration: An Alternative Way

How To Do Process Enumeration: An Alternative Way

March 4, 2024
How To Do DLL Injection: An In-Depth Cybersecurity Example

How To Do DLL Injection: An In-Depth Cybersecurity Example

February 8, 2024
Process Injection By Example: The Complete Guide

Process Injection By Example: The Complete Guide

January 24, 2024
How To Build Your Own: Python String Analysis for Malware Insights

How To Build Your Own: Python String Analysis for Malware Insights

November 10, 2023

StackZero

StackZero is a specialized technical blog dedicated to the realm of cybersecurity. It primarily provides insightful articles and comprehensive tutorials designed to educate readers on developing security tools. The blog encompasses a broad spectrum of subjects, starting from the foundational principles of cryptography and extending to more sophisticated areas such as exploitation and reverse engineering. This makes StackZero an invaluable resource for both beginners and professionals in the field of cybersecurity.
The blog covers a wide range of topics, from the basics of cryptography to the more advanced topics of exploitation and reverse engineering.

Tags

application security blind sqli blind sql injection bruteforce c cesar cipher command injection cryptography ctf cybersecurity debugging dom-based xss dvwa ethical-hacking ethical hacking exploitation file inclusion gdb hacking injection javascript malware malware analysis malware evasion network-security pentesting lab picoctf pico ctf python reflected xss reverse engineering sql sqli sql injection static analysis stored xss substitution substitution cipher vulnerable application web application security web exploitation web security windows windows api xss
  • About Me
  • Contacts
  • HomePage
  • Opt-out preferences
  • Privacy Policy
  • Terms and Conditions

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Manage Cookie Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
View preferences
{title} {title} {title}
No Result
View All Result
  • Homepage
  • Cryptography and Privacy
  • Ethical Hacking
  • Reverse Engineering
  • Contacts
  • About Me