|
| 1 | +/** |
| 2 | + * @name BeanShell injection |
| 3 | + * @description Evaluation of a user-controlled BeanShell expression |
| 4 | + * may lead to arbitrary code execution. |
| 5 | + * @kind path-problem |
| 6 | + * @problem.severity error |
| 7 | + * @precision high |
| 8 | + * @id java/beanshell-injection |
| 9 | + * @tags security |
| 10 | + * external/cwe/cwe-094 |
| 11 | + */ |
| 12 | + |
| 13 | +import java |
| 14 | +import BeanShellInjection |
| 15 | +import semmle.code.java.dataflow.FlowSources |
| 16 | +import DataFlow::PathGraph |
| 17 | + |
| 18 | +class BeanShellInjectionConfig extends TaintTracking::Configuration { |
| 19 | + BeanShellInjectionConfig() { this = "BeanShellInjectionConfig" } |
| 20 | + |
| 21 | + override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource } |
| 22 | + |
| 23 | + override predicate isSink(DataFlow::Node sink) { sink instanceof BeanShellInjectionSink } |
| 24 | + |
| 25 | + override predicate isAdditionalTaintStep(DataFlow::Node prod, DataFlow::Node succ) { |
| 26 | + exists(ClassInstanceExpr cie | |
| 27 | + cie.getConstructedType() |
| 28 | + .hasQualifiedName("org.springframework.scripting.support", "StaticScriptSource") and |
| 29 | + cie.getArgument(0) = prod.asExpr() and |
| 30 | + cie = succ.asExpr() |
| 31 | + ) |
| 32 | + or |
| 33 | + exists(MethodAccess ma | |
| 34 | + ma.getMethod().hasName("setScript") and |
| 35 | + ma.getMethod() |
| 36 | + .getDeclaringType() |
| 37 | + .hasQualifiedName("org.springframework.scripting.support", "StaticScriptSource") and |
| 38 | + ma.getArgument(0) = prod.asExpr() and |
| 39 | + ma.getQualifier() = succ.asExpr() |
| 40 | + ) |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +from DataFlow::PathNode source, DataFlow::PathNode sink, BeanShellInjectionConfig conf |
| 45 | +where conf.hasFlowPath(source, sink) |
| 46 | +select sink.getNode(), source, sink, "BeanShell injection from $@.", source.getNode(), |
| 47 | + "this user input" |
0 commit comments