Sanitize: An Introductory Dive into SQL Injection Exploitation
Introduction:
In the ever-evolving landscape of cybersecurity, a constant tug-of-war exists between security professionals and cyber adversaries. This time, we turn our focus towards a web security challenge aptly named "Sanitize," promising a supposedly super secure login page for us to test our mettle against. Our objective was simple - to escape the query context and log in as the administrator.
Machine Name: sanitize
Difficulty: Easy
Category: WEB
CHALLENGE DESCRIPTION
Can you escape the query context and log in as admin at my super secure login page?
Initial Interaction:
Upon launching the Sanitize machine, we were provided with an IP address. Navigating to this IP in our browser revealed a rather austere login screen, presumably guarding access to more sensitive data.

Our Strategy:
Faced with a login screen, we immediately thought of trying SQL Injection, a common method attackers use to exploit applications that use client-supplied data in SQL queries without first 'sanitizing' or validating the input. We hypothesized that the system might be vulnerable to a classic technique known as 'blind' SQL injection.
The Initial Test:

In the username field, we inputted "admin'—" and chose "password" as the password. Much to our surprise, this first attempt was immediately successful, revealing the coveted flag. But what had just occurred behind the scenes?

Decoding the Success:
When we entered "admin'—" as the username, we were trying to manipulate the SQL query executed by the system. If our hypothesis was correct, the system might be running a SQL query along the lines of:
"SELECT * FROM user WHERE username = 'admin'--' AND password = 'password';"
Here, the 'admin'—part attempts to conclude the SQL query prematurely, thereby making the system ignore anything that follows. The two dashes (--) in SQL are a way to introduce comment lines, essentially telling the SQL interpreter to ignore everything after them.
In this case, the SQL interpreter ignored the password check because of the comment dashes following the username 'admin'. This bypass allowed us to log in as the admin user without knowing the actual password.
Conclusion:
Our encounter with the Sanitize machine serves as a sobering reminder of how even seemingly innocuous input fields can be exploited using SQL injection if data is not properly sanitized. It underlines the critical importance of input validation and sanitization in any system that interacts with user-supplied data.
As cybersecurity enthusiasts, professionals, or simply users, we must continuously strive to learn and adapt in this dynamic field. After all, the next login screen we encounter could be the gate to a trove of sensitive information, waiting for the right (or wrong) key.