SQL Injection
Introduction
Structured Query Language (SQL)
#To connect to a database server (You will be asked for the password after pressing Enter)
mysql -u <User-Name> -p
#To connect with the password directly (Not recommended as the password will be stored in the terminal history)
mysql -u <User-Name> -p<Password>
#To connect to a remote database server
mysql -u <User-Name> -h <Remote-Server> -P <Port-Number> -p
#To list databases
SHOW DATABASES;
#To select a database
USE <Database-Name>;
#To list tables
SHOW TABLES;
#To get information about the data type in a table
DESCRIBE <Table-Name>;
#To insert rows into a table
INSERT INTO <Table-Name> VALUES (<Column1-Value>, <Column2-Value>, <Column3-Value>, ...);
#To insert rows into specific columns (Skipping columns with the 'NOT NULL' constraint will result in an error)
INSERT INTO <Table-Name>(<Column-Name>, <Column-Name>, ...) VALUES (<Column-Value>, <Column-Value>, ...);
#To insert multiple rows at a time
INSERT INTO <Table-Name>(<Column-Name>, <Column-Name>, ...) VALUES (<Column-Value>, <Column-Value>, ...),(<Column-Value>, <Column-Value>, ...);
#To select everything from a table
SELECT * FROM <Table-Name>;
#To select specific columns
SELECT <Column-Name>, <Column-Name>,... FROM <Table-Name>;
#To delete a table (Directly delete without a confirmation message)
DROP TABLE <Table-Name>;
#To edit a table
ALTER TABLE <Table-Name> <Edit-To-Be-Done>;
#To edit a record
UPDATE <Table-Name> SET <Column-Name>=<New-Value>, <Column-Name>=<New-Value>, ... WHERE <Condition>;
#To filter results, use WHERE or LIKE. (String and date data types should be surrounded by single quotes (') or double quotes ("), while numbers can be used directly.)
SELECT * FROM <Table-Name> WHERE <Condition>;
#Using LIKE to match a pattern. % is used to match zero or more characters. _ is used to match only one character
SELECT * FROM <Table-Name> WHERE <Column-Name> LIKE <Condition>;SQL Injection
Checking for SQLi
OR Injection
Using Comments
Union Injecton
Exploitation
Exploitation
Database Enumeration
Reading and Writing Files
Reading Files
Writing Files
Mitigating SQL Injection
SQLMap
Last updated