Skip to content

Commit 76b9273

Browse files
committed
Improve reliability of have_powershell
I have a case where on a Windows 2008 R2 host with PowerShell 2.0 the 'have_powershell' method times out. When I interactively run the command I find that the output stops after the PowerShell command and the token from 'cmd_exec' is NOT displayed. When I hit return the shell then processes the '&echo <randomstring>' and generates the token that 'cmd_exec' was looking for. I tried various versions of the PowerShell command string such as 'Get-Host;Exit(0)', '$PSVErsionTable.PSVersion', and '-Command Get-Host' but was unable to change the behavior. I found that adding 'echo. | ' simulated pressing enter and did not disrupt the results on this host or on another host where the 'have_powershell' method functioned as expected. There may be a better solution, but this was the only one that I could find.
1 parent dc7ec45 commit 76b9273

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/msf/core/post/windows/powershell.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module Powershell
1919
# Returns true if powershell is installed
2020
#
2121
def have_powershell?
22-
cmd_out = cmd_exec("powershell get-host")
22+
cmd_out = cmd_exec("echo. | powershell get-host")
2323
return true if cmd_out =~ /Name.*Version.*InstanceID/
2424
return false
2525
end

0 commit comments

Comments
 (0)