之前偶們有就RASP技術攻防基礎作過簡單介紹,穿越捷徑:淺談RASP技術攻防之基礎篇
今兒接上回,說一說環境配置的事兒,廢話不多說,直接進入正題
PS:程式碼已上傳至github,地址:https://github.com/iiiusky/java_rasp_example
初始化專案
首先我們在IDEA中新建一個maven專案

取名為JavawebAgent


然後當前的目錄結構如下:

刪除src目錄,然後右鍵新建Module

依然選擇Maven專案

然後在ArtifactId處填入agent

然後確定即可

然後再次重複一遍上面的新建Module的操作,將第二小步中的ArtifactId改為test,第三小步中的Module Name 改為test-struts2,如下圖所示


這時候的目錄結構如下

其中agent目錄為我們要實現agent的主要程式碼區域,test-struts2為測試web程式碼區域。(注:test-struts2不是必選的)
test-struts2模組基礎配置
test-struts2部分的程式碼這邊就不進行復述了,大家可以去本專案的地址中直接下載test-struts2內容。
agent模組基本配置
≡≡ pom.xml包配置
agent這個pom包配置的話有坑,這個以後在說,先看pom.xml內容吧。
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-all</artifactId>
<version>5.1</version>
</dependency>
</dependencies>
<build>
<finalName>agent</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<archive>
<manifestFile>src/main/resources/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>commons-io:commons-io:jar:*</include>
<include>org.ow2.asm:asm-all:jar:*</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
將上述內容複製到agent模組下的pom.xml中
12
≡≡ 建立MAINFEST.NF檔案
在resources目錄下建立MAINFEST.NF檔案,檔案內容如下
Manifest-Version: 1.0
Can-Retransform-Classes: true
Can-Redefine-Classes: true
Can-Set-Native-Method-Prefix: true
≡≡ maven自動打包配置
在idea中右上部分找到Add Configurations , 然後點選此按鈕

在彈出的視窗中點左上角的+,選擇maven

然後點下圖①的位置選擇工作目錄,在②的位置選擇agent,在③的位置填入clean install

完成以後如下圖所示,然後點選OK儲存即可

這時候右上角已經可以看到我們剛剛配置的maven自動打包功能了,agent每改一處都需要重新build,不然無法生效。

≡≡ 建立Agent主要實現程式碼包
在agent包下面的java資料夾下右鍵選擇新建package,然後填入你的包名,我這邊的包名為
cn.org.javaweb.agent

到目前為止,我們已經將基本環境以及目錄結構配置完成了~
下篇文章我們接著說程式碼實現部分的內容~