Using JTest for Security Testing
|
Andy Meneely, Ben Smith, and Laurie Williams |
| 1.0 | What is JTest? |
| 2.0 | Getting Started |
| 3.0 | Using Static Analysis |
| 4.0 | Gathering Metrics |
| 5.0 | Unit Test Generation |
| 6.0 | Resources |
| 7.0 | Troubleshooting |
|
JTest is a comprehensive automated testing tool that integrates static analysis, metrics, code coverage, unit test generation, and coding policy enforcement into a single platform. The idea is to combine all of the latter technologies into a single tool so that they can all be run at once. JTest employs a large database of known vulnerabilities that can be found in Java code, working with a variety of technologies (JSP, JDBC, etc). JTest is a customized version of the Eclipse IDE, so most of the project management work is performed with Eclipse features. In this tutorial, we will be employing three main features of JTest: static analysis, metrics, and unit test generation. |
|
In this tutorial, we assume that you already have JTest 8.4 set up and have the proper licensing. If you are using this tutorial for a class (e.g. CSC 591-003 for NCSU Fall 2009) consult your lab instructions on how to access and start JTest. Also, this tutorial assumes that your JTest has Subclipse installed. If you need to install Subclipse, use the Update Site found on their website and our tutorial on plugin installation. For this tutorial, we will be using the intentionally-vulnerable web application WebGoat to use JTest's features. We will first be installing WebGoat's source code by checking out the project from the Subversion repository.
![]() Figure 2.1: Checking to see if servers exist ![]() Figure 2.2: Checking out the WebGoat source ![]() Figure 2.3: Choosing a Dynamic Web Application ![]() Figure 2.4: Asserting that Tomcat is Target Runtime ![]() Figure 2.5: Setting JavaSource as an Eclipse source folder |
|
The goal of security-focused static analysis is to find specific vulnerabilities in your code. Thus, let's start with a location in the code where we know a vulnerability exists and see if JTest finds it. Let's start with an SQL Injection vulnerability.
![]() Figure 3.2: Locating the SQL Injection Vulnerability ![]() Figure 3.3: JTest Test Configurations ![]() Figure 3.4: Creating a new child ![]() Figure 3.5: Customizing the CWE configuration ![]() Figure 3.6: Running the customized user test ![]() Figure 3.7: The JTest execution window (after completion) ![]() Figure 3.8: Viewing the SQL injection vulnerabilities Next, we are going to switch to the Login module for a different vulnerability type.
![]() Figure 3.9: Inspecting the getAllEmployees method ![]() Figure 3.9: The code for the Login method in DBSQLInjection.java ![]() Figure 3.11: Reverting the code for DBSQLInjection.java |
|
JTest also gathers metrics about the code as it is going through static analysis. For performance reasons, let's create a JTest configuration that only collects metrics.
![]() Figure 4.1: The list of metrics JTest can gather ![]() Figure 4.3: Metrics gathering (after execution) ![]() Figure 4.4: Viewing the resultant metrics |
|
JTest not only runs static analysis and gathers metrics, it also generates basic unit tests that can also reveal vulnerabilities. In this part of the tutorial, we will be generating unit tests on parts of the code that do not have full exception handling. Note that improper exception handling can lead to unknowingly leaking potentially valuable information.
![]() Figure 5.1: Generating a new child for generation of unit tests ![]() Figure 5.2: Selecting the default test generation options ![]() Figure 5.3: Running the user-defined unit test generation procedure ![]() Figure 5.4: The WebGoat.jtest project ![]() Figure 5.5: Running the generated test ![]() Figure 5.6: The generated test results |
|
JTest does a whole lot more than we discuss here. JTest can perform more thorough analyses beyond security. Below are a few resources related to JTest. |
|
To install the Tomcat runtime, follow these steps:
![]() Figure 7.1: Viewing the installed servers ![]() Figure 7.2: Creating a new server |