Skip to content
This repository has been archived by the owner on Oct 27, 2021. It is now read-only.

Commit

Permalink
Initial SQL injection for springframework
Browse files Browse the repository at this point in the history
  • Loading branch information
Niko committed Apr 12, 2021
1 parent 5362d06 commit e29736e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/scala/io/joern/scanners/QueryTags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ object QueryTags {

val integers = "integers"
val strings = "strings"

val sqlInjection = "SQL injection"
val sqli = "SQLi"
}
43 changes: 43 additions & 0 deletions src/main/scala/io/joern/scanners/java/SQLInjection.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.joern.scanners.java;

import io.joern.scanners._
import io.shiftleft.semanticcpg.language._
import io.shiftleft.console._
import io.shiftleft.macros.QueryMacros._
import io.shiftleft.dataflowengineoss.language._
import io.shiftleft.dataflowengineoss.queryengine.EngineContext

// The queries are tied to springframework
object SQLInjection extends QueryBundle {

implicit val resolver: ICallResolver = NoResolve

@q
def sqlInjection()(implicit context: EngineContext): Query =
Query.make(
name = "SQL injection",
author = Crew.niko,
title =
"SQL injection: A parameter is used in an insecure database API call.",
description =
"""
|An attacker controlled parameter is used in an insecure database API call.
|
|If the parameter is not validated and sanitized, this is a SQL injection.
|""".stripMargin,
score = 5,
withStrRep({ cpg =>
def source =
cpg.method
.where(_.methodReturn.evalType(
"org.springframework.web.servlet.ModelAndView"))
.parameter

def sinks = cpg.method.name("query").parameter.order(1)

// sinks where the first argument is reachable by a source
sinks.reachableBy(source).l
}),
tags = List(QueryTags.sqli, QueryTags.sqlInjection)
)
}

0 comments on commit e29736e

Please sign in to comment.