Skip to content

Commit 0bd0d5f

Browse files
committed
feat: 新增QLExpress组件检测时判断安全配置是否开启
1 parent f779d40 commit 0bd0d5f

File tree

3 files changed

+76
-2
lines changed

3 files changed

+76
-2
lines changed

dongtai-core/src/main/java/io/dongtai/iast/core/bytecode/IastClassFileTransformer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.dongtai.iast.core.handler.hookpoint.SpyDispatcherImpl;
1111
import io.dongtai.iast.core.handler.hookpoint.models.policy.PolicyManager;
1212
import io.dongtai.iast.core.handler.hookpoint.vulscan.dynamic.FastjsonCheck;
13+
import io.dongtai.iast.core.handler.hookpoint.vulscan.dynamic.QLExpressCheck;
1314
import io.dongtai.iast.core.utils.AsmUtils;
1415
import io.dongtai.iast.core.utils.PropertyUtils;
1516
import io.dongtai.iast.core.utils.matcher.ConfigMatcher;
@@ -145,7 +146,9 @@ public byte[] transform(final ClassLoader loader,
145146

146147
try {
147148
ScopeManager.SCOPE_TRACKER.getPolicyScope().enterAgent();
148-
149+
if (" com/ql/util/express/config/QLExpressRunStrategy".substring(1).equals(internalClassName)){
150+
QLExpressCheck.setQLClassLoader(loader);
151+
}
149152
if (" com/alibaba/fastjson/JSON".substring(1).equals(internalClassName)) {
150153
FastjsonCheck.setJsonClassLoader(loader);
151154
} else if (" com/alibaba/fastjson/parser/ParserConfig".substring(1).equals(internalClassName)) {

dongtai-core/src/main/java/io/dongtai/iast/core/handler/hookpoint/vulscan/dynamic/DynamicPropagatorScanner.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
public class DynamicPropagatorScanner implements IVulScan {
2626
private final static Set<SinkSafeChecker> SAFE_CHECKERS = new HashSet<>(Arrays.asList(
2727
new FastjsonCheck(),
28-
new XXECheck()
28+
new XXECheck(),
29+
new QLExpressCheck()
2930
));
3031

3132
private final static Set<SinkSourceChecker> SOURCE_CHECKERS = new HashSet<>(Arrays.asList(
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package io.dongtai.iast.core.handler.hookpoint.vulscan.dynamic;
2+
3+
import io.dongtai.iast.core.handler.hookpoint.models.MethodEvent;
4+
import io.dongtai.iast.core.handler.hookpoint.models.policy.SignatureMethodMatcher;
5+
import io.dongtai.iast.core.handler.hookpoint.models.policy.SinkNode;
6+
import io.dongtai.log.DongTaiLog;
7+
8+
import java.lang.reflect.Field;
9+
import java.lang.reflect.Modifier;
10+
import java.util.Arrays;
11+
import java.util.List;
12+
13+
/**
14+
* @author UzJu
15+
* @date 2023/10/24 16:02
16+
* @Site UzzJu.com
17+
* @Comment :)
18+
*/
19+
20+
public class QLExpressCheck implements SinkSafeChecker {
21+
public static List<String> QLExpress_SINK_METHODS = Arrays.asList(
22+
" com.ql.util.express.ExpressRunner.parseInstructionSet(java.lang.String)".substring(1)
23+
);
24+
private String policySignature;
25+
private static ClassLoader QL_CLASS_LOADER;
26+
27+
@Override
28+
public boolean match(MethodEvent event, SinkNode sinkNode) {
29+
if (sinkNode.getMethodMatcher() instanceof SignatureMethodMatcher) {
30+
this.policySignature = ((SignatureMethodMatcher) sinkNode.getMethodMatcher()).getSignature().toString();
31+
}
32+
33+
return QLExpress_SINK_METHODS.contains(this.policySignature);
34+
}
35+
36+
@Override
37+
public boolean isSafe(MethodEvent event, SinkNode sinkNode){
38+
/**
39+
* Die QLExpress-Komponente bietet die Konfigurationsfunktion forbidInvokeSecurityRiskMethods, um die Erkennung von schwarzen Listen zu ermöglichen. Daher muss zusätzlich zur Bestimmung des Senkenpunkts auch festgestellt werden, ob der Benutzer diese Konfiguration aktiviert hat.
40+
* Wenn diese Konfiguration aktiviert ist, werden Sie beim Aufruf einer auf der schwarzen Liste stehenden Klasse aufgefordert: com.ql.util.express.exception.QLSecurityRiskException: Eine unsichere Systemmethode wurde mit QLExpress aufgerufen: public java.lang.Process java. lang.Runtime.exec(java.lang.String) throws java.io.IOException
41+
* */
42+
DongTaiLog.debug("Start der Ermittlung, ob das Feld forbidInvokeSecurityRiskMethods der QLExpress-Komponente wahr ist oder nicht");
43+
try {
44+
Class<?> cls;
45+
if (QL_CLASS_LOADER == null){
46+
cls = Class.forName(" com.ql.util.express.config.QLExpressRunStrategy".substring(1));
47+
}else {
48+
cls = Class.forName(" com.ql.util.express.config.QLExpressRunStrategy".substring(1), false, QL_CLASS_LOADER);
49+
}
50+
Field field = cls.getDeclaredField("forbidInvokeSecurityRiskMethods");
51+
if (Modifier.isStatic(field.getModifiers()) && Modifier.isPrivate(field.getModifiers())) {
52+
field.setAccessible(true);
53+
boolean value = field.getBoolean(null);
54+
DongTaiLog.debug("forbidInvokeSecurityRiskMethods = " + value);
55+
return value;
56+
} else {
57+
DongTaiLog.debug("Field is not static and private.");
58+
return true;
59+
}
60+
}catch (Throwable e){
61+
DongTaiLog.debug("Beim Abrufen der Felder der QLExpress-Komponente ist ein Fehler aufgetreten.: {}, {}",
62+
e.getClass().getName() + ": " + e.getMessage(),
63+
e.getCause() != null ? e.getCause().getMessage() : "");
64+
return true;
65+
}
66+
}
67+
public static void setQLClassLoader(ClassLoader qlClassLoader) {
68+
QL_CLASS_LOADER = qlClassLoader;
69+
}
70+
}

0 commit comments

Comments
 (0)