目錄

安裝 AcuSensor 代理於 Java – AWS Elastic Beanstalk & WAR 檔案

本文將介紹如何在 AWS Elastic Beanstalk 上運行 Java 應用程序,然後使用 AcuSensor 運行交互式應用程序安全測試(IAST)掃描

前提條件

  • 安裝JAVA
  • 安裝Eclipse IDE for Enterprise JAVA and Web Developers
  • 從 “Web, XML, Java EE and OSGI Enterprise Development” 安裝Eclipse擴展:
    • Eclipse Java EE Developer Tools
    • Eclipse Java Web Developer Tools
    • Eclipse Web Developer Tools
    • JST Server Adapters Extensions (Apache Tomcat)

步驟1:使用 Eclipse IDE 準備範例應用程序

  • 從菜單點選到“檔案”→“新建”→“專案”
    New Project
  • 在新專案精靈中,搜索並選擇動態Web專案選項,然後單擊“下一步”按鈕。
    Dynamic Web Project
  • 在“項目名稱”欄中設置為axexample-java。
  • 在“目標運行時”欄中設置為Apache Tomcat v8.5。
  • 在“動態Web模塊版本”欄中設置為3.1。
  • 在“配置”欄中設置為Apache Tomcat v8.5的默認配置。
  • 單擊“下一步”按鈕。
    leave default settings and click on the Next button
  • 在Java視窗中,保留默認設置,然後單擊“下一步”按鈕。
    enable the Generate web.xml option and click the Finish button
  • 在Web模組窗口中,啟用“生成web.xml”選項,然後單擊“完成”按鈕。
    click on the No button
  • 在“打開關聯的透視圖”對話框中,單擊“否”按鈕。
  • 展開axexample-java項目。
  • 右鍵點擊src文件夾。
  • 選擇“新建”→“其他”。
    Highlight the Servlet option
  • Highlight “Servlet”選項。
  • 點擊“下一步>”按鈕。
    Set the Java package field to com.mytest.axexample
  • 將Java包字段設置為com.mytest.axexample。
  • 在“類名”欄中設置為axExampleJavaServlet。
  • 點擊“完成”按鈕。
  • 將axExampleJavaServlet.java文件的內容編輯為以下內容:

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);
        }
}

  • 展開 axexample-java 項目,右鍵單擊 axexample-java/src/main/webapp 文件夾,然後選擇“新建”→“檔案”選項。
    Set the filename to index.html and click on the Finish button
  • 在“檔案名稱”欄中設置為 index.html,然後點擊“完成”按鈕。
  • 將 index.html 文件的內容編輯

<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>

  • 確認兩個新檔案的變更已經儲存
  • 右鍵點擊 axexample-java 專案,選擇「匯出…」選項,搜尋 WAR 檔案選項,並選取它。
    Click on the Next_button and select a Destination for your exported WAR file
  • 按下「下一步 >」按鈕,並選擇您的匯出 WAR 檔案的目的地。
    Ensure that the filename for your export file is ROOT.war
  • 確保匯出檔案的檔名為 ROOT.war,
  • 按下「完成」按鈕。

步驟 2:為 Java 準備 AcuSensor

我們將部署測試應用程序到以下 URL:http://eb.acunetixexample.com – 您需要將其更改為您的測試部署所使用的主機名

  • 為上述 URL 創建一個新的目標,將 http://eb.acunetixexample.com 替換為您選擇的主機名的 URL
  • 從 Acunetix UI 下載 Java AcuSensor 並保留 AcuSensor.jar 文件以供下一步使用

步驟 3:為您的源代碼包準備一個文件夾

<p>此內容須<a class="login" title="登入" href="//acunetix.twnfi.net/login?redirect_to=">登入</a>才能觀看</p>

部署您的 Web 應用程式至 AWS Elastic Beanstalk

  • 從您的 AWS 儀表板,導航至 Elastic Beanstalk -> 環境
  • 點擊「建立新環境」按鈕
    Create a new environment
  • 將您的環境層級設定為 Web 伺服器環境
    Set your environment tier to Web server environment
  • 點擊「選擇」按鈕,在 Elastic Beanstalk -> 建立環境頁面中:
    • 將應用程式名稱設定為您的 Web 應用程式名稱;在本例中,假設您命名為 axexample-java
      you will use the name axexample-java
    • 設定平台下拉式選單為Tomcat。
      Set the Platform dropdown to Tomcat
    • 啟用「Upload your code」選項並點擊「Choose file」按鈕。
      Enable the Upload your code
    • 選擇您的axexample.zip源代碼捆包進行上傳,然後點擊「Create environment」按鈕。
  • AWS Elastic Beanstalk已經開始創建您的環境,這可能需要幾分鐘的時間。
  • 當程序完成時,您將被送到環境的儀表板。
    you will be sent to your environment's dashboard
  • 請注意您的環境的新URL,此URL是由AWS Elastic Beanstalk自動創建的:
    • 當 AWS Elastic Beanstalk 創建您的環境時,可能需要幾分鐘的時間。完成後,您將被送到環境儀表板。
    • 請注意,AWS Elastic Beanstalk 自動創建了您的環境的新 URL,您需要使用此 URL 創建 CNAME。在這個範例中,我們需要建立一個 CNAME,將 eb.acunetixexample.com 指向 axexamplejava-env.eba-y3m5stqv.us-east-1.elasticbeanstalk.com。以下是使用 Namecheap cPanel 介面的示例:
      CNAME for eb.acunetixexample.com to point to axexamplejava-env.eba-y3m5stqv.us-east-1.elasticbeanstalk.com
    • 添加 CNAME 記錄後(DNS 記錄需要一些時間來傳播),您可以通過瀏覽您的 URL(在這個範例中是 http://eb.acunetixexample.com)來查看您創建的 Web 應用程式。
      you can see the web application you have created by browsing to your URL

測試和掃描你的網頁應用程式

在瀏覽器中輸入您的網頁應用程式網址,例如 http://eb.acunetixexample.com,以確認它按預期運行;您將看到以下畫面:
Point your browser to your web application
最後,在目標上運行掃描;活動面板將確認AcuSensor已被偵測並用於掃描。
run a scan on your target