SQL Injection Fundamentals
| Field | Value |
|---|---|
| Module ID | 33 |
| Difficulty | Medium |
| Tier | Tier 0 |
| Category | Offensive |
| Estimated Time | 8 hours |
| Cubes Earned | 0 |
| Experience Points | 900 |
| Creators | 21y4d |
| Last Updated | 2025-10-01T00:00:00.000000Z |
| URL | https://academy.hackthebox.com/app/module/33 |
Module Includes
- 17 Sections
- 12 Interactive Exercises
- 1 Assessments
- 0 Cubes
Module Description
Databases are an important part of web application infrastructure and SQL (Structured Query Language) to store, retrieve, and manipulate information stored in them. SQL injection is a code injection technique used to take advantage of coding vulnerabilities and inject SQL queries via an application to bypass authentication, retrieve data from the back-end database, or achieve code execution on the underlying server.
Module Summary
Database Management systems offer faster storage and retrieval of data in comparison to traditional file storage. This makes them the medium of choice for storing data such as credentials, posts, and comments used by web applications. However, improperly implemented SQL logic can be dangerous and can lead to authentication bypass, information disclosure, remote code execution, and total server compromise.
Applications implement code to create SQL queries to interact with databases. These queries can incorporate user input, which may not be properly sanitized. This leads to the creation of queries that cause unintended actions other than what the developer expected.
This module aims to develop the skills necessary to identify and exploit SQL injection vulnerabilities, mainly for MySQL databases, and as an intro to all other types of SQL injections.
In this module, we will cover the following topics:
- Basics of databases and their different types
- Basics of SQL and MySQL
- Basic statements and operators in MySQL and how to use them
- What are SQL injections, and how can we use them
- Use SQL injections to subvert the web application logic and bypass authentication
- Use UNION SQL injections to dump data from different tables and databases within the DBMS
- Use SQL injections to read files of the back-end server
- Use SQL injections to write a web shell on the back-end server and gain remote control over it
- How to mitigate such SQL injections and patch your code
CREST CPSA/CRT-related Sections:
- All sections
CREST CCT APP-related Sections:
- All sections
CREST CCT INF-related Sections:
- All sections
This module is broken down into sections with accompanying hands-on exercises to practice each of the tactics and techniques we cover. The module ends with a practical hands-on skills assessment to gauge your understanding of the various topic areas.
As you work through the module, you will see example commands and command output for the various topics introduced. It is worth reproducing as many of these examples as possible to reinforce further the concepts introduced in each section. You can do this in the Pwnbox provided in the interactive sections or your own virtual machine.
You can start and stop the module at any time and pick up where you left off. There is no time limit or "grading," but you must complete all of the exercises and the skills assessment to receive the maximum number of cubes and have this module marked as complete in any paths you have chosen.
The module is classified as "Medium" but assumes a working knowledge of the Linux command line and an understanding of information security fundamentals.
A firm grasp of the following modules can be considered prerequisites for successful completion of this module:
- Introduction to Networking
- Linux Fundamentals
- Introduction to Web Applications
- Web Requests
Sections
17 sections - 12 Interactive
| # | Group | Type | Title |
|---|---|---|---|
| 1 | Introduction | theory | Introduction |
| 2 | Databases | theory | Intro to Databases |
| 3 | theory | Types of Databases | |
| 4 | MySQL | interactive | Intro to MySQL |
| 5 | interactive | SQL Statements | |
| 6 | interactive | Query Results | |
| 7 | interactive | SQL Operators | |
| 8 | SQL Injections | theory | Intro to SQL Injections |
| 9 | interactive | Subverting Query Logic | |
| 10 | interactive | Using Comments | |
| 11 | interactive | Union Clause | |
| 12 | interactive | Union Injection | |
| 13 | Exploitation | interactive | Database Enumeration |
| 14 | interactive | Reading Files | |
| 15 | interactive | Writing Files | |
| 16 | Mitigations | theory | Mitigating SQL Injection |
| 17 | Closing it Out | interactive | Skills Assessment - SQL Injection Fundamentals |
Conclusion
In this module, we walked through an overview of database management systems (DBMS) and structured query language (SQL). We built our own SQL queries from the ground up, looked at union-based SQL injection flaws, and discusses mitigations that can be taken to defend against SQL injection.
Module Key Takeaways
- An understanding of DBMS and SQL
- The ability to craft and interpret SQL queries
- Exploiting SQL injections to subvert the web app logic
- Exploiting union-based SQL injection vulnerabilities
- Leveraging SQL injection for operating system interaction
- Mitigations to prevent SQL injection