|
| 1 | +/** |
| 2 | + * @kind path-problem |
| 3 | + */ |
| 4 | + |
| 5 | +import java |
| 6 | +import semmle.code.java.dataflow.TaintTracking |
| 7 | +import semmle.code.java.dataflow.FlowSources |
| 8 | +import DataFlow::PathGraph |
| 9 | + |
| 10 | + |
| 11 | +/** |
| 12 | + * 把添加machine到定时任务执行连起来 |
| 13 | + * |
| 14 | + */ |
| 15 | +predicate machine(DataFlow::Node expSrc, DataFlow::Node expDest) { |
| 16 | + exists(MethodAccess ma, Method me, MethodAccess ma1,Method me1 | |
| 17 | + me.getName() = "addMachine" and |
| 18 | + me = ma.getMethod() and |
| 19 | + expSrc.asExpr() = ma.getAnArgument() and |
| 20 | + me1.getName()="fetchOnce" and |
| 21 | + ma1.getMethod() = me1 and |
| 22 | + ma1.getAnArgument() = expDest.asExpr() |
| 23 | + ) |
| 24 | +} |
| 25 | + |
| 26 | + |
| 27 | +/** |
| 28 | + * 把添加machine到每个MachineInfo调用自身方法连起来 |
| 29 | + */ |
| 30 | +predicate machine1(DataFlow::Node expSrc, DataFlow::Node expDest) { |
| 31 | + exists(MethodAccess ma, Method me, MethodAccess ma1,Method me1 | |
| 32 | + me.getName() = "addMachine" and |
| 33 | + me = ma.getMethod() and |
| 34 | + expSrc.asExpr() = ma.getAnArgument() and |
| 35 | + me1.getQualifiedName().matches("%MachineInfo%") and |
| 36 | + me1.getName().matches("%get%") and |
| 37 | + ma1.getMethod() = me1 and |
| 38 | + expDest.asExpr() = ma1 |
| 39 | + ) |
| 40 | +} |
| 41 | + |
| 42 | + |
| 43 | +predicate machine2(DataFlow::Node expSrc, DataFlow::Node expDest) { |
| 44 | + exists(MethodAccess ma, Method me, MethodAccess ma1,Method me1 | |
| 45 | + me.getName() = "getMachines" and |
| 46 | + me = ma.getMethod() and |
| 47 | + expSrc.asExpr() = ma and |
| 48 | + me1.getQualifiedName().matches("%MachineInfo%") and |
| 49 | + me1.getName().matches("%get%") and |
| 50 | + ma1.getMethod() = me1 and |
| 51 | + expDest.asExpr() = ma1 |
| 52 | + ) |
| 53 | +} |
| 54 | + |
| 55 | +// predicate machine2(DataFlow::Node expSrc, DataFlow::Node expDest) { |
| 56 | +// exists(MethodAccess ma, Method me | |
| 57 | +// me.getName() = "addMachine" and |
| 58 | +// me = ma.getMethod() and |
| 59 | +// expSrc.asExpr() = ma.getAnArgument() and |
| 60 | +// expDest.asExpr() = ma.getAnArgument() |
| 61 | +// ) |
| 62 | +// } |
| 63 | + |
| 64 | + |
| 65 | +class SsrfConfig extends TaintTracking::Configuration { |
| 66 | + SsrfConfig() { this = "SsrfConfig" } |
| 67 | + |
| 68 | + override predicate isSource(DataFlow::Node src) { |
| 69 | + src instanceof RemoteFlowSource |
| 70 | + } |
| 71 | + |
| 72 | + |
| 73 | +// override predicate isSink(DataFlow::Node sink) { |
| 74 | +// exists(Method me, MethodAccess ma| me.getName() = "execute" and ma.getMethod() = me and |
| 75 | +// ma.getAnArgument() = sink.asExpr()) |
| 76 | +// } |
| 77 | + |
| 78 | + override predicate isSink(DataFlow::Node sink) { |
| 79 | + exists(ConstructorCall call,Class clz| |
| 80 | + call.getAnArgument() = sink.asExpr() and call.getConstructedType()=clz and clz.getName()="HttpGet") |
| 81 | + } |
| 82 | + |
| 83 | + |
| 84 | + // override predicate isSink(DataFlow::Node sink) { |
| 85 | + // exists(Method method, MethodAccess call | |
| 86 | + // method.hasName("execute") and method.getDeclaringType().getAnAncestor().hasQualifiedName("org.apache.http.impl.nio.client", "CloseableHttpAsyncClient") and call.getMethod() = method |
| 87 | + // and |
| 88 | + // sink.asExpr() = call.getArgument(0) |
| 89 | + // ) |
| 90 | + // } |
| 91 | + |
| 92 | + override predicate isAdditionalTaintStep(DataFlow::Node expSrc, DataFlow::Node expDest) { |
| 93 | + exists(MethodAccess ma, Method me, MethodAccess maa,Method mee | |
| 94 | + // me.getQualifiedName().matches("%MachineInfo%") and |
| 95 | + me.getName()="setIp" and |
| 96 | + ma.getMethod() = me and |
| 97 | + expSrc.asExpr() = ma.getAnArgument() and |
| 98 | + // mee.getQualifiedName().matches("%MachineInfo%") and |
| 99 | + mee.getName().matches("getIp") and |
| 100 | + maa.getMethod() = mee and |
| 101 | + expDest.asExpr() = maa |
| 102 | + ) |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | +from SsrfConfig config, DataFlow::PathNode source, DataFlow::PathNode sink |
| 107 | +where config.hasFlowPath(source, sink) |
| 108 | +select source.getNode(), source, sink, "source" |
0 commit comments