|
| 1 | +# -*- coding: binary -*- |
| 2 | +require 'msf/core/post/common' |
| 3 | +require 'msf/core/post/windows/registry' |
| 4 | + |
| 5 | +module Msf |
| 6 | +class Post |
| 7 | +module Windows |
| 8 | + |
| 9 | +module Dotnet |
| 10 | + include ::Msf::Post::Common |
| 11 | + include ::Msf::Post::Windows::Registry |
| 12 | + |
| 13 | + def initialize(info = {}) |
| 14 | + super |
| 15 | + register_advanced_options( |
| 16 | + [ |
| 17 | + OptInt.new('Dotnet::Post::timeout', [true, 'Dotnet execution timeout, set < 0 to run async without termination', 15]), |
| 18 | + OptBool.new('Dotnet::Post::log_output', [true, 'Write output to log file', false]), |
| 19 | + OptBool.new('Dotnet::Post::dry_run', [true, 'Return encoded output to caller', false]), |
| 20 | + OptBool.new('Dotnet::Post::force_wow64', [true, 'Force WOW64 execution', false]), |
| 21 | + ], self.class) |
| 22 | + end |
| 23 | + # |
| 24 | + # Searches the subkey for the value 'Version' which contains the |
| 25 | + # actual version, rather than the over-arching release |
| 26 | + # An alternative would be to query for it, and catch the exception. |
| 27 | + # |
| 28 | + def search_for_version(dotnet_subkey) |
| 29 | + dotnet_version = nil |
| 30 | + begin |
| 31 | + subkeys = registry_enumvals(dotnet_subkey) |
| 32 | + rescue::Exception => e |
| 33 | + print_status("Encountered exception in search_for_version: #{e.class} #{e}") |
| 34 | + end |
| 35 | + subkeys.each do |i| |
| 36 | + if i == 'Version' |
| 37 | + dotnet_version = registry_getvaldata(dotnet_subkey, i) |
| 38 | + break |
| 39 | + end |
| 40 | + end |
| 41 | + return dotnet_version |
| 42 | + end |
| 43 | + |
| 44 | + # |
| 45 | + # Bruteforce search all subkeys in an over-arching release to |
| 46 | + # locate the actual release version. |
| 47 | + # |
| 48 | + def get_versionception(dotnet_vkey) |
| 49 | + exact_version = nil |
| 50 | + begin |
| 51 | + subkeys = registry_enumkeys(dotnet_vkey) |
| 52 | + rescue::Exception => e |
| 53 | + print_status("Encountered exception in get_versionception: #{e.class} #{e}") |
| 54 | + end |
| 55 | + subkeys.each do |i| |
| 56 | + exact_version = search_for_version(dotnet_vkey + '\\' +i) |
| 57 | + unless exact_version.nil? |
| 58 | + #if we find a version, stop looking |
| 59 | + break |
| 60 | + end |
| 61 | + end |
| 62 | + return exact_version |
| 63 | + end |
| 64 | + |
| 65 | + # |
| 66 | + # 'Public' function that returns a list of all .NET versions on |
| 67 | + # a windows host |
| 68 | + # |
| 69 | + def get_dotnet_versions |
| 70 | + ret_val = Array.new |
| 71 | + key = 'HKLM\\SOFTWARE\\Microsoft\NET Framework Setup\\NDP' |
| 72 | + begin |
| 73 | + dotnet_keys = registry_enumkeys(key) |
| 74 | + rescue::Exception => e |
| 75 | + print_status("Encountered exception in get_dotnet_version: #{e.class} #{e}") |
| 76 | + end |
| 77 | + unless dotnet_keys.nil? |
| 78 | + dotnet_keys.each do |i| |
| 79 | + if i[0,1] == 'v' |
| 80 | + key = 'HKLM\\SOFTWARE\\Microsoft\NET Framework Setup\\NDP\\'+i |
| 81 | + dotnet_version = get_versionception(key) |
| 82 | + unless dotnet_version.nil? |
| 83 | + ret_val << dotnet_version |
| 84 | + end |
| 85 | + end |
| 86 | + end |
| 87 | + end |
| 88 | + return ret_val |
| 89 | + end |
| 90 | +end |
| 91 | +end |
| 92 | +end |
| 93 | +end |
0 commit comments