SQL Injection Attacks | Shahul Hameed
Lab 1: SQL injection UNION attack, determining the number of columns returned by the query
This lab contains an SQL injection vulnerability in the product
category filter. The results from the query are returned in the application's
response, so you can use a UNION attack to retrieve data from other tables. The
first step of such an attack is to determine the number of columns that are
being returned by the query. You will then use this technique in subsequent
labs to construct the full attack.
To solve the lab, determine the number of columns returned by
the query by performing an SQL injection UNION attack that returns
an additional row containing null values.
Solutions:
- Use Burp Suite to intercept and
modify the request that sets the product category filter.
- Modify the category parameter, giving it the value '+UNION+SELECT+NULL--. Observe that an error occurs.
- Modify the category parameter to add an additional column containing
a null value: '+UNION+SELECT+NULL,NULL--
- Continue adding null values until the error disappears and the response includes additional content containing the null values.
Lab 2: SQL injection UNION attack, finding a column containing text
Introduction
This
lab contains an SQL injection vulnerability in the product category filter. The
results from the query are returned in the application's response, so you can
use a UNION attack to retrieve data from other tables. To construct such an
attack, you first need to determine the number of columns returned by the
query. You can do this using a technique you learned in a previous lab. The next step is to identify a column that
is compatible with string data.
The
lab will provide a random value that you need to make appear within the query
results. To solve the lab, perform an SQL injection UNION attack that returns an additional row
containing the value provided. This technique helps you determine which columns
are compatible with string data.
Solution:
- Use Burp Suite to intercept and
modify the request that sets the product category filter.
- Determine the number of columns that are being returned
by the query. Verify
that the query is returning three columns, using the following payload in
the category parameter: '+UNION+SELECT+NULL,NULL,NULL--
- Try replacing each null with
the random value provided by the lab, for example: '+UNION+SELECT+'abcdef',NULL,NULL--
- If an error occurs, move on to the next null and try that instead.
Lab 3: SQL injection UNION attack, retrieving data from other tables
This lab contains an SQL injection vulnerability in the product category
filter. The results from the query are returned in the application's response,
so you can use a UNION attack to retrieve data from other tables. To construct
such an attack, you need to combine some of the techniques you learned in
previous labs.
The database contains a different table called users
, with columns called username
and password
.
To solve the lab, perform an SQL
injection UNION attack that retrieves all usernames and passwords, and use
the information to log in as the administrator
user.
Solution
- Use Burp
Suite to intercept and modify the request that sets the product category
filter.
- Determine
the number
of columns that are being returned by the query and which
columns contain text data. Verify that the query is returning two
columns, both of which contain text, using a payload like the following in
the category parameter:
'+UNION+SELECT+'abc','def'--
. - Use the
following payload to retrieve the contents of the
users
table:'+UNION+SELECT+username,+password+FROM+users--
- Verify that the application's response contains usernames and passwords.
The database contains a different table called users
, with columns called username and password.
To solve the lab, perform an SQL injection UNION attack that retrieves all usernames and password, and use the information to log in as the administrator
user.
Solutions
- Use Burp
Suite to intercept and modify the request that sets the product category
filter.
- Determine the number of columns that are being returned by the query and which columns contain text data. Verify that the query is returning two columns, only one of which contain text, using a payload like the following in the
category
parameter:'+UNION+SELECT+NULL,'abc'--
Use the following payload to retrieve the contents of the
users
table:'+UNION+SELECT+NULL,username||'~'||password+FROM+users--
Verify that the application's response contains usernames and passwords.
This lab contains an SQL injection vulnerability in the product category
filter. You can use a UNION attack to retrieve the results from an injected
query.
To solve the lab, display the database version string.
Solution
- Use Burp
Suite to intercept and modify the request that sets the product category
filter.
- Determine
the number of columns
that are being returned by the query and which columns contain
text data.
Verify that the query is returning two columns, both of which contain
text, using a payload like the following in the
category
parameter:'+UNION+SELECT+'abc','def'+FROM+dual--
- Use the following
payload to display the database version:
'+UNION+SELECT+BANNER,+NULL+FROM+v$versio--
https://portswigger.net/web-security/sql-injection/cheat-sheet
Step 1: Intercept the UI in the burp suite application.
Find the number of columns using the ORDER BY statement.
Payload: GET /filter?category=Accessories'+ORDER+BY+2+-- HTTP/1.1
Step 2: Find the datatype of columns in the table.
Oracle database: SELECT Statement
Payload: GET
/filter?category=Accessories'+UNION+SELECT+'a',+'a'+FROM+DUAL--
Step 3: Get the version of the database.
Oracle database: SELECT Version statement
Payload:
GET
/filter?category=Accessories'+UNION+SELECT+banner,+NULL+FROM+v$version--
Lab 6: SQL injection attack, querying the database type and version on MySQL and Microsoft
Introduction
This lab contains an SQL injection vulnerability in the product category
filter. You can use a UNION attack to retrieve the results from an injected
query.
To solve the lab, display the database version string.
Solution
- Use Burp
Suite to intercept and modify the request that sets the product category
filter.
- Determine
the number of columns
that are being returned by the query and which columns contain
text data.
Verify that the query is returning two columns, both of which contain
text, using a payload like the following in the
category
parameter:'+UNION+SELECT+'abc','def'#
- Use the
following payload to display the database version:
'+UNION+SELECT+@@version,+NULL#
Step 1: Intercept the UI in the burp suite application.
Find the number of columns using the ORDER BY statement.
Note: Here comment using (#) instead of (--)
Comments
Post a Comment