11function Invoke-InvokeExpressionInjection1
22{
33 param ($UserInput )
4- Invoke-Expression " Get-Process -Name $UserInput " # BAD
4+ Invoke-Expression " Get-Process -Name $UserInput " # $ Alert
55}
66
77function Invoke-InvokeExpressionInjection2
88{
99 param ($UserInput )
10- iex " Get-Process -Name $UserInput " # BAD
10+ iex " Get-Process -Name $UserInput " # $ Alert
1111}
1212
1313function 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
1919function 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
2525function 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
3131function Invoke-InvokeExpressionInjection6
3232{
3333 param ($UserInput )
34- Add-Type " public class Foo { $UserInput }" # BAD
34+ Add-Type " public class Foo { $UserInput }" # $ Alert
3535}
3636
3737function 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
4343function 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
5151function 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
7878function Invoke-ExploitableCommandInjection2
7979{
8080 param ($UserInput )
8181
82- powershell " Get-Process -Name $UserInput " # BAD
82+ powershell " Get-Process -Name $UserInput " # $ Alert
8383}
8484
8585function Invoke-ExploitableCommandInjection3
8686{
8787 param ($UserInput )
8888
89- cmd / c " ping $UserInput " # BAD
89+ cmd / c " ping $UserInput " # $ Alert
9090}
9191
9292function 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
112112function Invoke-MethodInjection1
113113{
114114 param ($UserInput )
115115
116- Get-Process | Foreach-Object $UserInput # BAD
116+ Get-Process | Foreach-Object $UserInput # $ Alert
117117}
118118
119119function Invoke-MethodInjection2
120120{
121121 param ($UserInput )
122122
123- (Get-Process - Id $pid ).$UserInput () # BAD
123+ (Get-Process - Id $pid ).$UserInput () # $ Alert
124124}
125125
126126
127127function 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
134134function 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
142142function 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
150150function 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
157157function 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
166166Invoke-InvokeExpressionInjection1 - UserInput $input
167167Invoke-InvokeExpressionInjection2 - UserInput $input
@@ -251,20 +251,20 @@ Invoke-InvokeExpressionInjectionSafe5 -UserInput $input
251251
252252function 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
260260function 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