This repository was archived by the owner on Apr 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Go local variants #13
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d392df1
Initial Go Local Variants
GeekMasher e933e4a
Add example for Command Injection
GeekMasher e2f345f
Add support for os.Environ
GeekMasher 30d413b
Update docs
GeekMasher 6e2b173
Add query suite
GeekMasher 67be247
Add Go local variants
GeekMasher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,45 @@ | ||
| /** | ||
| * @name Command built from user-controlled sources | ||
| * @description Building a system command from user-controlled sources is vulnerable to insertion of | ||
| * malicious code by the user. | ||
| * @kind path-problem | ||
| * @problem.severity warning | ||
| * @security-severity 4.0 | ||
| * @precision low | ||
| * @id go/command-injection | ||
| * @tags security | ||
| * external/cwe/cwe-078 | ||
| * local | ||
| */ | ||
|
|
||
| import go | ||
| import semmle.go.security.CommandInjection | ||
| import DataFlow::PathGraph | ||
| import semmle.go.security.CommandInjectionCustomizations::CommandInjection | ||
| import github.LocalSources | ||
|
|
||
| class CommandInjectionLocalConfiguration extends TaintTracking::Configuration { | ||
| CommandInjectionLocalConfiguration() { this = "CommandInjection" } | ||
|
|
||
| // Local sources of input | ||
| override predicate isSource(DataFlow::Node source) { source instanceof LocalSources::Sources } | ||
|
|
||
| override predicate isSink(DataFlow::Node sink) { | ||
| exists(Sink s | sink = s | not s.doubleDashIsSanitizing()) | ||
| } | ||
|
|
||
| override predicate isSanitizer(DataFlow::Node node) { | ||
| super.isSanitizer(node) or | ||
| node instanceof Sanitizer | ||
| } | ||
|
|
||
| override predicate isSanitizerGuard(DataFlow::BarrierGuard guard) { | ||
| guard instanceof SanitizerGuard | ||
| } | ||
| } | ||
|
|
||
| // TODO: DoubleDashSanitizingConfiguration? | ||
| from CommandInjectionLocalConfiguration cfg, DataFlow::PathNode source, DataFlow::PathNode sink | ||
| where cfg.hasFlowPath(source, sink) | ||
| select sink.getNode(), source, sink, "This command depends on $@.", source.getNode(), | ||
| "a user-provided value" |
This file contains hidden or 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,32 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "flag" | ||
| "fmt" | ||
| "log" | ||
| "os" | ||
| "os/exec" | ||
| ) | ||
|
|
||
| func runPing(ip *string) { | ||
| cmdString := fmt.Sprintf("ping %v", *ip) | ||
| fmt.Printf("Command :: %s\n", cmdString) | ||
| cmd := exec.Command(cmdString) | ||
| err := cmd.Run() | ||
| if err != nil { | ||
| log.Fatal(err) | ||
| } | ||
| } | ||
|
|
||
| func main() { | ||
| ip := flag.String("ip", "8.8.8.8", "IP Address to contact") | ||
| flag.Parse() | ||
|
|
||
| log.Printf(" Flag >> %s\n", *ip) | ||
| runPing(ip) | ||
|
|
||
| ip2 := os.Args[0] | ||
| log.Printf(" Argv >> %s", ip2) | ||
| runPing(&ip2) | ||
|
|
||
| } |
This file contains hidden or 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,27 @@ | ||
| import go | ||
|
|
||
| // ========== Sources ========== | ||
| module LocalSources { | ||
| abstract class Sources extends DataFlow::Node { } | ||
|
|
||
| // https://pkg.go.dev/os#Args | ||
| // class OsArgs extends Sources { | ||
| // OsArgs() { | ||
| // exists(ValueEntity value | value.hasQualifiedName(package("os", ""), "Args") and this = value) | ||
| // } | ||
| // } | ||
| class OsGetenv extends Sources, DataFlow::CallNode { | ||
| OsGetenv() { | ||
| // https://pkg.go.dev/os#Getenv | ||
| this.getTarget().hasQualifiedName(package("os", ""), "Getenv") | ||
| or | ||
| // https://pkg.go.dev/os#Environ | ||
| this.getTarget().hasQualifiedName(package("os", ""), "Environ") | ||
| } | ||
| } | ||
|
|
||
| // https://pkg.go.dev/flag | ||
| class Flag extends Sources, DataFlow::CallNode { | ||
| Flag() { this.getTarget().hasQualifiedName(package("flag", ""), "String") } | ||
| } | ||
| } | ||
This file contains hidden or 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,11 @@ | ||
| # See https://help.semmle.com/codeql/codeql-cli/procedures/query-suites.html#filtering-the-queries-in-a-query-suite | ||
| # for additional ways to exclude queries | ||
|
|
||
| - description: "GitHub's Field Team CodeQL GoLang extended Suite" | ||
|
|
||
| - qlpack: github-queries-go | ||
| - include: | ||
| tags contain: local | ||
|
|
||
| - import: codeql-suites/go-security-extended.qls | ||
| from: codeql-go |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to support os.Args as this is the main use case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@securingdev Can you help fix this issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to take a crack at it @GeekMasher - can we connect at some point tomorrow so that I know what you're looking for (and why this section of code was in, and then commented out)?