forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 20
invoke expression powershell query #154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
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
16 changes: 16 additions & 0 deletions
16
powershell/ql/src/queries/security/cwe-078/DoNotUseInvokeExpression.ql
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,16 @@ | ||
| /** | ||
| * @name Use of Invoke-Expression | ||
| * @description Do not use Invoke-Expression | ||
| * @kind problem | ||
| * @problem.severity error | ||
| * @security-severity 9.8 | ||
| * @precision high | ||
| * @id powershell/do-not-use-invoke-expression | ||
| * @tags security | ||
| */ | ||
| import powershell | ||
| import semmle.code.powershell.dataflow.DataFlow | ||
|
|
||
| from CmdCall call | ||
| where call.getName() = "Invoke-Expression" | ||
| select call, "Do not use Invoke-Expression. It is a command injection risk." |
33 changes: 33 additions & 0 deletions
33
powershell/ql/src/queries/security/cwe-078/DoNotuseInvokeExpression.qhelp
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,33 @@ | ||
| <!DOCTYPE qhelp PUBLIC | ||
| "-//Semmle//qhelp//EN" | ||
| "qhelp.dtd"> | ||
| <qhelp> | ||
| <overview> | ||
| <p> | ||
| <code>Invoke-Expression</code> cmdlet should only be used as a last resort. In most scenarios, safer and more robust alternatives are available. Using Invoke-Expression can lead to arbitrary commands being executed</p> | ||
|
|
||
| </overview> | ||
| <recommendation> | ||
|
|
||
| <p>Avoid using Invoke-Expression in your powershell code.</p> | ||
chanel-y marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| <p>If you’re running some command and the command path has spaces in it, then you need the command invocation operator <code>&</code></p> | ||
| </recommendation> | ||
|
|
||
| <references> | ||
|
|
||
| <li> | ||
| Powershell: | ||
| <a href="https://devblogs.microsoft.com/powershell/invoke-expression-considered-harmful/">Invoke-Expression considered harmful</a>. | ||
| </li> | ||
| <li> | ||
| PSScriptAnalyzer: | ||
| <a href="https://learn.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/rules/avoidusinginvokeexpression?view=ps-modules">AvoidUsingInvokeExpression</a> | ||
| </li> | ||
| <li> | ||
| StackOverflow: | ||
| <a href="https://stackoverflow.com/questions/51252465/in-what-scenario-was-invoke-expression-designed-to-be-used/51252636#51252636">In what scenario was Invoke-Expression designed to be used?</a> | ||
| </li> | ||
|
|
||
| </references> | ||
| </qhelp> | ||
1 change: 1 addition & 0 deletions
1
...t/query-tests/security/cwe-078/DoNotUseInvokeExpression/DoNotUseInvokeExpression.expected
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 @@ | ||
| | test.ps1:2:1:2:27 | call to Invoke-Expression | Do not use Invoke-Expression. It is a command injection risk. | |
1 change: 1 addition & 0 deletions
1
...test/query-tests/security/cwe-078/DoNotUseInvokeExpression/DoNotUseInvokeExpression.qlref
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 @@ | ||
| queries/security/cwe-078/DoNotUseInvokeExpression.ql |
2 changes: 2 additions & 0 deletions
2
powershell/ql/test/query-tests/security/cwe-078/DoNotUseInvokeExpression/test.ps1
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,2 @@ | ||
| $command = "Get-Process" | ||
| Invoke-Expression $Command |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.