目錄

安裝 AcuSensor 代理於 Java – Windows (JBOSS 7.4 Standalone + WAR File)

以下文章會告訴您如何在 JBOSS 中執行 Java 應用程式,然後使用 AcuSensor 執行互動式應用程式安全測試 (IAST) 掃描

🔍 環境注意事項
  • 本文檔在 Windows 10 系統下,使用安裝在 C:\Program Files\Java\jdk1.8.0_241 資料夾中的 Java SE Development Kit 8 Update 241 (64-bit) 進行測試。您還需要將 JAVA_HOME 環境變數設置為相應的資料夾。 set your JAVA_HOME

前置需求

  • 安裝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準備範例應用程式

  • 前往選單點選 File NewProject Dynamic Web Project
  • New Project 精靈中,搜尋並選擇「Dynamic Web Project」,然後點擊「Next」按鈕 Configuration Dynamic Web Project
  • 輸入「axexample-java」為專案名稱(Project name)
  • 設定運行環境(Target runtime)為 Apache Tomcat v8.5
  • 動態網頁模組版本(Dynamic web module version)設為 3.1
  • 將設定(Configuration)設為 Apache Tomcat v8.5 的預設設定,接著按下「Next leave default settings and click on the Next button
  • Java 視窗中,保持預設設定,並點擊「Next」按鈕。 enable the Generate web.xml option
  • 在「Web Module」視窗中,啟用「Generate web.xml」選項,然後點擊「Finish」按鈕。 click on the No button
  • 在「Open Associated Perspective?」視窗中,點擊 No 按鈕。
  • 展開 axexample-java 專案
  • src 資料夾上按滑鼠右鍵
  • 選擇「NewOther」選項。 Highlight the Servlet option
  • 選取 Servlet 選項
  • 接著按下「Next >」按鈕 Configuration Servlet option
  • Java package 欄位設置為 com.mytest.axexample
  • Class name 欄位設置為 axExampleJavaServlet
  • 點擊 Finish 按鈕
  • 請將 axExampleJavaServlet.java 的內容修改為以下:
				
					package com.mytest.axexample;

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><script>class RocketElementorAnimation{constructor(){this.deviceMode=document.createElement("span"),this.deviceMode.id="elementor-device-mode",this.deviceMode.setAttribute("class","elementor-screen-only"),document.body.appendChild(this.deviceMode)}_detectAnimations(){let t=getComputedStyle(this.deviceMode,":after").content.replace(/"/g,"");this.animationSettingKeys=this._listAnimationSettingsKeys(t),document.querySelectorAll(".elementor-invisible[data-settings]").forEach(t=>{const e=t.getBoundingClientRect();if(e.bottom>=0&&e.top<=window.innerHeight)try{this._animateElement(t)}catch(t){}})}_animateElement(t){const e=JSON.parse(t.dataset.settings),i=e._animation_delay||e.animation_delay||0,n=e[this.animationSettingKeys.find(t=>e[t])];if("none"===n)return void t.classList.remove("elementor-invisible");t.classList.remove(n),this.currentAnimation&&t.classList.remove(this.currentAnimation),this.currentAnimation=n;let s=setTimeout(()=>{t.classList.remove("elementor-invisible"),t.classList.add("animated",n),this._removeAnimationSettings(t,e)},i);window.addEventListener("rocket-startLoading",function(){clearTimeout(s)})}_listAnimationSettingsKeys(t="mobile"){const e=[""];switch(t){case"mobile":e.unshift("_mobile");case"tablet":e.unshift("_tablet");case"desktop":e.unshift("_desktop")}const i=[];return["animation","_animation"].forEach(t=>{e.forEach(e=>{i.push(t+e)})}),i}_removeAnimationSettings(t,e){this._listAnimationSettingsKeys().forEach(t=>delete e[t]),t.dataset.settings=JSON.stringify(e)}static run(){const t=new RocketElementorAnimation;requestAnimationFrame(t._detectAnimations.bind(t))}}document.addEventListener("DOMContentLoaded",RocketElementorAnimation.run);</script></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 資料夾,選擇 [New] → [File] 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>
				
			
  • 確保對兩個新文件的更改均已保存 search for the WAR file option
  • 對 axexample-java 項目點擊右鍵,點選“匯出…”,搜索 WAR 文件選項並選擇它 Ensure that the filename for your export file is axexample-java.war
  • 單擊“下一步 >”按鈕,為匯出的 WAR 文件選擇一個目標位置
  • 確保匯出文件的檔案名為 axexample-java.war
  • 點選“完成”按鈕

步驟 2:為 Java 準備 AcuSensor

我們將把測試應用程序部署到以下 URL:http://127.0.0.1:8080/axexample-java/ (在生產環境中,您需要將其更改為部署時使用的主機名稱)

  • 為您的 URL 創建一個新目標
  • 從 Acunetix UI 下載 Java 版本的 AcuSensor,並保留 AcuSensor.jar 文件以進行下一步操作

步驟 3:為 AspectJWeaver 組件準備資料夾

步驟 4:部署 AcuSensor 及所需組件

  • 建立資料夾 %JBOSS_HOME%\modules\system\layers\base\com\invicti
  • 建立資料夾 %JBOSS_HOME%\modules\system\layers\base\com\invicti\sensor
  • 建立資料夾 %JBOSS_HOME%\modules\system\layers\base\com\invicti\sensor\main
  • 將您的 AcuSensor.jar 檔案複製到 %JBOSS_HOME%\modules\system\layers\base\com\invicti\sensor\main
  • 使用文字編輯器,建立檔案 %JBOSS_HOME%\modules\system\layers\base\com\invicti\sensor\main\module.xml
  • 編輯 %JBOSS_HOME%\modules\system\layers\base\com\invicti\sensor\main\module.xml 文件的內容,使其讀取如下:
				
					<?xml version="1.0" encoding="UTF-8"?>
<module name="com.invicti.sensor" xmlns="urn:jboss:module:1.9">
  <resources>
    <resource-root path="acusensor.jar"/>
    <resource-root path="aspectjrt-1.9.7.jar"/>
  </resources>
  <dependencies>
    <module name="javax.api"/>
    <module name="javax.servlet.api"/>
    <module name="java.logging"/>
    <module name="org.jboss.modules"/>
  </dependencies>
</module>
				
			
  • https://repo1.maven.org/maven2/org/aspectj/aspectjrt/1.9.7/aspectjrt-1.9.7.jar
  • 下載 AspectJRT 將 aspectjrt-1.9.7.jar 文件複製到 %JBOSS_HOME%\modules\system\layers\base\com\invicti\sensor\main
  • 準備一個自定義配置以實現 AcuSensor 集成:
    C:\Users\default.user> cd C:\jboss\standalone\configuration
    C:\jboss\standalone\configuration> copy standalone.xml standalone-invicti.xml
            1 file(s) copied.
    C:\jboss\standalone\configuration>
  • 使用文字編輯器,編輯 %JBOSS_HOME%\standalone\configuration\standalone-invicti.xml 文件,找到 <subsystem xmlns=”urn:jboss:domain:ee:6.0″> 這一行下方立即添加以下的突出顯示:
				
					...
...
        </subsystem>
        <subsystem xmlns="urn:jboss:domain:ee:6.0">
            <global-modules>
                <module name="com.invicti.sensor" slot="main"/>
            </global-modules>
            <spec-descriptor-property-replacement>false</spec-descriptor-property-replacement>
            <concurrent>
...
...
				
			
  • 編輯 %JBOSS_HOME%\bin\standalone.conf.bat 檔案,並在文件底部添加以下內容
    rem *** Acusensor settings
    set "JAVA_OPTS=%JAVA_OPTS% -Dacusensor.debug.log=ON"
    set "MODULE_OPTS=-javaagent:C:\aspectjweaver\aspectjweaver-1.9.7.jar"

步驟 5:部署您的應用程式

  • 將您的 axexample-java.war 文件複製到 %JBOSS_HOME%\standalone\deployments 文件夾中

步驟 6:啟動您的 JBOSS 伺服器

  • 從命令行中,瀏覽到您的 %JBOSS_HOME%\bin 文件夾,並啟動 JBOSS 指定之前建立的自定義配置文件:
    C:\Users\default.user> cd C:\jboss\bin
    C:\jboss\bin>standalone --server-config=standalone-invicti.xml
    Calling "C:\jboss\bin\standalone.conf.bat"
    Setting JAVA property to "C:\Program Files\Java\jdk1.8.0_241\\bin\java"
    ===============================================================================
      JBoss Bootstrap Environment
      JBOSS_HOME: "C:\jboss"
      JAVA: "C:\Program Files\Java\jdk1.8.0_241\\bin\java"
      JAVA_OPTS: "-javaagent:"C:\jboss\jboss-modules.jar" -Dprogram.name=standalone.bat -Xms1G -Xmx1G -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Dacusensor.debug.log=ON -verbose:gc -Xloggc:"C:\jboss\standalone\log\gc.log" -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=3M -XX:-TraceClassUnloading "
    ===============================================================================
    ...

測試並掃描您的 Web 應用程式

將您的瀏覽器指向 Web 應用程序以確認其按預期運行;您將獲得以下結果: you will get the following 最後,在您的目標上運行掃描;活動面板將確認檢測到 AcuSensor 並在掃描中使用它。 the Activity panel will confirm that AcuSensor was detected