FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

:new:新增 Java Agent 环境 · fish123123/JavaSecurityLearning@759dd41 · GitHub

Repository navigation

Commit 759dd41

Browse files
committed
🆕新增 Java Agent 环境
1 parent 0ffd951 commit 759dd41

38 files changed

Lines changed: 893 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
!**/src/main/**/target/
4+
!**/src/test/**/target/
5+
6+
### IntelliJ IDEA ###
7+
.idea/modules.xml
8+
.idea/jarRepositories.xml
9+
.idea/compiler.xml
10+
.idea/libraries/
11+
*.iws
12+
*.iml
13+
*.ipr
14+
15+
### Eclipse ###
16+
.apt_generated
17+
.classpath
18+
.factorypath
19+
.project
20+
.settings
21+
.springBeans
22+
.sts4-cache
23+
24+
### NetBeans ###
25+
/nbproject/private/
26+
/nbbuild/
27+
/dist/
28+
/nbdist/
29+
/.nb-gradle/
30+
build/
31+
!**/src/main/**/build/
32+
!**/src/test/**/build/
33+
34+
### VS Code ###
35+
.vscode/
36+
37+
### Mac OS ###
38+
.DS_Store
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.example</groupId>
5+
<artifactId>Agentmain</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<name>Archetype - Agentmain</name>
8+
<dependencies>
9+
<dependency>
10+
<groupId>com.sun</groupId>
11+
<artifactId>tools</artifactId>
12+
<version>1.8.0</version>
13+
<scope>system</scope>
14+
<systemPath>D:\\SoftWares\\LanguageEnv\\Java\\8u321\\lib\\tools.jar</systemPath>
15+
</dependency>
16+
</dependencies>
17+
<url>http://maven.apache.org</url>
18+
<build>
19+
<plugins>
20+
<plugin>
21+
<groupId>org.apache.maven.plugins</groupId>
22+
<artifactId>maven-assembly-plugin</artifactId>
23+
<version>2.6</version>
24+
<configuration>
25+
<descriptorRefs>
26+
<descriptorRef>jar-with-dependencies</descriptorRef>
27+
</descriptorRefs>
28+
<archive>
29+
<manifestFile>
30+
src/main/resources/META-INF/MAINFEST.MF
31+
</manifestFile>
32+
</archive>
33+
</configuration>
34+
</plugin>
35+
<plugin>
36+
<groupId>org.apache.maven.plugins</groupId>
37+
<artifactId>maven-compiler-plugin</artifactId>
38+
<configuration>
39+
<source>6</source>
40+
<target>6</target>
41+
</configuration>
42+
</plugin>
43+
</plugins>
44+
</build>
45+
</project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.drunkbaby;
2+
3+
import com.sun.tools.attach.*;
4+
5+
import java.io.IOException;
6+
import java.util.List;
7+
8+
public class Inject_Agent {
9+
public static void main(String[] args) throws IOException, AttachNotSupportedException, AgentLoadException, AgentInitializationException {
10+
//调用VirtualMachine.list()获取正在运行的JVM列表
11+
List<VirtualMachineDescriptor> list = VirtualMachine.list();
12+
for(VirtualMachineDescriptor vmd : list){
13+
//遍历每一个正在运行的JVM,如果JVM名称为Sleep_Hello则连接该JVM并加载特定Agent
14+
if(vmd.displayName().equals("com.drunkbaby.Sleep_Hello")){
15+
16+
//连接指定JVM
17+
VirtualMachine virtualMachine = VirtualMachine.attach(vmd.id());
18+
//加载Agent
19+
virtualMachine.loadAgent("E:\\Coding\\Java\\Java-Agent-Memshell\\Agentmain\\target\\Agentmain-1.0-SNAPSHOT-jar-with-dependencies.jar");
20+
//断开JVM连接
21+
virtualMachine.detach();
22+
}
23+
24+
}
25+
}
26+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.drunkbaby;
2+
3+
import java.lang.instrument.Instrumentation;
4+
5+
import static java.lang.Thread.sleep;
6+
7+
public class Java_Agent_agentmain {
8+
public static void agentmain(String args, Instrumentation inst) throws InterruptedException {
9+
while (true){
10+
System.out.println("调用了agentmain-Agent!");
11+
sleep(3000);
12+
}
13+
}
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.drunkbaby;
2+
3+
import static java.lang.Thread.sleep;
4+
5+
public class Sleep_Hello {
6+
public static void main(String[] args) throws InterruptedException {
7+
while (true){
8+
System.out.println("Hello World!");
9+
sleep(5000);
10+
}
11+
}
12+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.drunkbaby;
2+
3+
import com.sun.tools.attach.VirtualMachine;
4+
import com.sun.tools.attach.VirtualMachineDescriptor;
5+
6+
import java.util.List;
7+
8+
import com.sun.tools.attach.VirtualMachine;
9+
import com.sun.tools.attach.VirtualMachineDescriptor;
10+
11+
import java.util.List;
12+
13+
public class get_PID {
14+
public static void main(String[] args) {
15+
16+
List<VirtualMachineDescriptor> list = VirtualMachine.list();
17+
for(VirtualMachineDescriptor vmd : list){
18+
19+
//遍历每一个正在运行的JVM,如果JVM名称为get_PID则返回其PID
20+
if(vmd.displayName().equals("get_PID"))
21+
System.out.println(vmd.id());
22+
}
23+
24+
}
25+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Manifest-Version: 1.0
2+
Agent-Class: com.drunkbaby.Java_Agent_agentmain
3+
Can-Redefine-Classes: true
4+
Can-Retransform-Classes: true
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>$org.example</groupId>
5+
<artifactId>$Agentmain</artifactId>
6+
<version>$1.0-SNAPSHOT</version>
7+
<dependencies>
8+
<dependency>
9+
<groupId>junit</groupId>
10+
<artifactId>junit</artifactId>
11+
<version>3.8.1</version>
12+
<scope>test</scope>
13+
</dependency>
14+
</dependencies>
15+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package $org.example;
2+
3+
/**
4+
* Hello world!
5+
*
6+
*/
7+
public class App
8+
{
9+
public static void main( String[] args )
10+
{
11+
System.out.println( "Hello World!" );
12+
}
13+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package $org.example;
2+
3+
import junit.framework.Test;
4+
import junit.framework.TestCase;
5+
import junit.framework.TestSuite;
6+
7+
/**
8+
* Unit test for simple App.
9+
*/
10+
public class AppTest
11+
extends TestCase
12+
{
13+
/**
14+
* Create the test case
15+
*
16+
* @param testName name of the test case
17+
*/
18+
public AppTest( String testName )
19+
{
20+
super( testName );
21+
}
22+
23+
/**
24+
* @return the suite of tests being tested
25+
*/
26+
public static Test suite()
27+
{
28+
return new TestSuite( AppTest.class );
29+
}
30+
31+
/**
32+
* Rigourous Test :-)
33+
*/
34+
public void testApp()
35+
{
36+
assertTrue( true );
37+
}
38+
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL