Skip to content

Commit ce35618

Browse files
committed
fixed tests, comments were put on wrong line ty copilot
1 parent b3626db commit ce35618

3 files changed

Lines changed: 33 additions & 33 deletions

File tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
function MyFunction[1] # $ Alert Alert
2-
{...}
1+
function MyFunction[1]
2+
{...} # $ Alert Alert

powershell/ql/test/query-tests/security/cwe-022/test.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@ Add-Type -AssemblyName System.IO.Compression.FileSystem
33
$zip = [System.IO.Compression.ZipFile]::OpenRead("MyPath\to\archive.zip")
44

55
foreach ($entry in $zip.Entries) {
6-
$targetPath = Join-Path $extractPath $entry.FullName # $ Source
6+
$targetPath = Join-Path $extractPath $entry.FullName # $ Alert
77
$fullTargetPath = [System.IO.Path]::GetFullPath($targetPath)
88

9-
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $fullTargetPath) # $ Alert
9+
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $fullTargetPath) # $ Sink
1010
}
1111

1212
foreach ($entry in $zip.Entries) {
13-
$targetPath = Join-Path $extractPath $entry.FullName # $ Source
13+
$targetPath = Join-Path $extractPath $entry.FullName # $ Alert
1414
$fullTargetPath = [System.IO.Path]::GetFullPath($targetPath)
1515

16-
$stream = [System.IO.File]::Open($fullTargetPath, 'Create') # $ Alert
16+
$stream = [System.IO.File]::Open($fullTargetPath, 'Create') # $ Sink
1717
$entry.Open().CopyTo($stream)
1818
$stream.Close()
1919
}
2020

2121
foreach ($entry in $zip.Entries) {
22-
$targetPath = Join-Path $extractPath $entry.FullName # $ Source
22+
$targetPath = Join-Path $extractPath $entry.FullName # $ Alert
2323
$fullTargetPath = [System.IO.Path]::GetFullPath($targetPath)
2424

2525
$extractRoot = [System.IO.Path]::GetFullPath($extractPath)
2626
if ($fullTargetPath.StartsWith($extractRoot)) {
27-
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $fullTargetPath) # $ Alert
27+
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $fullTargetPath) # $ Sink
2828
}
2929
}

powershell/ql/test/query-tests/security/cwe-078/CommandInjection/test.ps1

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
11
function Invoke-InvokeExpressionInjection1
22
{
33
param($UserInput)
4-
Invoke-Expression "Get-Process -Name $UserInput" # BAD
4+
Invoke-Expression "Get-Process -Name $UserInput" # $ Alert
55
}
66

77
function Invoke-InvokeExpressionInjection2
88
{
99
param($UserInput)
10-
iex "Get-Process -Name $UserInput" # BAD
10+
iex "Get-Process -Name $UserInput" # $ Alert
1111
}
1212

1313
function Invoke-InvokeExpressionInjection3
1414
{
1515
param($UserInput)
16-
$executionContext.InvokeCommand.InvokeScript("Get-Process -Name $UserInput") # BAD
16+
$executionContext.InvokeCommand.InvokeScript("Get-Process -Name $UserInput") # $ Alert
1717
}
1818

1919
function Invoke-InvokeExpressionInjection4
2020
{
2121
param($UserInput)
22-
$host.Runspace.CreateNestedPipeline("Get-Process -Name $UserInput", $false).Invoke() # BAD
22+
$host.Runspace.CreateNestedPipeline("Get-Process -Name $UserInput", $false).Invoke() # $ Alert
2323
}
2424

2525
function Invoke-InvokeExpressionInjection5
2626
{
2727
param($UserInput)
28-
[PowerShell]::Create().AddScript("Get-Process -Name $UserInput").Invoke() # BAD
28+
[PowerShell]::Create().AddScript("Get-Process -Name $UserInput").Invoke() # $ Alert
2929
}
3030

3131
function Invoke-InvokeExpressionInjection6
3232
{
3333
param($UserInput)
34-
Add-Type "public class Foo { $UserInput }" # BAD
34+
Add-Type "public class Foo { $UserInput }" # $ Alert
3535
}
3636

3737
function Invoke-InvokeExpressionInjection7
3838
{
3939
param($UserInput)
40-
Add-Type -TypeDefinition "public class Foo { $UserInput }" # BAD
40+
Add-Type -TypeDefinition "public class Foo { $UserInput }" # $ Alert
4141
}
4242

4343
function Invoke-InvokeExpressionInjection8
4444
{
4545
param($UserInput)
4646

4747
$code = "public class Foo { $UserInput }"
48-
Add-Type -TypeDefinition $code # BAD
48+
Add-Type -TypeDefinition $code # $ Alert
4949
}
5050

5151
function Invoke-InvokeExpressionInjectionFP
@@ -72,21 +72,21 @@ function Invoke-ExploitableCommandInjection1
7272
{
7373
param($UserInput)
7474

75-
powershell -command "Get-Process -Name $UserInput" # BAD
75+
powershell -command "Get-Process -Name $UserInput" # $ Alert
7676
}
7777

7878
function Invoke-ExploitableCommandInjection2
7979
{
8080
param($UserInput)
8181

82-
powershell "Get-Process -Name $UserInput" # BAD
82+
powershell "Get-Process -Name $UserInput" # $ Alert
8383
}
8484

8585
function Invoke-ExploitableCommandInjection3
8686
{
8787
param($UserInput)
8888

89-
cmd /c "ping $UserInput" # BAD
89+
cmd /c "ping $UserInput" # $ Alert
9090
}
9191

9292
function Invoke-ScriptBlockInjection1
@@ -95,7 +95,7 @@ function Invoke-ScriptBlockInjection1
9595

9696
## Often used when making remote connections
9797

98-
$sb = [ScriptBlock]::Create("Get-Process -Name $UserInput") # BAD
98+
$sb = [ScriptBlock]::Create("Get-Process -Name $UserInput") # $ Alert
9999
Invoke-Command RemoteServer $sb
100100
}
101101

@@ -105,63 +105,63 @@ function Invoke-ScriptBlockInjection2
105105

106106
## Often used when making remote connections
107107

108-
$sb = $executionContext.InvokeCommand.NewScriptBlock("Get-Process -Name $UserInput") # BAD
108+
$sb = $executionContext.InvokeCommand.NewScriptBlock("Get-Process -Name $UserInput") # $ Alert
109109
Invoke-Command RemoteServer $sb
110110
}
111111

112112
function Invoke-MethodInjection1
113113
{
114114
param($UserInput)
115115

116-
Get-Process | Foreach-Object $UserInput # BAD
116+
Get-Process | Foreach-Object $UserInput # $ Alert
117117
}
118118

119119
function Invoke-MethodInjection2
120120
{
121121
param($UserInput)
122122

123-
(Get-Process -Id $pid).$UserInput() # BAD
123+
(Get-Process -Id $pid).$UserInput() # $ Alert
124124
}
125125

126126

127127
function Invoke-MethodInjection3
128128
{
129129
param($UserInput)
130130

131-
(Get-Process -Id $pid).$UserInput.Invoke() # BAD
131+
(Get-Process -Id $pid).$UserInput.Invoke() # $ Alert
132132
}
133133

134134
function Invoke-ExpandStringInjection1
135135
{
136136
param($UserInput)
137137

138138
## Used to attempt a variable resolution
139-
$executionContext.InvokeCommand.ExpandString($UserInput) # BAD
139+
$executionContext.InvokeCommand.ExpandString($UserInput) # $ Alert
140140
}
141141

142142
function Invoke-ExpandStringInjection2
143143
{
144144
param($UserInput)
145145

146146
## Used to attempt a variable resolution
147-
$executionContext.SessionState.InvokeCommand.ExpandString($UserInput) # BAD
147+
$executionContext.SessionState.InvokeCommand.ExpandString($UserInput) # $ Alert
148148
}
149149

150150
function Invoke-InvokeExpressionInjectionCmdletBinding
151151
{
152152
[CmdletBinding()]
153153
param($UserInput)
154-
Invoke-Expression "Get-Process -Name $UserInput" # BAD
154+
Invoke-Expression "Get-Process -Name $UserInput" # $ Alert
155155
}
156156

157157
function Invoke-StartProcessInjection
158158
{
159159
param($UserInput)
160-
Start-Process -FilePath $UserInput # BAD
160+
Start-Process -FilePath $UserInput # $ Alert
161161
}
162162

163163

164-
$input = Read-Host "enter input"
164+
$input = Read-Host "enter input" # $ Source
165165

166166
Invoke-InvokeExpressionInjection1 -UserInput $input
167167
Invoke-InvokeExpressionInjection2 -UserInput $input
@@ -251,20 +251,20 @@ Invoke-InvokeExpressionInjectionSafe5 -UserInput $input
251251

252252
function false-positive-in-call-operator($d)
253253
{
254-
$o = Read-Host "enter input"
254+
$o = Read-Host "enter input" # $ Source
255255
& unzip -o "$o" -d $d # GOOD
256256

257-
. "$o" # BAD
257+
. "$o" # $ Alert
258258
}
259259

260260
function flow-through-env-var() {
261261
$x = $env:foo
262262

263263
. "$x" # GOOD # we don't consider environment vars flow sources
264264

265-
$input = Read-Host "enter input"
265+
$input = Read-Host "enter input" # $ Source
266266
$env:bar = $input
267267

268268
$y = $env:bar
269-
. "$y" # BAD # but we have flow through them
269+
. "$y" # $ Alert # but we have flow through them
270270
}

0 commit comments

Comments
 (0)