-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #483 from HXSecurity/beta
1.9.0-beta1
- Loading branch information
Showing
37 changed files
with
1,257 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
dongtai-common/src/main/java/io/dongtai/iast/common/constants/AgentConstant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...main/java/io/dongtai/iast/core/bytecode/enhance/plugin/framework/dubbo/DispatchDubbo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.dongtai.iast.core.bytecode.enhance.plugin.framework.dubbo; | ||
|
||
import io.dongtai.iast.core.bytecode.enhance.ClassContext; | ||
import io.dongtai.iast.core.bytecode.enhance.plugin.DispatchPlugin; | ||
import io.dongtai.iast.core.handler.hookpoint.models.policy.Policy; | ||
import org.objectweb.asm.ClassVisitor; | ||
|
||
public class DispatchDubbo implements DispatchPlugin { | ||
public static final String ALIBABA_DUBBO_SYNC_HANDLER = " com.alibaba.dubbo.rpc.listener.ListenerInvokerWrapper".substring(1); | ||
public static final String APACHE_DUBBO_SYNC_HANDLER = " org.apache.dubbo.rpc.listener.ListenerInvokerWrapper".substring(1); | ||
public static final String ALIBABA_DUBBO_EXCHANGE_HANDLER = " com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler".substring(1); | ||
public static final String APACHE_DUBBO_EXCHANGE_HANDLER = " org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler".substring(1); | ||
public static final String APACHE_DUBBO_EXCHANGE_CHANNEL = " org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeChannel".substring(1); | ||
public static final String ALIBABA_DUBBO_PROXY_HANDLER = " com.alibaba.dubbo.rpc.proxy.AbstractProxyInvoker".substring(1); | ||
public static final String APACHE_DUBBO_PROXY_HANDLER = " org.apache.dubbo.rpc.proxy.AbstractProxyInvoker".substring(1); | ||
|
||
@Override | ||
public ClassVisitor dispatch(ClassVisitor classVisitor, ClassContext context, Policy policy) { | ||
String className = context.getClassName(); | ||
|
||
if (ALIBABA_DUBBO_SYNC_HANDLER.equals(className)) { | ||
classVisitor = new DubboSyncHandlerAdapter(classVisitor, context, " com.alibaba".substring(1)); | ||
} else if (APACHE_DUBBO_SYNC_HANDLER.equals(className)) { | ||
classVisitor = new DubboSyncHandlerAdapter(classVisitor, context, " org.apache".substring(1)); | ||
} else if (ALIBABA_DUBBO_EXCHANGE_HANDLER.equals(className)) { | ||
classVisitor = new DubboExchangeHandlerAdapter(classVisitor, context, " com.alibaba".substring(1)); | ||
} else if (APACHE_DUBBO_EXCHANGE_HANDLER.equals(className)) { | ||
classVisitor = new DubboExchangeHandlerAdapter(classVisitor, context, " org.apache".substring(1)); | ||
} else if (APACHE_DUBBO_EXCHANGE_CHANNEL.equals(className)) { | ||
classVisitor = new DubboExchangeChannelAdapter(classVisitor, context, " org.apache".substring(1)); | ||
} else if (ALIBABA_DUBBO_PROXY_HANDLER.equals(className)) { | ||
classVisitor = new DubboProxyHandlerAdapter(classVisitor, context, " com.alibaba".substring(1)); | ||
} else if (APACHE_DUBBO_PROXY_HANDLER.equals(className)) { | ||
classVisitor = new DubboProxyHandlerAdapter(classVisitor, context, " org.apache".substring(1)); | ||
} | ||
|
||
return classVisitor; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...ongtai/iast/core/bytecode/enhance/plugin/framework/dubbo/DubboExchangeChannelAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.dongtai.iast.core.bytecode.enhance.plugin.framework.dubbo; | ||
|
||
import io.dongtai.iast.core.bytecode.enhance.ClassContext; | ||
import io.dongtai.iast.core.bytecode.enhance.plugin.AbstractClassVisitor; | ||
import io.dongtai.iast.core.utils.AsmUtils; | ||
import io.dongtai.log.DongTaiLog; | ||
import org.objectweb.asm.ClassVisitor; | ||
import org.objectweb.asm.MethodVisitor; | ||
|
||
public class DubboExchangeChannelAdapter extends AbstractClassVisitor { | ||
public static final String DUBBO_EXCHANGE_CHANNEL_SEND = "{package}.dubbo.remoting.exchange.support.header.HeaderExchangeChannel.send(java.lang.Object)"; | ||
|
||
private final String packageName; | ||
private final String sendSign; | ||
|
||
public DubboExchangeChannelAdapter(ClassVisitor classVisitor, ClassContext context, String packageName) { | ||
super(classVisitor, context); | ||
this.packageName = packageName; | ||
this.sendSign = DUBBO_EXCHANGE_CHANNEL_SEND.replace("{package}", this.packageName); | ||
} | ||
|
||
@Override | ||
public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) { | ||
MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); | ||
String signCode = AsmUtils.buildSignature(context.getClassName(), name, desc); | ||
|
||
if (this.sendSign.equals(signCode)) { | ||
DongTaiLog.debug("Adding dubbo provider response tracking by {}", signCode); | ||
mv = new DubboExchangeChannelSendAdviceAdapter(mv, access, name, desc, signCode, | ||
this.context, this.packageName); | ||
setTransformed(); | ||
} | ||
return mv; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...t/core/bytecode/enhance/plugin/framework/dubbo/DubboExchangeChannelSendAdviceAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package io.dongtai.iast.core.bytecode.enhance.plugin.framework.dubbo; | ||
|
||
import io.dongtai.iast.core.bytecode.enhance.ClassContext; | ||
import io.dongtai.iast.core.bytecode.enhance.plugin.AbstractAdviceAdapter; | ||
import org.objectweb.asm.*; | ||
import org.objectweb.asm.commons.Method; | ||
|
||
public class DubboExchangeChannelSendAdviceAdapter extends AbstractAdviceAdapter { | ||
private static final Method GET_RESULT_METHOD = Method.getMethod("java.lang.Object getResult()"); | ||
private static final Method GET_STATUS_METHOD = Method.getMethod("byte getStatus()"); | ||
|
||
private final String packageName; | ||
private final Type objectType; | ||
private final Type responseType; | ||
|
||
protected DubboExchangeChannelSendAdviceAdapter(MethodVisitor mv, int access, String name, String desc, | ||
String signature, ClassContext context, String packageName) { | ||
super(mv, access, name, desc, context, "dubbo", signature); | ||
this.packageName = packageName; | ||
String packageDesc = packageName.replace(".", "/"); | ||
this.responseType = Type.getObjectType(packageDesc + "/dubbo/remoting/exchange/Response"); | ||
this.objectType = Type.getObjectType("java/lang/Object"); | ||
} | ||
|
||
@Override | ||
protected void before() { | ||
mark(tryLabel); | ||
Label elseLabel = new Label(); | ||
|
||
isFirstLevelDubbo(); | ||
mv.visitJumpInsn(EQ, elseLabel); | ||
|
||
collectDubboResponse(); | ||
|
||
mark(elseLabel); | ||
} | ||
|
||
@Override | ||
protected void after(int opcode) { | ||
} | ||
|
||
private void isFirstLevelDubbo() { | ||
invokeStatic(ASM_TYPE_SPY_HANDLER, SPY_HANDLER$getDispatcher); | ||
invokeInterface(ASM_TYPE_SPY_DISPATCHER, SPY$isFirstLevelDubbo); | ||
} | ||
|
||
private void collectDubboResponse() { | ||
Label tryL = new Label(); | ||
Label catchL = new Label(); | ||
Label exHandlerL = new Label(); | ||
visitTryCatchBlock(tryL, catchL, exHandlerL, ASM_TYPE_THROWABLE.getInternalName()); | ||
visitLabel(tryL); | ||
|
||
|
||
int respLocal = newLocal(this.responseType); | ||
loadArg(0); | ||
checkCast(this.responseType); | ||
storeLocal(respLocal); | ||
|
||
invokeStatic(ASM_TYPE_SPY_HANDLER, SPY_HANDLER$getDispatcher); | ||
loadLocal(respLocal); | ||
invokeVirtual(this.responseType, GET_RESULT_METHOD); | ||
loadLocal(respLocal); | ||
invokeVirtual(this.responseType, GET_STATUS_METHOD); | ||
invokeInterface(ASM_TYPE_SPY_DISPATCHER, SPY$collectDubboResponse); | ||
|
||
visitLabel(catchL); | ||
Label endL = new Label(); | ||
visitJumpInsn(GOTO, endL); | ||
visitLabel(exHandlerL); | ||
visitVarInsn(ASTORE, this.nextLocal); | ||
visitLabel(endL); | ||
} | ||
} |
Oops, something went wrong.