Skip to content

SQL Injections

Alexis edited this page Apr 16, 2020 · 8 revisions

#SQL Injections

What is an SQL Injection ?

SQL injections are one of the most common form of attacks on the web.

An SQL injection is pretty similar to an XSS attack except that, this time, the hacker enters SQL statements that could delete your whole database, or show sensitive information. SQL injections are extremelly dangerous for your web application and could cost you alot if one of them manages to make their way onto your website.

here's an example of a javascript system that handles a login page

txtUserId = getRequestString("UserId");
txtSQL = "SELECT * FROM Users WHERE UserId = " + txtUserId;

now here's what a user could do to trick your web application into spilling sensitive info

Imagine this is your login page

Username: myUser

Password: myPass

but what if the hacker decided to enter this instead ?

Username: myUser

Password: " or ""="

Then the SQL query just executed looks like this:

SELECT * FROM Users WHERE Name ="" or ""="" AND Pass ="" or ""=""

This statement returns all the rows inside the users table, since or ""="" is always TRUE Now, that's scary not to say the least !, and it only takes a minute or so to execute this attack, anybody can execute this, imagine what a senior hacker with bad intentions could do to your application ! you, your employees and your customers' privacy are at risk, And as I mentioned before, if your customers cannot trust your website they will not make business with you ! First impression is something really important when it comes to your web application.

How can a hacker damage my database ?

imagine you have a form, in which you can enter a specific ID, as an example we will take an "Item Return" Form

Item Id:340 (Hint: This can be found printed on the back of the item)

Reason for returning the product: bla bla bla, the item is not functioning correctly.....

Now that's what a normal user would type, but if a hacker wanted to delete some tables inside your database he could do:

Item Id:340; DROP TABLE Debts

This translates to this in sql:

SELECT * FROM Users WHERE UserId = 105; DROP TABLE Suppliers;

The hacker would've successfully dropped the Debts table, no more debts.. Yay !

For the hacker of course...

Conclusion

That pretty much sums up what an SQL Injection is, now if you want to protect yourself against these types of attacks you can read this

Clone this wiki locally