这玩意比较抽象,全靠自己理解。推荐两个入门文章
codeQL入门CodeQL从入门到放弃
网上文章也开始多起来了,学吧

好文推荐

  1. @GetMapping("/vuln/yarm")
  2. public void yarm(String content) {
  3. Yaml y = new Yaml();
  4. y.load(content);
  5. }
/**
 * @id java/examples/vuldemo
 * @name RCEConfig
 * @description RCEConfig
 * @kind path-problem
 * @problem.severity warning
 */

import java
import semmle.code.java.dataflow.FlowSources
import semmle.code.java.security.QueryInjection
import DataFlow::PathGraph

class VulConfig extends TaintTracking::Configuration {
  VulConfig() { this = "RCEConfig" }

  override predicate isSource(DataFlow::Node src) {
    src instanceof RemoteFlowSource
  }

  override predicate isSink(DataFlow::Node sink) {
    exists(Method method, Call call |
      //  用这个名字的可能不是什么好东西,这个exec我是将他也作为了Runtime去扫,所以下面就不再有这个类
      method.hasName("exec") 
      or method.hasName("eval") 
      or method.hasName("evaluate") |
      call.getCallee() = method
      and sink.asExpr() = call.getArgument(0)
      )
    or
    exists(ConstructorCall expr, Constructor cons |
      //  还有这个
      cons.getDeclaringType().hasQualifiedName("java.lang", "ProcessBuilder") |
      expr.getConstructor() = cons
      and sink.asExpr() = expr.getArgument(0)
    )
  }
}

from VulConfig config, DataFlow::PathNode source, DataFlow::PathNode sink
where config.hasFlowPath(source, sink)
select source.getNode(), source, sink, "source"

image.png

SSRF.ql

虽然不能说有newURL(url)就算ssrf,但是这样误报总比漏报好,newURL(url)一般都会用到,先就这样

/**
 * @id java/examples/vuldemo
 * @name RCEConfig
 * @description RCEConfig
 * @kind path-problem
 * @problem.severity warning
 */

import java
import semmle.code.java.dataflow.FlowSources
import semmle.code.java.security.QueryInjection
import DataFlow::PathGraph

class VulConfig extends TaintTracking::Configuration {
    VulConfig() { this = "SSRFConfig" }

    override predicate isSource(DataFlow::Node src) {
      src instanceof RemoteFlowSource
    }

    override predicate isSink(DataFlow::Node sink) {
      exists(ConstructorCall expr, Constructor cons |
        expr.getConstructor() = cons
        and cons.getDeclaringType().hasQualifiedName("java.net", "URL")
        and sink.asExpr() = expr.getArgument(0)
      )
    }
  }

  from VulConfig config, DataFlow::PathNode source, DataFlow::PathNode sink
  where config.hasFlowPath(source, sink)
  select source.getNode(), source, sink, "source"

image.png