Skip to content

Commit 47eda6d

Browse files
authored
Merge pull request #483 from HXSecurity/beta
1.9.0-beta1
2 parents e8aedc7 + 3e0753a commit 47eda6d

37 files changed

+1257
-203
lines changed

.github/workflows/code-check.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ name: Build Agent and Upload To OSS
55

66
on:
77
push:
8-
branches: [ main ]
8+
branches:
9+
- main
10+
- beta
911
pull_request:
10-
branches: [ main ]
12+
branches:
13+
- main
14+
- beta
1115
paths-ignore:
1216
- '.github/**'
1317
- 'changes/**'

.github/workflows/codeql-analysis.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ name: "CodeQL"
1313

1414
on:
1515
push:
16-
branches: [ main ]
16+
branches:
17+
- main
18+
- beta
1719
paths-ignore:
1820
- '.github/**'
1921
- 'changes/**'
@@ -24,7 +26,9 @@ on:
2426
- 'LICENSE'
2527
- '.gitignore'
2628
pull_request:
27-
branches: [ main ]
29+
branches:
30+
- main
31+
- beta
2832
paths-ignore:
2933
- '.github/**'
3034
- 'changes/**'

dongtai-common/src/main/java/io/dongtai/iast/common/constants/AgentConstant.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.dongtai.iast.common.constants;
22

33
public class AgentConstant {
4-
public static final String VERSION_VALUE = "v1.8.2";
4+
public static final String VERSION_VALUE = "v1.9.0-beta1";
55
public static final String LANGUAGE = "JAVA";
66
public static final String THREAD_NAME_PREFIX = "DongTai-IAST-";
77
public static final String THREAD_NAME_PREFIX_CORE = "DongTai-IAST-Core-";

dongtai-common/src/main/java/io/dongtai/iast/common/scope/Scope.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ public enum Scope {
55
HTTP_ENTRY(2),
66
SERVLET_INPUT_STREAM_READ(3),
77
SERVLET_OUTPUT_WRITE(4),
8+
DUBBO_REQUEST(5),
9+
DUBBO_ENTRY(6),
10+
DUBBO_SOURCE(7),
811
;
912

1013
private final int id;

dongtai-common/src/main/java/io/dongtai/iast/common/scope/ScopeAggregator.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
public class ScopeAggregator {
44
private final GeneralScope httpRequestScope = new GeneralScope();
55
private final GeneralScope httpEntryScope = new GeneralScope();
6+
private final GeneralScope dubboRequestScope = new GeneralScope();
7+
private final GeneralScope dubboEntryScope = new GeneralScope();
8+
private final GeneralScope dubboSourceScope = new GeneralScope();
69
private final GeneralScope servletInputStreamReadScope = new GeneralScope();
710
private final GeneralScope servletOutputStreamWriteScope = new GeneralScope();
811
private final PolicyScope policyScope = new PolicyScope();
@@ -15,6 +18,18 @@ public GeneralScope getHttpEntryScope() {
1518
return httpEntryScope;
1619
}
1720

21+
public GeneralScope getDubboRequestScope() {
22+
return dubboRequestScope;
23+
}
24+
25+
public GeneralScope getDubboEntryScope() {
26+
return dubboEntryScope;
27+
}
28+
29+
public GeneralScope getDubboSourceScope() {
30+
return dubboSourceScope;
31+
}
32+
1833
public GeneralScope getServletInputStreamReadScope() {
1934
return servletInputStreamReadScope;
2035
}

dongtai-common/src/main/java/io/dongtai/iast/common/scope/ScopeTracker.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ public GeneralScope getScope(Scope scope) {
1616
return this.get().getServletInputStreamReadScope();
1717
case SERVLET_OUTPUT_WRITE:
1818
return this.get().getServletOutputStreamWriteScope();
19+
case DUBBO_REQUEST:
20+
return this.get().getDubboRequestScope();
21+
case DUBBO_ENTRY:
22+
return this.get().getDubboEntryScope();
23+
case DUBBO_SOURCE:
24+
return this.get().getDubboSourceScope();
1925
default:
2026
return null;
2127
}
2228
}
2329

2430
public boolean inEnterEntry() {
25-
return this.get().getHttpEntryScope().in();
31+
return this.get().getHttpEntryScope().in() || this.get().getDubboRequestScope().in();
2632
}
2733

2834
public PolicyScope getPolicyScope() {

dongtai-core/src/main/java/io/dongtai/iast/core/EngineManager.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,12 @@ public static void enterHttpEntry(Map<String, Object> requestMeta) {
140140
TAINT_RANGES_POOL.set(new HashMap<Integer, TaintRanges>());
141141
ScopeManager.SCOPE_TRACKER.getScope(Scope.HTTP_ENTRY).enter();
142142
}
143+
144+
public static void enterDubboEntry(Map<String, Object> requestMeta) {
145+
REQUEST_CONTEXT.set(requestMeta);
146+
TRACK_MAP.set(new HashMap<Integer, MethodEvent>(1024));
147+
TAINT_HASH_CODES.set(new HashSet<Integer>());
148+
TAINT_RANGES_POOL.set(new HashMap<Integer, TaintRanges>());
149+
ScopeManager.SCOPE_TRACKER.getScope(Scope.DUBBO_ENTRY).enter();
150+
}
143151
}

dongtai-core/src/main/java/io/dongtai/iast/core/bytecode/enhance/asm/AsmMethods.java

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
import java.lang.dongtai.SpyDispatcher;
66
import java.lang.dongtai.SpyDispatcherHandler;
7-
import java.util.Collection;
8-
import java.util.Enumeration;
7+
import java.net.InetSocketAddress;
8+
import java.util.*;
99

1010
/**
1111
* 常用的ASM method 集合 省得我到处声明
@@ -132,6 +132,54 @@ static Method getAsmMethod(final Class<?> clazz,
132132
int.class
133133
);
134134

135+
Method SPY$enterDubbo = InnerHelper.getAsmMethod(
136+
SpyDispatcher.class,
137+
"enterDubbo"
138+
);
139+
Method SPY$leaveDubbo = InnerHelper.getAsmMethod(
140+
SpyDispatcher.class,
141+
"leaveDubbo",
142+
Object.class,
143+
Object.class
144+
);
145+
Method SPY$isFirstLevelDubbo = InnerHelper.getAsmMethod(
146+
SpyDispatcher.class,
147+
"isFirstLevelDubbo"
148+
);
149+
Method SPY$collectDubboRequest = InnerHelper.getAsmMethod(
150+
SpyDispatcher.class,
151+
"collectDubboRequest",
152+
Object.class,
153+
Object.class,
154+
Object.class,
155+
String.class,
156+
InetSocketAddress.class,
157+
boolean.class,
158+
boolean.class,
159+
boolean.class,
160+
boolean.class
161+
);
162+
163+
Method SPY$collectDubboRequestSource = InnerHelper.getAsmMethod(
164+
SpyDispatcher.class,
165+
"collectDubboRequestSource",
166+
Object.class,
167+
Object.class,
168+
String.class,
169+
Object[].class,
170+
Map.class,
171+
String.class,
172+
String.class,
173+
String.class
174+
);
175+
176+
Method SPY$collectDubboResponse = InnerHelper.getAsmMethod(
177+
SpyDispatcher.class,
178+
"collectDubboResponse",
179+
Object.class,
180+
byte.class
181+
);
182+
135183
Method SPY$enterSource = InnerHelper.getAsmMethod(
136184
SpyDispatcher.class,
137185
"enterSource"
@@ -209,6 +257,19 @@ static Method getAsmMethod(final Class<?> clazz,
209257
String.class
210258
);
211259

260+
Method SPY$traceDubboInvoke = InnerHelper.getAsmMethod(
261+
SpyDispatcher.class,
262+
"traceDubboInvoke",
263+
Object.class,
264+
String.class,
265+
Object.class,
266+
Object[].class,
267+
Map.class,
268+
String.class,
269+
String.class,
270+
String.class
271+
);
272+
212273
Method SPY$reportService = InnerHelper.getAsmMethod(
213274
SpyDispatcher.class,
214275
"reportService",

dongtai-core/src/main/java/io/dongtai/iast/core/bytecode/enhance/plugin/PluginRegister.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.dongtai.iast.core.bytecode.enhance.ClassContext;
44
import io.dongtai.iast.core.bytecode.enhance.plugin.authentication.shiro.DispatchShiro;
55
import io.dongtai.iast.core.bytecode.enhance.plugin.core.DispatchClassPlugin;
6+
import io.dongtai.iast.core.bytecode.enhance.plugin.framework.dubbo.DispatchDubbo;
67
import io.dongtai.iast.core.bytecode.enhance.plugin.framework.feign.DispatchFeign;
78
import io.dongtai.iast.core.bytecode.enhance.plugin.framework.j2ee.dispatch.DispatchJ2ee;
89
import io.dongtai.iast.core.bytecode.enhance.plugin.hardcoded.DispatchHardcodedPlugin;
@@ -34,6 +35,7 @@ public PluginRegister() {
3435
this.plugins.add(new DispatchJdbc());
3536
this.plugins.add(new DispatchShiro());
3637
this.plugins.add(new DispatchFeign());
38+
this.plugins.add(new DispatchDubbo());
3739

3840
this.plugins.add(new DispatchClassPlugin());
3941
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package io.dongtai.iast.core.bytecode.enhance.plugin.framework.dubbo;
2+
3+
import io.dongtai.iast.core.bytecode.enhance.ClassContext;
4+
import io.dongtai.iast.core.bytecode.enhance.plugin.DispatchPlugin;
5+
import io.dongtai.iast.core.handler.hookpoint.models.policy.Policy;
6+
import org.objectweb.asm.ClassVisitor;
7+
8+
public class DispatchDubbo implements DispatchPlugin {
9+
public static final String ALIBABA_DUBBO_SYNC_HANDLER = " com.alibaba.dubbo.rpc.listener.ListenerInvokerWrapper".substring(1);
10+
public static final String APACHE_DUBBO_SYNC_HANDLER = " org.apache.dubbo.rpc.listener.ListenerInvokerWrapper".substring(1);
11+
public static final String ALIBABA_DUBBO_EXCHANGE_HANDLER = " com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler".substring(1);
12+
public static final String APACHE_DUBBO_EXCHANGE_HANDLER = " org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler".substring(1);
13+
public static final String APACHE_DUBBO_EXCHANGE_CHANNEL = " org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeChannel".substring(1);
14+
public static final String ALIBABA_DUBBO_PROXY_HANDLER = " com.alibaba.dubbo.rpc.proxy.AbstractProxyInvoker".substring(1);
15+
public static final String APACHE_DUBBO_PROXY_HANDLER = " org.apache.dubbo.rpc.proxy.AbstractProxyInvoker".substring(1);
16+
17+
@Override
18+
public ClassVisitor dispatch(ClassVisitor classVisitor, ClassContext context, Policy policy) {
19+
String className = context.getClassName();
20+
21+
if (ALIBABA_DUBBO_SYNC_HANDLER.equals(className)) {
22+
classVisitor = new DubboSyncHandlerAdapter(classVisitor, context, " com.alibaba".substring(1));
23+
} else if (APACHE_DUBBO_SYNC_HANDLER.equals(className)) {
24+
classVisitor = new DubboSyncHandlerAdapter(classVisitor, context, " org.apache".substring(1));
25+
} else if (ALIBABA_DUBBO_EXCHANGE_HANDLER.equals(className)) {
26+
classVisitor = new DubboExchangeHandlerAdapter(classVisitor, context, " com.alibaba".substring(1));
27+
} else if (APACHE_DUBBO_EXCHANGE_HANDLER.equals(className)) {
28+
classVisitor = new DubboExchangeHandlerAdapter(classVisitor, context, " org.apache".substring(1));
29+
} else if (APACHE_DUBBO_EXCHANGE_CHANNEL.equals(className)) {
30+
classVisitor = new DubboExchangeChannelAdapter(classVisitor, context, " org.apache".substring(1));
31+
} else if (ALIBABA_DUBBO_PROXY_HANDLER.equals(className)) {
32+
classVisitor = new DubboProxyHandlerAdapter(classVisitor, context, " com.alibaba".substring(1));
33+
} else if (APACHE_DUBBO_PROXY_HANDLER.equals(className)) {
34+
classVisitor = new DubboProxyHandlerAdapter(classVisitor, context, " org.apache".substring(1));
35+
}
36+
37+
return classVisitor;
38+
}
39+
}

0 commit comments

Comments
 (0)