SQL Based on Portswigger Lab 3

This type of UNION attack is done using the UNION keyword, which lets you execute an additional SELECT query and append the results to the original query.

For example,

if an application executes the following query containing the user input "Gifts":

SELECT name, description FROM products WHERE category = 'Gifts'

Then an attacker can submit the input:

' UNION SELECT username, password FROM users--

Blind SQL: This means that the application does not return the results of the SQL query or the details of any database errors within its responses.

First-order SQL injection:  It arises when the application takes user input in an unsafe way.

Second-Order SQL injection: It arises when the application takes user input from an HTTP request and stores it for future use. Later when handling a different HTTP request, the application retrieves the stored data and incorporates it into a SQL query in an unsafe way.

Second-order SQL injection often arises in situations where developers are aware of SQL injection

Examining the database:

Detecting and exploiting SQL injection work differently on different database platforms. For example:

  1. Syntax for String Concatenation
  2. comments
  3. Batched(or stacked queries)
  4. Platform-specific API’s
  5. Error messages.

String Concatenation:

For Oracle: ‘foo’|| ‘bar’

For Microsoft: ‘foo’ + ‘bar’

PostgreSQL: ‘foo’ || ‘bar’ OR ‘foo’ ‘bar’

MySQL: CONCAT(’foo’,’ bar’)

Substring( output : ba):

For Oracle: SUBSTR(’foobar’,2,4)

For Microsoft: SUBSTRING(’foobar’,4,2)

PostgreSQL: SUBSTRING(’foobar’,4,2)

MySQL: SUBSTRING(’foobar’,4,2)

Comments:

For Oracle: —comment

For Microsoft: —comment OR /comment*/

PostgreSQL: #comment OR /comment*/

MySQL: —comment OR /comment*/

Database Version:

For Oracle: SELECT banner FROM v$version

or SELECT version FROM v$instance

For Microsoft: SELECT @@version

PostgreSQL: SELECT version( )

MySQL: SELECT @@version

Batched(or stacked) queries:

For Oracle: Doesn’t support batched queries.

For Microsoft: QUERY-1-HERE ; QUERY-2-HERE

PostgreSQL: QUERY-1-HERE ; QUERY-2-HERE

MySQL: QUERY-1-HERE ; QUERY-2-HERE

In MySQL, batched queries typically can’t be used for SQL injection. However, this is occasionally possible if the target application uses certain PHP or Python APIs to communicate with the MySQL database.

Besides, there are many methods such as Time Delays, Condition Time Delays, and Extracting data via visible error messages. DNS lookup etc.

For more read, you can go to the SQL cheatsheet on Portswigger.

Obfuscate: Code obfuscation is fooled by the source code


#HappyHacking

Comments

Popular posts from this blog

My Starting 001

SQL injection attack, querying the database type and version on Oracle(Portswigger Lab 07)