Â
SQL stands for Structured Query Language, designed for maintaining data in a Relational Database Management System(RDBMS): a database system which stores data in rows and columns
A transaction in SQL is known as Query
SELECT (NAME,PHONE_NUMBER ) FROM DIRECTORY
SELECT (NAME,PHONE_NUMBER) FROM DIRECTORY WHERE NAME= "DHAMAN ATTARWAL"
Two or more Conditions can be imposed at a time using AND,OR, NOT keywords
SELECT (NAME,PROFESSION) FROM DIRECTORY WHERE NAME="MUDI_JI" AND PROFESSION="TEA_SELLER"
SELECT (HOUR) FROM TIME UNION SELECT (MIN) FROM TIME
ERROR:SELECT(HOUR)FROM TIME UNION SELECT(MIN,SEC) FROM TIME
DROP TABLE DIRECTORY
TRUNCATE TABLE DIRECTORY
In simple terms, it’s injection/addition where data provided by user is included in a SQL query such that part of user’s input treated as an sql code.
Example:
Entering password as ‘ OR 1=1--
SELECT * FROM USERS where USER="admin" AND PASSWORD="" OR 1=1--AND PHONE_NUMBER=<RANDOM_NUMBERS>
SELECT * FROM USERS where USER="+req.body.user+" AND PASSWORD="+req.body.pass+" AND PHONE_NUMBER="+req.body.phn";
/*CORRECT: SELECT * FROM USERS where USER="admin" AND PASSWORD="password" AND PHONE_NUMBER=100*/
When Data in the Database can be  altered by a injection attack then , it is classified under a Second Order Attack
A very simple example is a register and reset password system which present in almost every web page
Let's suppose we have an account in a web site , using SQL to store data, with username: injection and we need to change the password without knowing the original password
Step 1: We Register in the website using the username as injection" -- and a random string as temp password
Now we would have users in the database with username injection and injection" --
Next: We would go to the reset password page and reset the password for injection" --
For this, we would use
On doing this we would change the password for username injection, lets see how this would work...
When we try to reset the password using , a command similar to this would be runningÂ
UPDATE ? SET PASSWORD="<NEW_PASSWORD>" WHERE USERNAME="<USERNAME>" AND PASSWORD="<OLD_PASSWORD>"
Which would be equivalent to in our example:
UPDATE ? SET PASSWORD="hello" WHERE USERNAME="injection" -- " AND PASSWORD="<OLD_PASSWORD>"
--THIS IS EQUIVALENT TO
UPDATE ? SET PASSWORD="hello" WHERE USERNAME="injection"
And so we were able to change the password of user: injection without knowing his password
Thank You 😄