Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat stack report #714

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions rasp/jvm/JVMProbe/src/main/java/com/security/smith/SmithProbe.java
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ public void start() {
smithproxyTimer.schedule(
smithproxyTimerTask,
0,
TimeUnit.MINUTES.toMillis(1)
TimeUnit.MINUTES.toMillis(10)
);
smithProxy.setClient(client);
smithProxy.setDisruptor(disruptor);
Expand Down Expand Up @@ -737,6 +737,22 @@ public void onEvent(Trace trace, long sequence, boolean endOfBatch) {
client.write(Operate.TRACE, jsonElement);
}

public StackTraceElement[] formatCurrentStackTrace() {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
if (stackTrace == null) {
return new StackTraceElement[0];
}
int startIndex = 0;
for (int i = 0; i < stackTrace.length; i++) {
StackTraceElement element = stackTrace[i];
if (element.getClassName().startsWith("com.security.smithloader.SmithAgent")) {
startIndex = i;
break;
}
}
return Arrays.copyOfRange(stackTrace, startIndex + 1, stackTrace.length);
}

public void printClassfilter(ClassFilter data) {
SmithLogger.logger.info("------------------------------------------------------------------------");
SmithLogger.logger.info("className:" + data.getClassName());
Expand Down Expand Up @@ -833,7 +849,7 @@ private void checkClassFilter(ClassLoader loader, String className, byte[] class

classFilter.setRuleId(rule_id);
classFilter.setTransId();
classFilter.setStackTrace(Thread.currentThread().getStackTrace());
classFilter.setStackTrace(formatCurrentStackTrace());

Gson gson = new GsonBuilder()
.registerTypeAdapter(ClassFilter.class, new ClassFilterSerializer())
Expand Down Expand Up @@ -1219,7 +1235,7 @@ public void onScanAllClass() {
}
classFilter.setTransId();
classFilter.setRuleId(rule_id);
classFilter.setStackTrace(Thread.currentThread().getStackTrace());
classFilter.setStackTrace(formatCurrentStackTrace());

Gson gson = new GsonBuilder()
.registerTypeAdapter(ClassFilter.class, new ClassFilterSerializer())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public void trace(int classID, int methodID, Object[] args, Object ret, boolean
trace.setBlocked(blocked);
trace.setRet(ret);
trace.setArgs(args);
trace.setStackTrace(Thread.currentThread().getStackTrace());
trace.setStackTrace(SmithProbeObj.formatCurrentStackTrace());
trace.setTypes(SmithProbeObj.getFuncTypes(classID, methodID));

ringBuffer.publish(sequence);
Expand Down Expand Up @@ -290,7 +290,7 @@ public void sendMetadataClass(Class<?> cla, int classID, int methodID) {
classFilter.setClassId(classID);
classFilter.setMethodId(methodID);
classFilter.setTypes(SmithProbeObj.getFuncTypes(classID, methodID));
classFilter.setStackTrace(Thread.currentThread().getStackTrace());
classFilter.setStackTrace(SmithProbeObj.formatCurrentStackTrace());
if (client != null) {
Gson gson = new GsonBuilder()
.registerTypeAdapter(ClassFilter.class, new ClassFilterSerializer())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ private String[] convertStackTrace(StackTraceElement[] stackTrace) {
return ret;

try {
StackTraceElement[] elements = Arrays.copyOfRange(stackTrace, 2, stackTrace.length);
String[] result = new String[elements.length];
String[] result = new String[stackTrace.length];

for (int i = 0; i < elements.length; i++) {
result[i] = elements[i].toString();
for (int i = 0; i < stackTrace.length; i++) {
result[i] = stackTrace[i].toString();
}

return result;
Expand Down
Loading