21 Aug 2023

Unveiling the Dangers of
Injection Vulnerabilities
Part (1)

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.

Now, does this feel like navigating through a narrow alley with broad limitations? It might seem that way at first glance.
But hold on a second! Think about it – imagine the thrill of meeting these three conditions and the vast opportunities that would unlock. The excitement doesn't stop there. You can take it even further: directly 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'.
But wait, there's more – brace yourself for this audacious move. You can craft a web shell and drop it onto the server, then access it through the web application. This opens up a realm where you can execute system commands on the backend server through the web shell.
For instance, conjure up something like:
blabla' union select '', '<?php system(COMMAND); ?>', '', '' into outfile '/var/www/html/shell.php'-- - .
And then, like a magician's flourish – BOOM! 🎩πŸ’₯



There you have it – the tantalizing potential of SQL injection isn't just about database tricks.
It's about painting your digital canvas with creativity, exploration, and impact.
🎨 So keep that fire of curiosity burning, and always remember to navigate this journey ethically and responsibly. πŸŒŸπŸ”’