This repository has been archived by the owner on Oct 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from joernio/claudiu/ghidra-env
Add getenvToStrcpy ghidra query
- Loading branch information
Showing
8 changed files
with
113 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
|
||
// gcc -fno-stack-protector -z execstack -no-pie -o buf2 buf2.c | ||
int main(int argc, char *argv[]) { | ||
const char* inEnv = getenv("BUF2IN"); | ||
if (inEnv == NULL) { | ||
printf("BUF2IN environment variable not set."); | ||
return -1; | ||
} | ||
|
||
char c[6]; | ||
strcpy(c, inEnv); | ||
printf("First argument is: %s\n", c); | ||
return 0; | ||
} | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
|
||
// gcc -fno-stack-protector -z execstack -no-pie -o buf2_neg buf2_neg.c | ||
int main(int argc, char *argv[]) { | ||
const char* inEnv = getenv("BUF2IN"); | ||
if (inEnv == NULL) { | ||
printf("BUF2IN environment variable not set."); | ||
return -1; | ||
} | ||
|
||
char c[6]; | ||
strcpy(c, "NOTHING"); | ||
printf("First argument is: %s\n", c); | ||
return 0; | ||
} | ||
|
Binary file not shown.
14 changes: 0 additions & 14 deletions
14
src/test/scala/io/joern/scanners/ghidra/MainArgsToStrcpyTests.scala
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
src/test/scala/io/joern/scanners/ghidra/UserInputIntoDangerousFunctionsTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.joern.scanners.ghidra | ||
|
||
import io.joern.suites.GhidraQueryTestSuite | ||
|
||
class UserInputIntoDangerousFunctionsTests extends GhidraQueryTestSuite { | ||
override def queryBundle = UserInputIntoDangerousFunctions | ||
|
||
"mainArgsToStrcpy query" when { | ||
def query = queryBundle.mainArgsToStrcpy() | ||
"executed on CPG for binary with dataflow between `main` fn args and `strcpy` source argument" should { | ||
"find the `main` function among the tracking points returned" in { | ||
buildCpgForBin("buf1.exe") | ||
val results = methodNamesForMatchedPoints(query) | ||
results shouldBe Set("main") | ||
} | ||
} | ||
} | ||
|
||
"getenvToStrcpy query" when { | ||
def query = queryBundle.getenvToStrcpy() | ||
|
||
"executed on CPG for binary call to `strcpy`, but no call to `getenv`" should { | ||
"return an empty set of matched method names" in { | ||
buildCpgForBin("buf1.exe") | ||
val results = methodNamesForMatchedPoints(query) | ||
results shouldBe Set() | ||
} | ||
} | ||
|
||
"executed on CPG for binary call to `strcpy`, and call to `getenv`, but no dataflow between them" should { | ||
"return an empty set of matched method names" in { | ||
buildCpgForBin("buf2_neg.exe") | ||
val results = methodNamesForMatchedPoints(query) | ||
results shouldBe Set() | ||
} | ||
} | ||
|
||
"executed on CPG for binary with dataflow between `getenv` return value and `strcpy` source argument" should { | ||
"find main function with data flow between getenv and strcpy" in { | ||
buildCpgForBin("buf2.exe") | ||
val results = methodNamesForMatchedPoints(query) | ||
results shouldBe Set("main") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters