Skip to content

Commit

Permalink
add tests for sql injection
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxMilshin committed Jun 11, 2024
1 parent 6b1cacc commit c745b6a
Show file tree
Hide file tree
Showing 7 changed files with 5,697 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,7 @@ fun PandaValue.toPathOrNull(): AccessPath? = when (this) {
}
}

is PandaLoadedValue -> {
when (className) {
"console" -> instance.toPathOrNull()
else -> TODO("Not implemented yet")
}
}
is PandaLoadedValue -> instance.toPathOrNull()

else -> null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,11 @@ class IRParser(
handle(todoExpr)
}

"Intrinsic.getmodulenamespace" -> {
val todoExpr = TODOExpr(opcode, inputs) // TODO
handle(todoExpr)
}

"Intrinsic.asyncfunctionenter" -> {
val todoExpr = TODOExpr(opcode, inputs) // TODO
handle(todoExpr)
Expand Down
45 changes: 40 additions & 5 deletions jacodb-panda-dynamic/src/test/kotlin/analysis/TaintSamples.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ import org.jacodb.panda.taint.UntrustedLoopBoundSinkCheck
import org.jacodb.panda.taint.UntrustedArraySizeSinkCheck
import org.jacodb.panda.taint.UntrustedIndexArrayAccessSinkCheck


private val logger = mu.KotlinLogging.logger {}

class TaintSamples {
private fun loadProjectForSample(programName: String): PandaProject {
val parser = loadIr("/samples/${programName}.json")
Expand Down Expand Up @@ -248,11 +245,15 @@ class TaintSamples {

@Nested
inner class SQLInjectionTest {
private val project: PandaProject = loadProjectForSample("taintSamples/SQLInjection")
private val fileTaintAnalyzer = TaintAnalyzer(project)
private fun getTaintAnalyserByProgramName(programName: String = "taintSamples/SQLInjection"): TaintAnalyzer {
val project: PandaProject = loadProjectForSample(programName)
val fileTaintAnalyzer = TaintAnalyzer(project)
return fileTaintAnalyzer
}

@Test
fun `counterexample - sql injection that lead to dropping table`() {
val fileTaintAnalyzer = getTaintAnalyserByProgramName()
val sinkResults = fileTaintAnalyzer.analyseOneCase(
CaseTaintConfig(
sourceMethodConfigs = listOf(SourceMethodConfig("getUserName")),
Expand All @@ -265,6 +266,40 @@ class TaintSamples {
)
assert(sinkResults.size == 1)
}

@Test
fun `counterexample - more realistic sql injection`() {
val fileTaintAnalyzer = getTaintAnalyserByProgramName("taintSamples/SQLInjection2")
val sinkResults = fileTaintAnalyzer.analyseOneCase(
CaseTaintConfig(
sourceMethodConfigs = listOf(SourceMethodConfig("getUser")),
sinkMethodConfigs = listOf(
SinkMethodConfig(
methodName = "query",
position = Argument(1)
)
),
)
)
assert(sinkResults.size == 1)
}

@Test
fun `counterexample - most production-like sql injection`() {
val fileTaintAnalyzer = getTaintAnalyserByProgramName("taintSamples/SQLInjection3")
val sinkResults = fileTaintAnalyzer.analyseOneCase(
CaseTaintConfig(
sourceMethodConfigs = listOf(SourceMethodConfig("getUser")),
sinkMethodConfigs = listOf(
SinkMethodConfig(
methodName = "query",
position = Argument(1)
)
),
)
)
assert(sinkResults.size == 1)
}
}

@Nested
Expand Down
Loading

0 comments on commit c745b6a

Please sign in to comment.