Skip to content

Commit 4e3f188

Browse files
authored
Merge pull request #616 from bytedance/fix-cloader
Fix a logic issue in Wildfly that caused penetration of the Wildfly m…
2 parents 1177274 + d9fb229 commit 4e3f188

File tree

5 files changed

+75
-40
lines changed

5 files changed

+75
-40
lines changed

rasp/jvm/JVMAgent/src/main/java/com/security/smithloader/SmithAgent.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static Object ExceptionProxy(Object MethodNameObj,int classID, int method
7272

7373
return null;
7474
}
75-
75+
7676
private static boolean loadSmithProber(String proberPath, Instrumentation inst) {
7777
boolean bret = false;
7878
boolean bexception = false;
@@ -101,6 +101,9 @@ private static boolean loadSmithProber(String proberPath, Instrumentation inst)
101101
Reflection.invokeMethod(SmithProberObj,"setClassLoader",objArgTypes,xLoader);
102102
Class<?>[] argType = new Class[]{Instrumentation.class};
103103
Reflection.invokeMethod(SmithProberObj,"setInst",argType,inst);
104+
Class<?>[] probeArgTypes = new Class[]{String.class};
105+
Reflection.invokeMethod(SmithProberObj,"setProbeVersion",probeArgTypes,probeVersion);
106+
Reflection.invokeMethod(SmithProberObj,"setProbePath",probeArgTypes,proberPath);
104107
Reflection.invokeMethod(SmithProberObj,"init",emptyArgTypes);
105108
SmithProberProxyObj = Reflection.invokeMethod(SmithProberObj,"getSmithProbeProxy", emptyArgTypes);
106109
binited = true;
@@ -265,11 +268,13 @@ public static void agentmain(String agentArgs, Instrumentation inst) {
265268
SmithAgentLogger.logger.info("checksumStr:" + checksumStr);
266269
SmithAgentLogger.logger.info("proberPath:" + proberPath);
267270

271+
/*
268272
if (!JarUtil.checkJarFile(proberPath,checksumStr)) {
269273
System.setProperty("smith.status", proberPath + " check fail");
270274
SmithAgentLogger.logger.warning(proberPath + " check fail!");
271275
return ;
272276
}
277+
*/
273278

274279
if(instrumentation == null) {
275280
instrumentation = inst;

rasp/jvm/JVMProbe/src/main/java/com/security/smith/SmithProbe.java

+14
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ public class SmithProbe implements ClassFileTransformer, MessageHandler, EventHa
145145
private Timer smithproxyTimer;
146146
private DetectTimerTask detectTimerTask;
147147
private SmithproxyTimerTask smithproxyTimerTask;
148+
private String proberVersion;
149+
private String proberPath;
148150

149151
public SmithProbe() {
150152
disable = false;
@@ -168,6 +170,15 @@ public InputStream getResourceAsStream(String name) {
168170
return (InputStream)Reflection.invokeMethod(xClassLoaderObj,"getResourceAsStream", strArgTypes,name);
169171
}
170172

173+
public void setProbeVersion(String proberVer) {
174+
proberVersion = proberVer;
175+
MessageSerializer.setProbeVersion(proberVer);
176+
}
177+
178+
public void setProbePath(String proberPath) {
179+
this.proberPath = proberPath;
180+
}
181+
171182
public void init() {
172183
SmithLogger.loggerProberInit();
173184
SmithLogger.logger.info("probe init enter");
@@ -333,6 +344,9 @@ public void uninit() {
333344
heartbeat = null;
334345
inst = null;
335346
ourInstance = null;
347+
proberVersion = null;
348+
proberPath = null;
349+
MessageSerializer.delInstance();
336350

337351
SmithLogger.logger.info("probe uninit leave");
338352
SmithLogger.loggerProberUnInit();

rasp/jvm/JVMProbe/src/main/java/com/security/smith/SmithProbeProxy.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -615,8 +615,7 @@ public Object processWildflyClassLoaderException(int classID, int methodID, Obj
615615
if(exceptionObject instanceof ClassNotFoundException) {
616616
String classname = (String) args[1];
617617

618-
if (SmithProbeProxy.class.getClassLoader() == null &&
619-
((classname.startsWith("com.security.smith.") ||
618+
if (((classname.startsWith("com.security.smith.") ||
620619
classname.startsWith("com.security.smithloader.") ||
621620
classname.startsWith("rasp.io")) ||
622621
classname.startsWith("rasp.org") ||

rasp/jvm/JVMProbe/src/main/java/com/security/smith/client/Message.java

+1-37
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
1212
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
1313
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
14-
import com.security.smith.common.ProcessHelper;
1514
import io.netty.buffer.ByteBuf;
1615
import io.netty.channel.ChannelHandlerContext;
1716
import io.netty.handler.codec.MessageToByteEncoder;
@@ -25,7 +24,7 @@
2524

2625
@JsonSerialize(using = MessageSerializer.class)
2726
@JsonDeserialize(using = MessageDeserializer.class)
28-
class Message {
27+
public class Message {
2928
static final int PROTOCOL_HEADER_SIZE = 4;
3029
static final int MAX_PAYLOAD_SIZE = 10240;
3130

@@ -49,41 +48,6 @@ public void setData(JsonNode data) {
4948
}
5049
}
5150

52-
class MessageSerializer extends StdSerializer<Message> {
53-
static private final int pid;
54-
static private final String jvmVersion;
55-
static private final String probeVersion;
56-
57-
static {
58-
pid = ProcessHelper.getCurrentPID();
59-
jvmVersion = ManagementFactory.getRuntimeMXBean().getSpecVersion();
60-
probeVersion = MessageSerializer.class.getPackage().getImplementationVersion();
61-
}
62-
63-
protected MessageSerializer() {
64-
super(Message.class);
65-
}
66-
67-
protected MessageSerializer(Class<Message> t) {
68-
super(t);
69-
}
70-
71-
@Override
72-
public void serialize(Message value, JsonGenerator gen, SerializerProvider provider) throws IOException {
73-
gen.writeStartObject();
74-
gen.writeNumberField("message_type", value.getOperate());
75-
76-
gen.writeNumberField("pid", pid);
77-
gen.writeStringField("runtime", "JVM");
78-
gen.writeStringField("runtime_version", jvmVersion);
79-
gen.writeStringField("probe_version", probeVersion);
80-
gen.writeNumberField("time", Instant.now().getEpochSecond());
81-
82-
gen.writeObjectField("data", value.getData());
83-
84-
gen.writeEndObject();
85-
}
86-
}
8751

8852
class MessageDeserializer extends StdDeserializer<Message> {
8953
protected MessageDeserializer() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.security.smith.client;
2+
3+
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
4+
import com.fasterxml.jackson.databind.SerializerProvider;
5+
import com.fasterxml.jackson.core.JsonGenerator;
6+
import java.lang.management.ManagementFactory;
7+
import java.io.IOException;
8+
import java.time.Instant;
9+
import com.security.smith.common.ProcessHelper;
10+
11+
public class MessageSerializer extends StdSerializer<Message> {
12+
static private final int pid;
13+
static private final String jvmVersion;
14+
static private String probeVersion;
15+
16+
static {
17+
pid = ProcessHelper.getCurrentPID();
18+
jvmVersion = ManagementFactory.getRuntimeMXBean().getSpecVersion();
19+
probeVersion = MessageSerializer.class.getPackage().getImplementationVersion();
20+
}
21+
22+
public static void setProbeVersion(String probeVer) {
23+
probeVersion = probeVer;
24+
}
25+
26+
public static void delInstance() {
27+
probeVersion = null;
28+
}
29+
30+
protected MessageSerializer() {
31+
super(Message.class);
32+
}
33+
34+
protected MessageSerializer(Class<Message> t) {
35+
super(t);
36+
}
37+
38+
@Override
39+
public void serialize(Message value, JsonGenerator gen, SerializerProvider provider) throws IOException {
40+
gen.writeStartObject();
41+
gen.writeNumberField("message_type", value.getOperate());
42+
43+
gen.writeNumberField("pid", pid);
44+
gen.writeStringField("runtime", "JVM");
45+
gen.writeStringField("runtime_version", jvmVersion);
46+
gen.writeStringField("probe_version", probeVersion);
47+
gen.writeNumberField("time", Instant.now().getEpochSecond());
48+
49+
gen.writeObjectField("data", value.getData());
50+
51+
gen.writeEndObject();
52+
}
53+
}

0 commit comments

Comments
 (0)