|
9 | 9 | import java.lang.reflect.Modifier; |
10 | 10 | import java.util.Arrays; |
11 | 11 | import java.util.List; |
| 12 | +import java.util.Set; |
12 | 13 |
|
13 | 14 | /** |
14 | 15 | * @author UzJu |
@@ -36,29 +37,43 @@ public boolean match(MethodEvent event, SinkNode sinkNode) { |
36 | 37 | @Override |
37 | 38 | public boolean isSafe(MethodEvent event, SinkNode sinkNode){ |
38 | 39 | /** |
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 |
| 40 | + * The QLExpress component provides the forbidInvokeSecurityRiskMethods configuration function to enable blacklist detection. Therefore, in addition to determining the sink point, you must also determine if the user has this configuration enabled. |
| 41 | + * If this configuration is enabled, you will be prompted when calling a blacklisted class: com.ql.util.express.exception.QLSecurityRiskException: An unsafe system method was called using QLExpress: public java.lang.Process java. lang.Runtime.exec(java.lang.String) throws java.io.IOException |
41 | 42 | * */ |
42 | | - DongTaiLog.debug("Start der Ermittlung, ob das Feld forbidInvokeSecurityRiskMethods der QLExpress-Komponente wahr ist oder nicht"); |
| 43 | + DongTaiLog.debug("Start determining whether the forbidInvokeSecurityRiskMethods field of the QLExpress component is true or not."); |
43 | 44 | try { |
44 | 45 | Class<?> cls; |
45 | 46 | if (QL_CLASS_LOADER == null){ |
46 | 47 | cls = Class.forName(" com.ql.util.express.config.QLExpressRunStrategy".substring(1)); |
47 | 48 | }else { |
48 | 49 | cls = Class.forName(" com.ql.util.express.config.QLExpressRunStrategy".substring(1), false, QL_CLASS_LOADER); |
49 | 50 | } |
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; |
| 51 | + |
| 52 | + Field getBlackListField = cls.getDeclaredField("forbidInvokeSecurityRiskMethods"); |
| 53 | + Field getSendBoxModeField = cls.getDeclaredField("sandboxMode"); |
| 54 | + Field getWhiteListField = cls.getDeclaredField("SECURE_METHOD_LIST"); |
| 55 | + |
| 56 | + if (Modifier.isStatic(getBlackListField.getModifiers()) && Modifier.isPrivate(getBlackListField.getModifiers()) && Modifier.isStatic(getSendBoxModeField.getModifiers()) && Modifier.isPrivate(getSendBoxModeField.getModifiers()) && Modifier.isStatic(getWhiteListField.getModifiers()) && Modifier.isPrivate(getWhiteListField.getModifiers())) { |
| 57 | + // Make private fields accessible to reflection |
| 58 | + getBlackListField.setAccessible(true); |
| 59 | + getSendBoxModeField.setAccessible(true); |
| 60 | + getWhiteListField.setAccessible(true); |
| 61 | + |
| 62 | + // get fields value |
| 63 | + boolean blackListBoolean = getBlackListField.getBoolean(null); |
| 64 | + boolean sendBoxBoolean = getSendBoxModeField.getBoolean(null); |
| 65 | + Set<String> secureMethodList = (Set<String>) getWhiteListField.get(null); |
| 66 | + DongTaiLog.debug("SECURE_METHOD_LIST = " + secureMethodList); |
| 67 | + DongTaiLog.debug("sandboxMode = " + sendBoxBoolean); |
| 68 | + DongTaiLog.debug("forbidInvokeSecurityRiskMethods = " + blackListBoolean); |
| 69 | + // All three conditions need to be met |
| 70 | + return (secureMethodList != null && !secureMethodList.isEmpty()) || sendBoxBoolean || blackListBoolean; |
56 | 71 | } else { |
57 | 72 | DongTaiLog.debug("Field is not static and private."); |
58 | 73 | return true; |
59 | 74 | } |
60 | 75 | }catch (Throwable e){ |
61 | | - DongTaiLog.debug("Beim Abrufen der Felder der QLExpress-Komponente ist ein Fehler aufgetreten.: {}, {}", |
| 76 | + DongTaiLog.debug("An error occurred while retrieving the fields of the QLExpress component.: {}, {}", |
62 | 77 | e.getClass().getName() + ": " + e.getMessage(), |
63 | 78 | e.getCause() != null ? e.getCause().getMessage() : ""); |
64 | 79 | return true; |
|
0 commit comments