Skip to content

Commit 6386d9d

Browse files
committed
Land rapid7#7178, Add a method to check the Powershell version
2 parents ea0ebf2 + e08c4a8 commit 6386d9d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,31 @@ def have_powershell?
3030
return false
3131
end
3232

33+
#
34+
# Returns the Powershell version
35+
#
36+
def get_powershell_version
37+
return nil unless have_powershell?
38+
39+
process, pid, c = execute_script('$PSVersionTable.PSVersion')
40+
41+
o = ''
42+
43+
while (d = process.channel.read)
44+
if d == ""
45+
if (Time.now.to_i - start < time_out) && (o == '')
46+
sleep 0.1
47+
else
48+
break
49+
end
50+
else
51+
o << d
52+
end
53+
end
54+
55+
o.scan(/[\d \-]+/).last.split[0,2] * '.'
56+
end
57+
3358
#
3459
# Get/compare list of current PS processes - nested execution can spawn many children
3560
# doing checks before and after execution allows us to kill more children...

0 commit comments

Comments
 (0)