Skip to content

Commit 3ea3d95

Browse files
committed
Add methods to check .Net and Powershell versions
1 parent 14a387e commit 3ea3d95

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

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

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

33+
#
34+
# Returns the .Net version
35+
#
36+
def get_dotnet_version
37+
cmd_out = cmd_exec('wmic /namespace:\\\\root\\cimv2 path win32_product where "name like \'%%.NET%%\'" get version')
38+
cmd_out.scan(/[\d\.]+/).flatten.first || ''
39+
end
40+
41+
42+
#
43+
# Returns the Powershell version
44+
#
45+
def get_powershell_version
46+
return nil unless have_powershell?
47+
48+
process, pid, c = execute_script('$PSVersionTable.PSVersion')
49+
50+
o = ''
51+
52+
while (d = process.channel.read)
53+
if d == ""
54+
if (Time.now.to_i - start < time_out) && (o == '')
55+
sleep 0.1
56+
else
57+
break
58+
end
59+
else
60+
o << d
61+
end
62+
end
63+
64+
o
65+
66+
o.scan(/[\d \-]+/).last.split[0,2] * '.'
67+
end
68+
3369
#
3470
# Get/compare list of current PS processes - nested execution can spawn many children
3571
# doing checks before and after execution allows us to kill more children...

0 commit comments

Comments
 (0)