Skip to content

Commit 3851db7

Browse files
committed
Use powershell when possible
1 parent 766c0cc commit 3851db7

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,31 @@ def have_powershell?
3636
def get_dotnet_version
3737
case sysinfo['OS']
3838
when /Windows 8|10/
39-
cmd_out = cmd_exec('wmic /namespace:\\\\root\\cimv2 path win32_optionalfeature where "caption like \'.NET Framework%\' and InstallState = 1" get caption')
39+
cmd = 'wmic /namespace:\\\\root\\cimv2 path win32_optionalfeature where "caption like \'.NET Framework%\' and InstallState = 1" get caption'
4040
else
41-
cmd_out = cmd_exec('wmic /namespace:\\\\root\\cimv2 path win32_product where "name like \'%%.NET%%\'" get version')
41+
cmd = 'wmic /namespace:\\\\root\\cimv2 path win32_product where "name like \'%%.NET%%\'" get version'
42+
end
43+
44+
if have_powershell?
45+
process, pid, c = execute_script(cmd)
46+
cmd_out = ''
47+
while (d = process.channel.read)
48+
if d == ""
49+
if (Time.now.to_i - start < time_out) && (cmd_out == '')
50+
sleep 0.1
51+
else
52+
break
53+
end
54+
else
55+
cmd_out << d
56+
end
57+
end
58+
else
59+
begin
60+
cmd_out = cmd_exec(cmd)
61+
rescue Rex::TimeoutError
62+
return nil
63+
end
4264
end
4365

4466
cmd_out.scan(/(\d\.[\d\.]+)/).flatten.first

0 commit comments

Comments
 (0)