11function Invoke-InvokeExpressionInjection1
22{
33 param ($UserInput )
4- Invoke-Expression " Get-Process -Name $UserInput "
4+ Invoke-Expression " Get-Process -Name $UserInput " # BAD
55}
66
77function Invoke-InvokeExpressionInjection2
88{
99 param ($UserInput )
10- iex " Get-Process -Name $UserInput "
10+ iex " Get-Process -Name $UserInput " # BAD
1111}
1212
1313function Invoke-InvokeExpressionInjection3
1414{
1515 param ($UserInput )
16- $executionContext.InvokeCommand.InvokeScript (" Get-Process -Name $UserInput " )
16+ $executionContext.InvokeCommand.InvokeScript (" Get-Process -Name $UserInput " ) # BAD
1717}
1818
1919function Invoke-InvokeExpressionInjection4
2020{
2121 param ($UserInput )
22- $host.Runspace.CreateNestedPipeline (" Get-Process -Name $UserInput " , $false ).Invoke()
22+ $host.Runspace.CreateNestedPipeline (" Get-Process -Name $UserInput " , $false ).Invoke() # BAD
2323}
2424
2525function Invoke-InvokeExpressionInjection5
2626{
2727 param ($UserInput )
28- [PowerShell ]::Create().AddScript(" Get-Process -Name $UserInput " ).Invoke()
28+ [PowerShell ]::Create().AddScript(" Get-Process -Name $UserInput " ).Invoke() # BAD
2929}
3030
3131function Invoke-InvokeExpressionInjection6
3232{
3333 param ($UserInput )
34- Add-Type " public class Foo { $UserInput }"
34+ Add-Type " public class Foo { $UserInput }" # BAD
3535}
3636
3737function Invoke-InvokeExpressionInjection7
3838{
3939 param ($UserInput )
40- Add-Type - TypeDefinition " public class Foo { $UserInput }"
40+ Add-Type - TypeDefinition " public class Foo { $UserInput }" # BAD
4141}
4242
4343function Invoke-InvokeExpressionInjection8
4444{
4545 param ($UserInput )
4646
4747 $code = " public class Foo { $UserInput }"
48- Add-Type - TypeDefinition $code
48+ Add-Type - TypeDefinition $code # BAD
4949}
5050
5151function Invoke-InvokeExpressionInjectionFP
@@ -72,21 +72,21 @@ function Invoke-ExploitableCommandInjection1
7272{
7373 param ($UserInput )
7474
75- powershell - command " Get-Process -Name $UserInput "
75+ powershell - command " Get-Process -Name $UserInput " # BAD
7676}
7777
7878function Invoke-ExploitableCommandInjection2
7979{
8080 param ($UserInput )
8181
82- powershell " Get-Process -Name $UserInput "
82+ powershell " Get-Process -Name $UserInput " # BAD
8383}
8484
8585function Invoke-ExploitableCommandInjection3
8686{
8787 param ($UserInput )
8888
89- cmd / c " ping $UserInput "
89+ cmd / c " ping $UserInput " # BAD
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 " )
98+ $sb = [ScriptBlock ]::Create(" Get-Process -Name $UserInput " ) # BAD
9999 Invoke-Command RemoteServer $sb
100100}
101101
@@ -105,22 +105,22 @@ function Invoke-ScriptBlockInjection2
105105
106106 # # Often used when making remote connections
107107
108- $sb = $executionContext.InvokeCommand.NewScriptBlock (" Get-Process -Name $UserInput " )
108+ $sb = $executionContext.InvokeCommand.NewScriptBlock (" Get-Process -Name $UserInput " ) # BAD
109109 Invoke-Command RemoteServer $sb
110110}
111111
112112function Invoke-MethodInjection1
113113{
114114 param ($UserInput )
115115
116- Get-Process | Foreach-Object $UserInput
116+ Get-Process | Foreach-Object $UserInput # BAD
117117}
118118
119119function Invoke-MethodInjection2
120120{
121121 param ($UserInput )
122122
123- (Get-Process - Id $pid ).$UserInput ()
123+ (Get-Process - Id $pid ).$UserInput () # BAD
124124}
125125
126126
@@ -136,15 +136,15 @@ function Invoke-ExpandStringInjection1
136136 param ($UserInput )
137137
138138 # # Used to attempt a variable resolution
139- $executionContext.InvokeCommand.ExpandString ($UserInput )
139+ $executionContext.InvokeCommand.ExpandString ($UserInput ) # BAD
140140}
141141
142142function Invoke-ExpandStringInjection2
143143{
144144 param ($UserInput )
145145
146146 # # Used to attempt a variable resolution
147- $executionContext.SessionState.InvokeCommand.ExpandString ($UserInput )
147+ $executionContext.SessionState.InvokeCommand.ExpandString ($UserInput ) # BAD
148148}
149149
150150
0 commit comments