Scanning an Application in AWS Elastic Beanstalk (Tomcat + WAR file)

The following article shows you how you can run a Java application in AWS Elastic Beanstalk and then use AcuSensor to run an interactive application security testing (IAST) scan for that application.

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 the menu item File → New → Project

  • In the New Project wizard, search for and select the Dynamic Web Project option and click on the Next button

  • 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 on the Next button

  • In the Java window, leave default settings and click on the Next button

  • In the Web Module window, enable the Generate web.xml option and click the Finish button

  • In the Open Associated Perspective? dialog, click on the No button
  • Expand the axexample-java project
  • Right-click on the src folder
  • Select the New → Other option

  • Highlight the Servlet option
  • Click on the Next > button

  • Set the Java package field to com.mytest.axexample
  • Set the Class name field to axExampleJavaServlet
  • Click on the Finish button
  • Edit the contents of the axExampleJavaServlet.java file 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-java project, right click on the axexample-java/src/main/webapp folder, and select the New → File option

  • Set the filename to index.html and click on the Finish button
  • Edit the contents of the index.html file 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 on the axexample-java project, click on the Export… option, search for the WAR file option, and select it

  • Click on the Next > button and select a Destination for your exported WAR file

  • Ensure that the filename for your export file is ROOT.war
  • Click on the Finish button

Step 2: Prepare AcuSensor for Java

We will deploy the test application to the following URL: http://eb.acunetixexample.com - you will need to change this to the hostname you will use for your test deployment

  • Create a new target for the above URL, replacing http://eb.acunetixexample.com with the URL for your chosen hostname
  • Download AcuSensor for Java from the Acunetix UI and retain the AcuSensor.jar file 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.war file into C:\axexample-java
  • Copy your AcuSensor.jar file into C:\axexample-java\.ebextensions
  • Using a text editor, create a file C:\axexample-java\.ebextensions\acusensor.config
  • Edit the contents of the C:\axexample-java\.ebextensions\acusensor.config file to read as follows:

commands:

  01_create_acusensor_directory:

    command: "mkdir -p /home/acusensor"

  02_get_aspectjweaver:

    command: "wget https://repo1.maven.org/maven2/org/aspectj/aspectjweaver/1.9.7/aspectjweaver-1.9.7.jar -O /home/acusensor/aspectjweaver.jar"

option_settings:

  aws:elasticbeanstalk:container:tomcat:jvmoptions:

    JVM Options: '-javaagent:/usr/share/tomcat/lib/aspectjweaver.jar -Dacusensor.debug.log=ON'

container_commands:

  01_copy_acusensor:

    command: "cp .ebextensions/AcuSensor.jar /home/acusensor/AcuSensor.jar"

  02_change_acusensor_dir_permissions:

    command: "sudo chown -R root:root /home/acusensor"

  03_link_aspectjweaver_library:

    command: "ln -s /home/acusensor/aspectjweaver.jar /usr/share/tomcat/lib/aspectjweaver.jar"

  04_link_acusensor_library:

    command: "ln -s /home/acusensor/AcuSensor.jar /usr/share/tomcat/lib/AcuSensor.jar"

Note: The parameter "-Dacusensor.debug.log=ON" is optional, and should ONLY be used for troubleshooting purposes. If this parameter is retained, this will output AcuSensor logging as additional lines in the Tomcat logs starting with "[Acunetix-debug]".

  • Use Windows Explorer to navigate to C:\axexample-java; click CTRL+A to select both .ebextensions and ROOT.war
  • Right-click on the selected items and click the Send to -> Compressed (zipped) folder menu option:

  • Rename your zip file to axexample-java.zip and retain your zip file for deployment steps below

Deploy your web application to AWS Elastic Beanstalk

  • From your AWS Dashboard, navigate to Elastic Beanstalk -> Environments
  • Click the Create a new environment button

  • Set your environment tier to Web server environment

  • Click the Select button
  • In the Elastic Beanstalk -> Create environment page:
  • Set the Application name field to the name for your web application; in this example you will use the name axexample-java

  • Set the Platform dropdown to Tomcat

  • Enable the Upload your code option and click the Choose file button

  • Select your axexample.zip source code bundle for upload and click the Create environment button
  • AWS Elastic Beanstalk will now create your environment; this can take a few minutes
  • When the process is complete you will be sent to your environment's dashboard

  • Take note of your environment's new URL which was created automatically by AWS Elastic Beanstalk:
  • you will need this to create a CNAME to point to this URL
  • in this example, we would create a CNAME for eb.acunetixexample.com to point to axexamplejava-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):

Test and scan your web application

Point your browser to your web application - in this example http://eb.acunetixexample.com - to confirm it is running as intended; you will get the following:

Finally, run a scan on your target; the Activity panel will confirm that AcuSensor was detected and used for the scan.

 

« Back to the Acunetix Support Page