Class: Msf::WindowsVersion
- Inherits:
-
Object
- Object
- Msf::WindowsVersion
- Defined in:
- lib/msf/core/windows_version.rb
Overview
Represents the version of a Windows operating system
Defined Under Namespace
Modules: MajorRelease, ServerSpecificVersions, WorkstationSpecificVersions
Constant Summary collapse
- VER_NT_WORKSTATION =
1
- VER_NT_DOMAIN_CONTROLLER =
2
- VER_NT_SERVER =
3
- ServerNameMapping =
{ :Server2003_SP0 => "Windows Server 2003", :Server2003_SP1 => "Windows Server 2003 Service Pack 1", :Server2003_SP2 => "Windows Server 2003 Service Pack 2", :Server2008_SP0 => "Windows Server 2008", :Server2008_SP1 => "Windows Server 2008 Service Pack 1", :Server2008_SP2 => "Windows Server 2008 Service Pack 2", :Server2008_SP2_Update => "Windows Server 2008 Service Pack 2 Update", :Server2008_R2_SP0 => "Windows Server 2008 R2", :Server2008_R2_SP1 => "Windows Server 2008 R2 Service Pack 1", :Server2012 => "Windows Server 2012 R2", :Server2012_R2 => "Windows Server 2012 R2", :Server2016 => "Windows Server 2016", :Server2019 => "Windows Server 2019", :Server2022 => "Windows Server 2022", :Server2022_23H2 => "Windows Server 2022 version 23H2", :Server2025 => "Windows Server 2025" }
- WorkstationNameMapping =
{ :Win2000 => "Windows 2000", :XP_SP0 => "Windows XP", :XP_SP1 => "Windows XP Service Pack 1", :XP_SP2 => "Windows XP Service Pack 2", :XP_SP3 => "Windows XP Service Pack 3", :Vista_SP0 => "Windows Vista", :Vista_SP1 => "Windows Vista Service Pack 1", :Vista_SP2 => "Windows Vista Service Pack 2", :Win7_SP0 => "Windows 7", :Win7_SP1 => "Windows 7 Service Pack 1", :Win8 => "Windows 8", :Win81 => "Windows 8.1", :Win10_1507 => "Windows 10 version 1507", :Win10_1511 => "Windows 10 version 1511", :Win10_1607 => "Windows 10 version 1607", :Win10_1703 => "Windows 10 version 1703", :Win10_1709 => "Windows 10 version 1709", :Win10_1803 => "Windows 10 version 1803", :Win10_1809 => "Windows 10 version 1809", :Win10_1903 => "Windows 10 version 1903", :Win10_1909 => "Windows 10 version 1909", :Win10_2004 => "Windows 10 version 2004", :Win10_20H2 => "Windows 10 version 20H2", :Win10_21H1 => "Windows 10 version 21H1", :Win10_21H2 => "Windows 10 version 21H2", :Win10_22H2 => "Windows 10 version 22H2", :Win11_21H2 => "Windows 11 version 21H2", :Win11_22H2 => "Windows 11 version 22H2", :Win11_23H2 => "Windows 11 version 23H2", :Win11_24H2 => "Windows 11 version 24H2" }
- Win10_InitialRelease =
Win10_1507
Constants included from ServerSpecificVersions
ServerSpecificVersions::Server2003_SP0, ServerSpecificVersions::Server2003_SP1, ServerSpecificVersions::Server2003_SP2, ServerSpecificVersions::Server2008_R2_SP0, ServerSpecificVersions::Server2008_R2_SP1, ServerSpecificVersions::Server2008_SP0, ServerSpecificVersions::Server2008_SP1, ServerSpecificVersions::Server2008_SP2, ServerSpecificVersions::Server2008_SP2_Update, ServerSpecificVersions::Server2012, ServerSpecificVersions::Server2012_R2, ServerSpecificVersions::Server2016, ServerSpecificVersions::Server2019, ServerSpecificVersions::Server2022, ServerSpecificVersions::Server2022_23H2, ServerSpecificVersions::Server2025
Constants included from WorkstationSpecificVersions
WorkstationSpecificVersions::Vista_SP0, WorkstationSpecificVersions::Vista_SP1, WorkstationSpecificVersions::Vista_SP2, WorkstationSpecificVersions::Win10_1507, WorkstationSpecificVersions::Win10_1511, WorkstationSpecificVersions::Win10_1607, WorkstationSpecificVersions::Win10_1703, WorkstationSpecificVersions::Win10_1709, WorkstationSpecificVersions::Win10_1803, WorkstationSpecificVersions::Win10_1809, WorkstationSpecificVersions::Win10_1903, WorkstationSpecificVersions::Win10_1909, WorkstationSpecificVersions::Win10_2004, WorkstationSpecificVersions::Win10_20H2, WorkstationSpecificVersions::Win10_21H1, WorkstationSpecificVersions::Win10_21H2, WorkstationSpecificVersions::Win10_22H2, WorkstationSpecificVersions::Win11_21H2, WorkstationSpecificVersions::Win11_22H2, WorkstationSpecificVersions::Win11_23H2, WorkstationSpecificVersions::Win11_24H2, WorkstationSpecificVersions::Win2000, WorkstationSpecificVersions::Win7_SP0, WorkstationSpecificVersions::Win7_SP1, WorkstationSpecificVersions::Win8, WorkstationSpecificVersions::Win81, WorkstationSpecificVersions::XP_SP0, WorkstationSpecificVersions::XP_SP1, WorkstationSpecificVersions::XP_SP2, WorkstationSpecificVersions::XP_SP3
Class Method Summary collapse
-
.from_ntlm_os_version(major, minor, build) ⇒ String
Get the string representation of the OS, given a major, minor and build number (as reported by an NTLM handshake).
Instance Method Summary collapse
-
#build_number ⇒ Object
The specific build number of this version (major.minor.build.service_pack).
-
#domain_controller? ⇒ Boolean
This Windows Server has been promoted to a DC.
-
#initialize(major, minor, build, service_pack, revision, product_type) ⇒ WindowsVersion
constructor
A new instance of WindowsVersion.
-
#product_name ⇒ Object
The name of the OS, as it is most commonly rendered.
-
#revision_number ⇒ Object
The specific revision number of this version This is mainly going to be present on Windows 10+, wherein it’s easy to get it from the registry.
- #to_s ⇒ Object
-
#vista_or_2008? ⇒ Boolean
Is this version number from the Vista/Server 2008 generation of Windows OSes.
-
#win7_or_2008r2? ⇒ Boolean
Is this version number from the Windows 7/Server 2008 R2 generation of Windows OSes.
-
#windows_server? ⇒ Boolean
Is this OS a Windows Server instance?.
-
#workstation? ⇒ Boolean
Is this a Workstation build?.
-
#xp_or_2003? ⇒ Boolean
Is this version number from the XP/Server 2003 generation of Windows OSes.
Constructor Details
#initialize(major, minor, build, service_pack, revision, product_type) ⇒ WindowsVersion
Returns a new instance of WindowsVersion.
148 149 150 151 152 153 154 155 |
# File 'lib/msf/core/windows_version.rb', line 148 def initialize(major, minor, build, service_pack, revision, product_type) self._major = major self._minor = minor self._build = build self._service_pack = service_pack self._revision = revision self.product_type = product_type end |
Class Method Details
.from_ntlm_os_version(major, minor, build) ⇒ String
Get the string representation of the OS, given a major, minor and build number (as reported by an NTLM handshake). The NTLM structure makes no guarantee that the underlying OS of the server is actually Windows, so if we don’t find a precise match, return nil
234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/msf/core/windows_version.rb', line 234 def self.from_ntlm_os_version(major, minor, build) workstation_string = self.version_string(major, minor, build, WorkstationSpecificVersions, WorkstationNameMapping) server_string = self.version_string(major, minor, build, ServerSpecificVersions, ServerNameMapping) version_strings = [] version_strings.append(workstation_string) unless workstation_string.nil? version_strings.append(server_string) unless server_string.nil? if version_strings.length > 0 version_strings.join('/') else nil end end |
Instance Method Details
#build_number ⇒ Object
The specific build number of this version (major.minor.build.service_pack)
164 165 166 |
# File 'lib/msf/core/windows_version.rb', line 164 def build_number Rex::Version.new("#{_major}.#{_minor}.#{_build}.#{_service_pack}") end |
#domain_controller? ⇒ Boolean
This Windows Server has been promoted to a DC
182 183 184 |
# File 'lib/msf/core/windows_version.rb', line 182 def domain_controller? product_type == VER_NT_DOMAIN_CONTROLLER end |
#product_name ⇒ Object
The name of the OS, as it is most commonly rendered. Includes Service Pack if present, or build number if Win10 or higher.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/msf/core/windows_version.rb', line 187 def product_name # First check if there's a specific, known version we have a string for if windows_server? known_version = self.class.version_string(_major, _minor, _build, ServerSpecificVersions, ServerNameMapping) else known_version = self.class.version_string(_major, _minor, _build, WorkstationSpecificVersions, WorkstationNameMapping) end return known_version unless known_version.nil? # Otherwise, build it up from version numbers, to the best of our ability result = "Unknown Windows version: #{_major}.#{_minor}.#{_build}" name = major_release_name result = name unless name.nil? result = "#{result} Service Pack #{_service_pack}" if _service_pack != 0 result = "#{result} Build #{_build}" if build_number >= Win10_InitialRelease result end |
#revision_number ⇒ Object
The specific revision number of this version This is mainly going to be present on Windows 10+, wherein it’s easy to get it from the registry.
159 160 161 |
# File 'lib/msf/core/windows_version.rb', line 159 def revision_number _revision end |
#to_s ⇒ Object
206 207 208 |
# File 'lib/msf/core/windows_version.rb', line 206 def to_s product_name end |
#vista_or_2008? ⇒ Boolean
Is this version number from the Vista/Server 2008 generation of Windows OSes
211 212 213 |
# File 'lib/msf/core/windows_version.rb', line 211 def vista_or_2008? build_number.between?(Vista_SP0, Vista_SP2) end |
#win7_or_2008r2? ⇒ Boolean
Is this version number from the Windows 7/Server 2008 R2 generation of Windows OSes
216 217 218 |
# File 'lib/msf/core/windows_version.rb', line 216 def win7_or_2008r2? build_number.between?(Win7_SP0, Win7_SP1) end |
#windows_server? ⇒ Boolean
Is this OS a Windows Server instance?
169 170 171 172 173 174 |
# File 'lib/msf/core/windows_version.rb', line 169 def windows_server? # There are other types than just workstation/server/DC, but Microsoft's own documentation says # "If it's not Workstation, then it's Server" # https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-osversioninfoexa product_type != VER_NT_WORKSTATION end |
#workstation? ⇒ Boolean
Is this a Workstation build?
177 178 179 |
# File 'lib/msf/core/windows_version.rb', line 177 def workstation? product_type == VER_NT_WORKSTATION end |
#xp_or_2003? ⇒ Boolean
Is this version number from the XP/Server 2003 generation of Windows OSes
221 222 223 |
# File 'lib/msf/core/windows_version.rb', line 221 def xp_or_2003? build_number.between?(XP_SP0, Server2003_SP2) end |