Skip to the content.

~

~/Security

~/Security/Appsec

~/Security/Appsec/OWASP10



input validation, input validation, input validation.

SQL injection (SQLi) is a web security vulnerability that allows an attacker to interfere with the queries that an application makes to its database. It generally allows an attacker to view data that they are not normally able to retrieve. This might include data belonging to other users, or any other data that the application itself is able to access. In many cases, an attacker can modify or delete this data, causing persistent changes to the application’s content or behavior.

High impact-can impact all of the CIA.

Occur when webapps don’t have proper boundaries set up.

Use a prepared statements-more efficient, more secure. They prevent SQLi as they separate the code from the data.

If you can’t use prepared statements, escape special characters.

The fundamental property that allows injection to happen-code can be interpreted as either instructions or data.

Cause

Prevention

Performing an SQLi Attack

Retrieving hidden data

The query given is- SELECT * FROM products WHERE category = 'Gifts' AND released = 1

change the parameters in the request to perform a query that returns all products

the query would be

SELECT * FROM products WHERE category = '' OR 1=1--' AND released = 1

Subverting application logic

On the login page, we may assume that the SQL query is

SELECT * FROM users WHERE username = 'wiener' AND password = 'bluecheese'

we can either manipulate the username or password parameters in a similar way to bypass authentication

In a real-life situation, you would be able to see what tech stack the website is running, and guess the username of the administrator account. At this point, you only need to make the SQL server interpret the code for the password checking logic as a comment, bypassing authentication

UNION attack

Finding the number of columns

For a UNION query to work, two key requirements must be met:

two effective methods to determine how many columns are being returned from the original query

Finding compatible datatypes of columns

Performing the UNION attack

I have determined the number of columns returned by the original query and found which columns can hold string data, and can now retrieve interesting data

If after Examining the database it surfaces that the database contains a different table called users, with columns called username and password, I can now perform an SQL injection UNION attack that retrieves all usernames and passwords, and use the information to log in as the administrator user

Examining the Database

Resources

Cheat Sheets

Quick Reference to SQLi

Portswigger’s SQLi Cheat Sheet

wip