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

Enhance: Remove namespace in iast-core and iast-inject module #221

Merged
merged 2 commits into from
Jan 10, 2022
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
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
package cn.huoxian.iast.api;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;

/**
* @author dongzhiyong@huoxian.cn
*/
public class ResponseWrapper extends HttpServletResponseWrapper {
private ServletOutputStream outputStream;
private PrintWriter writer;
private WrapperOutputStreamCopier copier;

private ServletOutputStream outputStream = null;
private PrintWriter writer = null;
private WrapperOutputStreamCopier copier = null;

public static Object cloneResponse(Object response) {
if (response instanceof HttpServletResponse) {
return new ResponseWrapper((HttpServletResponse) response);
}
return response;
// if (response instanceof HttpServletResponse) {
// return new ResponseWrapper((HttpServletResponse) response);
// }
// return response;
}

public ResponseWrapper(HttpServletResponse response) {
Expand Down
4 changes: 0 additions & 4 deletions iast-agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@
<pattern>org.apache.commons</pattern>
<shadedPattern>${shade-prefix}.org.apache.commons</shadedPattern>
</relocation>
<relocation>
<pattern>org.slf4j</pattern>
<shadedPattern>${shade-prefix}.org.slf4j</shadedPattern>
</relocation>
</relocations>

<filters>
Expand Down
5 changes: 0 additions & 5 deletions iast-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
<resource>
<directory>src/main/resources</directory>
<includes>
<include>logback-dongtai.xml</include>
<include>dongtai-servlet.jar</include>
<include>**/version</include>
<include>**/logo</include>
Expand Down Expand Up @@ -83,10 +82,6 @@
<pattern>ch.qos</pattern>
<shadedPattern>${shade-prefix}.ch.qos</shadedPattern>
</relocation>
<relocation>
<pattern>org.slf4j</pattern>
<shadedPattern>${shade-prefix}.org.slf4j</shadedPattern>
</relocation>
<relocation>
<pattern>org.json</pattern>
<shadedPattern>${shade-prefix}.org.json</shadedPattern>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,54 +25,54 @@ static Method getAsmMethod(final Class<?> clazz,
}

/**
* asm method of {@link Injecter#spyMethodOnBefore(Object, Object[], String, String, String, String, String, String,
* Object, String, boolean, int)}
* asm method of {@link #spyMethodOnBefore(Object, Object[], String, String, String, String, Object, String,
* boolean, int)}
*/
Method ASM_METHOD_Spy$spyMethodOnBefore = InnerHelper.getAsmMethod(
Injecter.class,
"spyMethodOnBefore",
Object.class, Object[].class, String.class, String.class, String.class, String.class, String.class,
String.class, Object.class, String.class, boolean.class, int.class
Object.class, String.class, boolean.class, int.class
);

/**
* asm method of {@link Injecter#spyMethodOnReturn(Object, String, int)}
* asm method of {@link #spyMethodOnReturn(Object, int)}
*/
Method ASM_METHOD_Spy$spyMethodOnReturn = InnerHelper.getAsmMethod(
Injecter.class,
"spyMethodOnReturn",
Object.class, String.class, int.class
Object.class,
int.class
);

/**
* asm method of {@link Injecter#spyMethodOnThrows(Throwable, String, int)}
* asm method of {@link #spyMethodOnThrows(Throwable, int)}
*/
Method ASM_METHOD_Spy$spyMethodOnThrows = InnerHelper.getAsmMethod(
Injecter.class,
"spyMethodOnThrows",
Throwable.class, String.class, int.class
Throwable.class,
int.class
);

/**
* asm method of {@link Injecter#spyMethodEnterPropagator(String)}
* asm method of {@link #spyMethodEnterPropagator()}
*/
Method ASM_METHOD_Spy$spyMethodEnterPropagator = InnerHelper.getAsmMethod(
Injecter.class,
"spyMethodEnterPropagator",
String.class
"spyMethodEnterPropagator"
);

/**
* asm method of {@link Injecter#spyMethodLeavePropagator(String)}
* asm method of {@link #spyMethodLeavePropagator()}
*/
Method ASM_METHOD_Spy$spyMethodLeavePropagator = InnerHelper.getAsmMethod(
Injecter.class,
"spyMethodLeavePropagator",
String.class
"spyMethodLeavePropagator"
);

/**
* asm method of {@link Injecter#isFirstLevelPropagator(String)}
* asm method of {@link #isFirstLevelPropagator()}
*/
Method ASM_METHOD_Spy$isFirstLevelPropagator = InnerHelper.getAsmMethod(
Injecter.class,
Expand All @@ -81,150 +81,134 @@ static Method getAsmMethod(final Class<?> clazz,
);

/**
* asm method of {@link Injecter#enterSink(String)}
* asm method of {@link #enterSink()}
*/
Method ASM_METHOD_Spy$enterSink = InnerHelper.getAsmMethod(
Injecter.class,
"enterSink",
String.class
"enterSink"
);

/**
* asm method of {@link Injecter#leaveSink(String)}
* asm method of {@link #leaveSink()}
*/
Method ASM_METHOD_Spy$leaveSink = InnerHelper.getAsmMethod(
Injecter.class,
"leaveSink",
String.class
"leaveSink"
);

/**
* asm method of {@link Injecter#isFirstLevelSink(String)}
* asm method of {@link #isFirstLevelSink()}
*/
Method ASM_METHOD_Spy$isFirstLevelSink = InnerHelper.getAsmMethod(
Injecter.class,
"isFirstLevelSink",
String.class
"isFirstLevelSink"
);

Method ASM_METHOD_Spy$hasTaint = InnerHelper.getAsmMethod(
Injecter.class,
"hasTaint",
String.class
"hasTaint"
);

/**
* asm method of {@link Injecter#enterSource(String)}
* asm method of {@link #enterSource()}
*/
Method ASM_METHOD_Spy$enterSource = InnerHelper.getAsmMethod(
Injecter.class,
"enterSource",
String.class
"enterSource"
);

/**
* asm method of {@link Injecter#leaveSource(String)}
* asm method of {@link #leaveSource()}
*/
Method ASM_METHOD_Spy$leaveSource = InnerHelper.getAsmMethod(
Injecter.class,
"leaveSource",
String.class
"leaveSource"
);

/**
* asm method of {@link Injecter#isFirstLevelSource(String)}
* asm method of {@link #isFirstLevelSource()}
*/
Method ASM_METHOD_Spy$isFirstLevelSource = InnerHelper.getAsmMethod(
Injecter.class,
"isFirstLevelSource",
String.class
"isFirstLevelSource"
);

/**
* asm method of {@link Injecter#enterHttp(String)}
* asm method of {@link #enterHttp()}
*/
Method ASM_METHOD_Spy$enterHttp = InnerHelper.getAsmMethod(
Injecter.class,
"enterHttp",
String.class
"enterHttp"
);

/**
* asm method of {@link Injecter#leaveHttp(String, Object)}
* asm method of {@link #leaveHttp(Object)}
*/
Method ASM_METHOD_Spy$leaveHttp = InnerHelper.getAsmMethod(
Injecter.class,
"leaveHttp",
String.class,
Object.class
);

/**
* asm method of {@link Injecter#isFirstLevelHttp(String)}
* asm method of {@link #isFirstLevelHttp()}
*/
Method ASM_METHOD_Spy$isFirstLevelHttp = InnerHelper.getAsmMethod(
Injecter.class,
"isFirstLevelHttp",
String.class
"isFirstLevelHttp"
);

/**
* asm method of {@link Injecter#cloneRequest(String, Object, boolean)}
* asm method of {@link #cloneRequest(Object, boolean)}
*/
Method ASM_METHOD_Spy$cloneRequest = InnerHelper.getAsmMethod(
Injecter.class,
"cloneRequest",
String.class,
Object.class,
boolean.class
);

Method ASM_METHOD_Spy$isReplayRequest = InnerHelper.getAsmMethod(
Injecter.class,
"isReplayRequest",
String.class
"isReplayRequest"
);

Method ASM_METHOD_Spy$cloneResponse = InnerHelper.getAsmMethod(
Injecter.class,
"cloneResponse",
String.class,
Object.class,
boolean.class
);


/**
* asm method of {@link Injecter#enterDubbo(String)}
* asm method of {@link #enterDubbo()}
*
* @since 1.2.0
*/
Method ASM_METHOD_Spy$enterDubbo = InnerHelper.getAsmMethod(
Injecter.class,
"enterDubbo",
String.class
"enterDubbo"
);

/**
* asm method of {@link Injecter#leaveDubbo(String)}
* asm method of {@link #leaveDubbo()}
*
* @since 1.2.0
*/
Method ASM_METHOD_Spy$leaveDubbo = InnerHelper.getAsmMethod(
Injecter.class,
"leaveDubbo",
String.class
"leaveDubbo"
);

/**
* asm method of {@link Injecter#isFirstLevelDubbo(String)}
* asm method of {@link #isFirstLevelDubbo()}
*
* @since 1.2.0
*/
Method ASM_METHOD_Spy$isFirstLevelDubbo = InnerHelper.getAsmMethod(
Injecter.class,
"isFirstLevelDubbo",
String.class
"isFirstLevelDubbo"
);

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ public class SpyUtils {
public synchronized static void init(final String namespace) {
EngineManager.SCOPE_TRACKER.set(new TrackerHelper());
// 注册接口单例对象,将各模块的实现类传递进去
if (Injecter.isInit(namespace)) {
if (Injecter.isInit()) {
return;
}

Injecter.init(
namespace,
unCaughtGetClassDeclaredJavaMethod(EventListenerHandlers.class, "onBefore",
String.class,
String.class,
Expand Down Expand Up @@ -82,7 +81,7 @@ public synchronized static void init(final String namespace) {
* @param namespace 命名空间
*/
public synchronized static void clean(final String namespace) {
Injecter.clean(namespace);
Injecter.clean();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ protected void captureMethodState(
pushNull();
}
loadArgArray();
push(context.getNamespace());
push(type);
push(context.getClassName());
push(context.getMatchClassName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ protected void after(final int opcode) {
if (!ENABLE_ALL_HOOK) {
Label elseLabel = new Label();
Label endLabel = new Label();
push(context.getNamespace());
invokeStatic(ASM_TYPE_SPY, ASM_METHOD_Spy$isFirstLevelPropagator);
mv.visitJumpInsn(EQ, elseLabel);
captureMethodState(opcode, HookType.PROPAGATOR.getValue(), true);
Expand All @@ -47,12 +46,10 @@ protected void after(final int opcode) {
}

private void enterPropagator() {
push(context.getNamespace());
invokeStatic(ASM_TYPE_SPY, ASM_METHOD_Spy$spyMethodEnterPropagator);
}

private void leavePropagator() {
push(context.getNamespace());
invokeStatic(ASM_TYPE_SPY, ASM_METHOD_Spy$spyMethodLeavePropagator);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,27 @@ protected void after(final int opcode) {
* 进入sink方法的字节码
*/
private void enterSink() {
push(context.getNamespace());
invokeStatic(ASM_TYPE_SPY, ASM_METHOD_Spy$enterSink);
}

/**
* 判断是否位于顶级sink方法的字节码
*/
private void isTopLevelSink() {
push(context.getNamespace());
invokeStatic(ASM_TYPE_SPY, ASM_METHOD_Spy$isFirstLevelSink);
}

/**
* 判断是否进入http且具有污点 isTopLevelSink()
*/
private void hasTaint() {
push(context.getNamespace());
invokeStatic(ASM_TYPE_SPY, ASM_METHOD_Spy$hasTaint);
}

/**
* 离开sink方法的字节码
*/
private void leaveSink() {
push(context.getNamespace());
invokeStatic(ASM_TYPE_SPY, ASM_METHOD_Spy$leaveSink);
}
}
Loading