Module: Msf::Post::Windows::Version
Defined Under Namespace
Classes: Error
Constant Summary
Constants included from Registry
Registry::HKEY_CLASSES_ROOT, Registry::HKEY_CURRENT_CONFIG, Registry::HKEY_CURRENT_USER, Registry::HKEY_DYN_DATA, Registry::HKEY_LOCAL_MACHINE, Registry::HKEY_PERFORMANCE_DATA, Registry::HKEY_USERS, Registry::REGISTRY_VIEW_32_BIT, Registry::REGISTRY_VIEW_64_BIT, Registry::REGISTRY_VIEW_NATIVE, Registry::REG_BIG_ENDIAN, Registry::REG_BINARY, Registry::REG_DWORD, Registry::REG_EXPAND_SZ, Registry::REG_LINK, Registry::REG_LITTLE_ENDIAN, Registry::REG_MULTI_SZ, Registry::REG_NONE, Registry::REG_QWORD, Registry::REG_SZ
Instance Method Summary collapse
- #get_version_info ⇒ Object
- #get_version_info_fallback_impl ⇒ Object
- #get_version_info_impl ⇒ Object
- #initialize(info = {}) ⇒ Object
Methods included from Registry
#meterpreter_registry_createkey, #meterpreter_registry_deletekey, #meterpreter_registry_deleteval, #meterpreter_registry_enumkeys, #meterpreter_registry_enumvals, #meterpreter_registry_getvaldata, #meterpreter_registry_getvalinfo, #meterpreter_registry_key_exist?, #meterpreter_registry_loadkey, #meterpreter_registry_perms, #meterpreter_registry_setvaldata, #meterpreter_registry_unloadkey, #normalize_key, #registry_createkey, #registry_deletekey, #registry_deleteval, #registry_enumkeys, #registry_enumvals, #registry_getvaldata, #registry_getvalinfo, #registry_hive_lookup, #registry_key_exist?, #registry_loadkey, #registry_setvaldata, #registry_unloadkey, #session_has_registry_ext, #shell_registry_cmd, #shell_registry_cmd_result, #shell_registry_createkey, #shell_registry_deletekey, #shell_registry_deleteval, #shell_registry_enumkeys, #shell_registry_enumvals, #shell_registry_getvaldata, #shell_registry_getvalinfo, #shell_registry_key_exist?, #shell_registry_loadkey, #shell_registry_setvaldata, #shell_registry_unloadkey, #split_key
Methods included from CliParse
#win_parse_error, #win_parse_results
Instance Method Details
#get_version_info ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/msf/core/post/windows/version.rb', line 24 def get_version_info result = get_version_info_impl if result.nil? print_error("Couldn't retrieve the target's build number!") raise Error, "Couldn't retrieve the target's build number!" end result end |
#get_version_info_fallback_impl ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/msf/core/post/windows/version.rb', line 34 def get_version_info_fallback_impl build_num_raw = cmd_exec('cmd.exe /c ver') groups = build_num_raw.match(/Version\s+(\d+)\.(\d+)\.(\d+)(?:\.(\d+))?/) if groups.nil? return nil end major, minor, build, revision = groups.captures # Default to workstation, since it'll likely be an older OS - pre Server editions return Msf::WindowsVersion.new(major.to_i, minor.to_i, build.to_i, 0, revision, Msf::WindowsVersion::VER_NT_WORKSTATION) end |
#get_version_info_impl ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/msf/core/post/windows/version.rb', line 46 def get_version_info_impl if session.type == 'meterpreter' result = session.railgun.ntdll.RtlGetVersion(input_os_version_info_ex) os_version_info_ex = unpack_version_info(result['VersionInformation']) major = os_version_info_ex[1] minor = os_version_info_ex[2] build = os_version_info_ex[3] service_pack = os_version_info_ex[6] product_type = os_version_info_ex[9] revision = 0 if (major >= 10) revision = registry_getvaldata('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'UBR', Msf::Post::Windows::Registry::REGISTRY_VIEW_NATIVE) end Msf::WindowsVersion.new(major, minor, build, service_pack, revision, product_type) else # Command shell - we'll try reg commands, and fall back to `ver` build_str = shell_registry_getvaldata('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'CurrentBuildNumber', Msf::Post::Windows::Registry::REGISTRY_VIEW_NATIVE) if build_str.nil? return get_version_info_fallback_impl end version_str = shell_registry_getvaldata('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'CurrentVersion', Msf::Post::Windows::Registry::REGISTRY_VIEW_NATIVE) if version_str.nil? return get_version_info_fallback_impl end build_num = build_str.to_i version_match = version_str.match(/(\d+)\.(\d+)/) if version_match.nil? return get_version_info_fallback_impl end major, minor = version_match.captures major = major.to_i minor = minor.to_i product = shell_registry_getvaldata('HKLM\SYSTEM\CurrentControlSet\Control\ProductOptions', 'ProductType', Msf::Post::Windows::Registry::REGISTRY_VIEW_NATIVE) case product when 'WinNT' product_type = Msf::WindowsVersion::VER_NT_WORKSTATION when 'LanmanNT' product_type = Msf::WindowsVersion::VER_NT_DOMAIN_CONTROLLER when 'ServerNT' product_type = Msf::WindowsVersion::VER_NT_SERVER else product_type = Msf::WindowsVersion::VER_NT_WORKSTATION end if (major == 6) && (minor == 3) && (build_num > 9600) # 9600 is Windows 8.1 build number # This is Windows 10+ - the version numbering is calculated differently major = shell_registry_getvaldata('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'CurrentMajorVersionNumber', Msf::Post::Windows::Registry::REGISTRY_VIEW_NATIVE) minor = shell_registry_getvaldata('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'CurrentMinorVersionNumber', Msf::Post::Windows::Registry::REGISTRY_VIEW_NATIVE) ubr = shell_registry_getvaldata('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'UBR', Msf::Post::Windows::Registry::REGISTRY_VIEW_NATIVE) if major.nil? || minor.nil? || ubr.nil? return get_version_info_fallback_impl end Msf::WindowsVersion.new(major, minor, build_num, 0, ubr, product_type) else # Pre-Windows 10 service_pack_raw = shell_registry_getvaldata('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'CSDVersion', Msf::Post::Windows::Registry::REGISTRY_VIEW_NATIVE) if service_pack_raw.nil? && (major >= 6) # Some older versions didn't put the Service Pack value in both 32 and 64-bit versions of the registry - look there specifically service_pack_raw = shell_registry_getvaldata('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'CSDVersion', Msf::Post::Windows::Registry::REGISTRY_VIEW_32_BIT) end service_pack = 0 unless service_pack_raw.nil? match = service_pack_raw.match(/Service Pack (\d+)/) unless match.nil? service_pack = match[1].to_i end end Msf::WindowsVersion.new(major, minor, build_num, service_pack, 0, product_type) end end end |
#initialize(info = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/msf/core/post/windows/version.rb', line 9 def initialize(info = {}) super( update_info( info, 'Compat' => { 'Meterpreter' => { 'Commands' => %w[ stdapi_railgun_api ] } } ) ) end |