Skip to content

hypnguyen1209/offensive-claude / skills/vulnerability-analysis

vulnerability-analysis

Unverified

Use when auditing source code for vulnerabilities — drive CodeQL/Semgrep/Joern to taint untrusted data source-to-sink across injection, memory safety, deserialization/prototype-pollution, secrets/crypto/authz/race, and supply-chain risks

scripts/joern_taint.sc

View on GitHub
// joern_taint.sc - CPGQL interprocedural taint queries for source->sink hunting.
//
// Joern builds a Code Property Graph (AST + CFG + PDG) and ships a reachableBy
// dataflow engine. This script defines source/sink/sanitizer sets and reports
// every flow where attacker-controlled data reaches a dangerous sink.
//
// Run via sast_runner.py:
//   python3 sast_runner.py joern --src ./app --script joern_taint.sc --out joern.json
// Or directly:
//   joern --script joern_taint.sc --param cpgPath=cpg.bin --param outPath=joern.json
//
// Works language-agnostically on the CPG; method-name patterns below cover
// C/C++, Java, Python, JS. Extend `sinks`/`sources` for your target.
//
// Reference: https://docs.joern.io/code-property-graph/  ;  reachableBy dataflow.

@main def run(cpgPath: String = "cpg.bin", outPath: String = "joern.json") = {
  importCpg(cpgPath)

  // ---- Source set: parameters/calls that introduce untrusted data ----
  def sources = cpg.call.name(
    "getParameter|getHeader|getQueryString" +     // Java servlet
    "|recv|read|fgets|fread|scanf|gets" +          // C/C++ I/O
    "|getenv" +                                    // env
    "|loads|get_json"                              // python-ish
  ).argument ++ cpg.method.parameter.name("argv|args|query|body|params|request|req")

  // ---- Sink set keyed by CWE for reporting ----
  val sinkSpecs = Map(
    "CWE-78"  -> "system|popen|exec|execve|execvp|ProcessBuilder|Runtime",
    "CWE-89"  -> "execute|executeQuery|createQuery|createNativeQuery|mysqli_query|query",
    "CWE-94"  -> "eval|compile|Function|create_function|assert",
    "CWE-502" -> "readObject|unserialize|pickle.loads|XMLDecoder|deserialize",
    "CWE-787" -> "memcpy|strcpy|strcat|sprintf|gets|memmove",   // buffer write
    "CWE-22"  -> "fopen|open|readfile|sendFile|include|require",
    "CWE-918" -> "urlopen|HttpClient|RestTemplate|curl_exec|fetch"
  )

  // ---- Sanitizers: flows passing through these are downgraded, not dropped ----
  def sanitizers = cpg.call.name(
    "escapeshellarg|htmlspecialchars|parseInt|Integer.parseInt|prepareStatement" +
    "|shlex.quote|html.escape|realpath|basename|normalize|filter_var"
  )

  case class Finding(cwe: String, sink: String, file: String, line: Int,
                     srcMethod: String, message: String)

  val findings = scala.collection.mutable.ArrayBuffer[Finding]()

  for ((cwe, pat) <- sinkSpecs) {
    val sinkCalls = cpg.call.name(pat)
    val sinkArgs  = sinkCalls.argument
    // reachableBy = is there a PDG path from a source into this sink argument?
    val flows = sinkArgs.reachableBy(sources).l
    flows.foreach { node =>
      val callOpt = node.inAst.isCall.name(pat).headOption
      callOpt.foreach { c =>
        // Path-level sanitizer check: did the flow cross a sanitizer call?
        val passed = c.argument.reachableByFlows(sanitizers).nonEmpty
        if (!passed) {
          findings += Finding(
            cwe, c.name,
            c.file.name.headOption.getOrElse("?"),
            c.lineNumber.getOrElse(0),
            c.method.fullName,
            s"untrusted data reaches ${c.name} (${cwe}) without sanitizer"
          )
        }
      }
    }
  }

  // De-dupe and serialize to JSON for sast_runner merge.
  val unique = findings.distinct
  val json = unique.map { f =>
    s"""  {"tool":"joern","cwe":"${f.cwe}","rule":"${f.cwe}","severity":"error",""" +
    s""""file":"${f.file.replace("\\","/")}","line":${f.line},""" +
    s""""message":"${f.message}"}"""
  }.mkString("[\n", ",\n", "\n]")

  java.nio.file.Files.write(java.nio.file.Paths.get(outPath), json.getBytes)
  println(s"[+] ${unique.size} taint flows -> ${outPath}")
}
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall