21 Aug 2023
SQL Injection: The Silent Threat
Hey there, pals! :D, I was pondering over the perfect topic for my first blog post. I didn't want to go with something overly simple or too advanced, aiming to engage both cyber geeks and friends. Then it hit me: why not dive into the intriguing realm of injection vulnerabilities? These little troublemakers have the potential to take us on quite a ride, making them a key player in OWASP's top 10 vulnerabilities. So, let's buckle up and explore the fascinating journey of injection vulnerabilities together!
π Feel free to chip in.
Absolutely, the primary goal here isn't to provide you with specific payloads. After all, there's already a treasure trove of payloads available from diverse sources β you can find an array of these, just like a buffet of hacking goodness. As a prime example of this, check out resources like: SQL Injection | pentestmonkey
We all know that SQL injection is a huge deal in the cybersecurity world, and we've all seen our pals racking up those bounties like champs
( Ν‘ββ―ΝΚ Ν‘β) β no jealousy here, just respect! But why is it so critical, Is it all about Database Enumeration? Well, let's take a whirlwind tour through its potential, shall we?
READING FILES:
You might have a sense of this from Database Enumeration, but the real deal here is using the privileges of the DB User to snoop around in the system's files.
And guess what?
This could potentially lead to system exploitation. Exciting, right?
Take MySQL, for instance. If the DB user has the mighty FILE
privilege, it's like holding the keys to the kingdom.
You can load the contents of a file into a table and then swipe that data from the table to read files ( Ν‘β‘β―ΝΚ Ν‘β‘). Just imagine, you can use LOAD_FILE('/PATH')
to load up any juicy files you can get your hands on. Or brace yourself, because it gets even wilder β you can even load up the source code of the backend server!
For instance, LOAD_FILE("/var/www/html/search.php")
could give you a peek behind the curtains.
WRITING FILES:
Absolutely, you can leverage SQL injection to take things up a notch and actually write files to the system. This includes the possibility of creating web shells that could potentially lead to Remote Code Execution (RCE) within the system.
To achieve this, there are three key prerequisites:
1. User with FILE
Privilege:
As mentioned earlier, having a user with the FILE
privilege is crucial. This privilege opens up the door for file-related operations.
2. Unrestricted secure_file_priv
:
Here comes the kicker β the MySQL global secure_file_priv
variable needs to be unchecked. For instance, you could run a query like:
blabla' UNION SELECT 1, variable_name, variable_value, 4 FROM information_schema.global_variables where variable_name="secure_file_priv"-- -
.
If this query shows an empty secure_file_priv
value, it's a signal that you've got the green light to read and write files wherever you fancy (β‘Μβ―ΝΚ Μβ‘).
3. Write Access to Desired Location:
Lastly, you'll need the golden key β write access to the specific location on the back-end server where you intend to create or modify files.
SELECT
strings into files. This means you can write just about any file you can imagine to the back-end server using INTO OUTFILE '/PATH/file'
. blabla' union select '', '<?php system(COMMAND); ?>', '', '' into outfile '/var/www/html/shell.php'-- -
.