web-inject
web-inject
web-inject
The development of this document is/was funded by three grants from the DOD Grant Number H98230-19-
1-0301
1 Overview
This Labtainer exercise explores injections. This lab covers SQL/NoSQL injections along with Web
based injections using PUT/POST/PATCH.
2 Lab Environment
This lab runs in the Labtainer framework, available at http://my.nps.edu/web/c3o/labtainers. That site
includes links to a pre-built virtual machine that has Labtainers installed, however Labtainers can be run
on any Linux host that supports Docker containers.
labtainer web-inject
On most Linux systems, these are links that you can right click on and select “Open Link”. If you chose
to edit the lab report on a different system, you are responsible for copying the completed report
back to the displayed path on your Linux system before using “stoplab” to stop the lab for the last
time.
The resulting virtual terminal is connected to the student workstation; you will have OWASP ZAP and
Firefox located on this workstation.
3 Network Configuration
The student workstation (web-inject) is configured to have IP address 192.168.99.101 while the
vulnerable webserver (web-inject-server) is 192.168.99.100;
Web-inject Web-inject-server
(Student workstation) (Vulnerable webserver)
192.168.99.101 192.168.99.100
4 Lab Tasks
It is assumed that the student has received instruction or independent study on the basic operation of
web operations
Record in Item #1 of your report why Firefox might have been chosen to be the web browser used.
Could Chrome or another web browser have been selected? What are some of the development tools
that differ between the main web browsers?
Note: if Firefox is running at the terminal and the “&” was not included then Firefox is not running in the
background. Close Firefox and reopen using “Firefox &” at the terminal
OWASP ZAP Application should be open and it should be prompting the user for input.
• OWASP ZAP user input: select “yes, I want to persist this session with the name based
on the current timestamp” then click start. This will open ZAP application.
• If you are prompted to “Manage Add-on” click close
• Search for a product, the user should see that the URL doesn’t change between the
different product. The user can view all product detail by navigating to the following
URL:
o https://192.168.99.100:3000/api/Products/
• This gives the learner a list of product IDs and will be used in modifying data in the
proceeding steps. Take note of “Orange Juice” which is product ID2 and pay attention to
the description.
• From the student workstation terminal, the learner will use curl to see if the options for a
specific product. Type the following command at the terminal:
o curl -X OPTIONS -D –
‘http://192.168.99.100:3000/api/Products/2’
• Pay attention to the Access-Control-Methods, if the learner is unsure of the different
types then a review of HTTP requests will need to be reviewed. The fact that it accepts
PUT, should mean that we can push updates via the terminal.
• From the student workstation terminal, type the following command
o curl -X PUT
"http://192.168.99.100:3000/api/Products/2" -H
"Content-Type: application/json" --data-binary
'{"description":"TEST"}'
• check the Products page to see if the description was updated. The product URL is:
o https://192.168.99.100:3000/api/Products/
• Modify the curl PUT command to change the price of product ID 8, make sure that the
price change is reflected on the web site and ensure that the price matches even when you
add the product to the shopping cart.
Record in Item #3 of your report why is allowing HTTP Put to write to a web site a bad idea?
Record in Item #4 of your report what is the main purpose of a HTTP Put request?
4.6 User Login Exploit using Injection (SQL Injection & HTTP Post Injection)
According to OWASP WSTG-INPV-05, an SQL injection testing checks if it is possible to inject
data into the application so that it executes a user-controlled SQL query in the database. Testers
find a SQL injection vulnerability if the application uses user input to create SQL queries
without proper input validation. A successful exploitation of this class of vulnerability allows an
unauthorized user to access or manipulate data in the database.
An SQL injection attack consists of insertion or “injection” of either a partial or complete SQL
query via the data input or transmitted from the client (browser) to the web application. A
successful SQL injection attack can read sensitive data from the database, modify database data
(insert/update/delete), execute administration operations on the database (such as shutdown the
DBMS), recover the content of a given file existing on the DBMS file system or write files into
the file system, and, in some cases, issue commands to the operating system. SQL injection
attacks are a type of injection attack, in which SQL commands are injected into data-plane input
in order to affect the execution of predefined SQL commands.
OWASP outlines the steps in testing for SQL injections by a few injections based attacks. First is
to perform a standard or classic SQL injection attack which will be completed in example 1.
OWASP further explains that you can also capture data and inject modified version in transit,
which will be review in example 2. In the last example the learner will combine what they have
learned in the first to examples and will be performing injection attacks to bypass user
authentication, this will be examined in example 3.
• The q= allows us to manipulate data. Try adding 1=1 after the equals sign, does this do
anything? In older version of SQL this might have returned an error, but this site is new
enough, so it does.
• Try modifying your search to use the following characters or combination of characters:
‘ ) ( - = “
• Below are two different URLs compare the two and see if there are any differences
http://192.168.99.100:3000/#/search?q=’))--
http://192.168.99.100:3000/#/search
Record in Item #5 of your report what are the prices for products 1, 3, and 24?
Record in Item #6 of your report what does the following snip it of HTTP code represent without
the double quotes “?q=’))—"
Record in Item #7 of your report why does 1=1 equate to an injection violation?
Record in Item #9 of your report in terms of web technology what defines REST and JSON?
• Navigate to the product search page while having the “inspect element” portion of
Firefox open.
• Add an item to the empty shopping cart (the shopping cart must be empty due to adding
an item to an empty cart is different from adding an item to a shopping cart with other
items present.
• In OWASP Zap, you should be able to see the history and you should be able to identify
a POST request to the following URL
http://192.168.99.100:3000/api/BasketItems/1
o Important to note the number 1 is the user ID so it may be different from you
• The request payload looks like the following
{"ProductId":1,"BasketId":"1","quantity":1}
o The product ID is the product in the card, the basket ID is the current user ID,
and the quantity is the quantity of the product.
• We can modify the order and send the request back to the website. Select a different
product and in the quantity, section list a negative number. Resend the request and the
web site should accept the order and we should see a refund.
Record in Item #10 of your report how might a web-based attack be prevented?
NoSQL database calls are written in the application's programming language, a custom
API call, or formatted according to a common convention (such as XML, JSON, LINQ,
etc). Malicious input targeting those specifications may not trigger the primarily
application sanitization checks. For example, filtering out common HTML special
characters will not prevent attacks against a JSON API.
Go onto OWASP website and research the main different between SQL and NoSQL injection.
Answer the two questions below. See reference 1 and 2 for direct links.
Record in Item #11 of your report define what a NoSQL based attack is and how the differ from a
traditional SQL based attack.
Record in Item #12 of your report which type of an attack is becoming more predominate?
• It returns nothing, but that doesn’t mean it wasn’t useful. In firefox, right click and
select “Inspect Element” you should see something that states there are not the same
number of columns. This means we will need to adjust the union statement. Try the
following command and see if it also yields the same result as above. Command
invalid')) UNION SELECT NULL,email,password,id,NULL,
FROM USERS--
• The same error should occur so that means we need additional NULLs to make up the
additional columns. Try typing in the following command and see if it still yields the
same results. Command:
Record in Item #13 of your report why are there so many NULLs needed in example 1, bullet point
3?
Record in Item #14 of your report why is knowing table structure critical for conducting insert or
update statements using SQL?
Record in Item #15 of your report any interesting finding of the report. Find three areas of interest
and explain why they were important and how they may have an impact on the security of this
website.
from the host Labtainer working directory. You can always restart the Labtainer to continue your work.
When the Labtainer is stopped, a zip file is created and copied to a location displayed by the stoplab
command. When the lab is completed, send that zip file to the instructor.
References
1. OWASP WSTG-INPV-05 - Testing for SQL Injection
https://owasp.org/www-project-web-security-testing-
guide/latest/4-Web_Application_Security_Testing/07-
Input_Validation_Testing/05-Testing_for_SQL_Injection