Deploy Invicti Shark for Java - AWS Elastic Beanstalk (Tomcat + WAR File)
This document shows you how to run a Java application in AWS Elastic Beanstalk and then use Invicti Shark to run an interactive application security testing (IAST) scan for that application.
The following installation instructions are for the newer version of the Java IAST sensor. If you are running the older, aspectjweaver-based Java sensor, you need to remove the old sensor and any reference to aspectjweaver.jar from the JVM Options before proceeding with installing the newer version of the Java sensor.
Prerequisites
- Install Java.
- Install Eclipse IDE for Enterprise Java and Web Developers.
- Install Eclipse Extensions from "Web, XML, Java EE and OSGI Enterprise Development":
- Eclipse Java EE Developer Tools
- Eclipse Java Web Developer Tools
- Eclipse Web Developer Tools
- JST Server Adapters Extensions (Apache Tomcat)
Step 1: Prepare an example application using Eclipse IDE
- Go to File > New > Project.
- In the New Project wizard, search for and choose the Dynamic Web Project option, then click Next.
- Set the Project name field to axexample-java.
- Set the Target runtime field to Apache Tomcat v8.5.
- Set the Dynamic web module version field to 3.1.
- Set the Configuration field to Default Configuration for Apache Tomcat v8.5.
- Click Next.

- In the Java window, leave the default settings and click Next.
- In the Web Module window, enable the Generate web.xml option and click Finish.

- In the Open Associated Perspective? dialog, click No.
- Expand the
axexample-javaproject. - Right-click the
srcfolder. - Choose New > Other.
- Highlight the Servlet option.
- Click Next.
- Set the Java package field to
com.mytest.axexample. - Set the Class name field to
axExampleJavaServlet. - Click Finish.

- Edit the contents of the
axExampleJavaServlet.javafile to read as follows:
package com.mytest.axexamplejava;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class HelloWorldServlet
*/
@WebServlet("/axExampleJavaServlet")
public class axExampleJavaServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public axExampleJavaServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.print("<html><body><h1>Test JAVA Site Example for AWS Elastic Beanstalk</h1><br>Welcome to the main page.<br></body></html>");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
- Expand the
axexample-javaproject, right-click theaxexample-java/src/main/webappfolder, and choose New > File. - Set the filename to
index.htmland click Finish. - Edit the contents of the
index.htmlfile to read as follows:
<head>
<title>Test JAVA Site Example for AWS Elastic Beanstalk</title>
</head>
<body>
<h1>Test JAVA Site Example for AWS Elastic Beanstalk</h1><br/><br/>
<a href="axExampleJavaServlet">Click here to invoke servlet</a>
</body>
</html>
- Make sure that the changes to both new files are saved.
- Right-click the
axexample-javaproject, click the Export option, search for the WAR file option, and choose it. - Click Next and choose a Destination for your exported WAR file.
- Ensure that the filename for your export file is
ROOT.war. - Click Finish.
Step 2: Prepare Invicti Shark for Java
The test application is deployed to the following URL: http://eb.acunetixexample.com - you need to change this to the hostname you use for your test deployment.
- Create a new target website for this URL, replacing
http://eb.acunetixexample.comwith the URL for your chosen hostname. For more information, refer to the How to add a website in Invicti Enterprise document. - Download Invicti Shark for Java from the Invicti UI and retain the
Shark (IAST and SCA).jarfile for the next step.
Step 3: Prepare a folder for your source code bundle
- Create a folder
C:\axexample-java - Create a folder
C:\axexample-java\.ebextensions - Copy your exported
ROOT.warfile intoC:\axexample-java - Copy your
Shark (IAST and SCA).jarfile intoC:\axexample-java\.ebextensions - Using a text editor, create a file
C:\axexample-java\.ebextensions\invictishark.config - Edit the contents of the
C:\axexample-java\.ebextensions\invictishark.configfile to read as follows:
commands:
01_create_shark_directory:
command: "mkdir -p /home/shark"
option_settings:
aws:elasticbeanstalk:container:tomcat:jvmoptions:
JVM Options: '-javaagent:/home/shark/Shark (IAST and SCA).jar -Dacusensor.debug.log=ON'
container_commands:
01_copy_shark:
command: "cp .ebextensions/Shark (IAST and SCA).jar /home/shark/Shark (IAST and SCA).jar"
02_change_shark_dir_permissions:
command: "sudo chown -R root:root /home/shark"
The parameter -Dacusensor.debug.log=ON is optional, and should ONLY be used for troubleshooting purposes. If this parameter is retained, this outputs Invicti Shark logging as additional lines in the Tomcat logs starting with [Shark-debug].
- Use Windows Explorer to navigate to
C:\axexample-java; press CTRL+A to select both.ebextensionsandROOT.war. - Right-click the selected items and click Send to > Compressed (zipped) folder.
- Rename your zip file to
axexample-java.zipand retain your zip file for the deployment steps.
Step 4: Deploy the web application to AWS Elastic Beanstalk
- From your AWS Dashboard, navigate to Elastic Beanstalk > Environments.
- Choose Create a new environment.

- Set your environment tier to Web server environment, then click Select.
- Set the Application name field to the name of your web application. In this example the name is
axexample-java. - Set the Platform drop-down to Tomcat.

- Enable the Upload your code option and click Choose file.

- Choose your
axexample.zipsource code bundle for upload and click Create environment. AWS Elastic Beanstalk creates your environment. This can take a few minutes. - When the process is complete, you're sent to your environment's dashboard.

- Take note of your environment's new URL which was created automatically by AWS Elastic Beanstalk:
- You need this to create a CNAME to point to this URL.
- In this example, create a CNAME for
eb.acunetixexample.comto point toaxexamplejava-env.eba-y3m5stqv.us-east-1.elasticbeanstalk.com. Here is an example using the Namecheap cPanel interface.

- Once the CNAME record has been added (giving time for DNS records to propagate), you can see the web application you have created by browsing to your URL (in this example
http://eb.acunetixexample.com).
Step 5: Test and scan your web application
- Point your browser to your web application—in this example,
http://eb.acunetixexample.comto confirm it's running as intended. - Run a scan on your URL. The scan summary confirms that Invicti Shark was detected and used for the scan.
Need help?
Invicti Support team is ready to provide you with technical help. Go to Help Center