Class: Msf::WindowsVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/msf/core/windows_version.rb

Overview

Represents the version of a Windows operating system

Defined Under Namespace

Modules: MajorRelease

Constant Summary collapse

VER_NT_WORKSTATION =
1
VER_NT_DOMAIN_CONTROLLER =
2
VER_NT_SERVER =
3
Win2000 =
Rex::Version.new('5.0.2195')
XP_SP0 =
Rex::Version.new('5.1.2600.0')
XP_SP1 =
Rex::Version.new('5.1.2600.1')
XP_SP2 =
Rex::Version.new('5.1.2600.2')
XP_SP3 =
Rex::Version.new('5.1.2600.3')
Server2003_SP0 =
Rex::Version.new('5.2.3790.0')
Server2003_SP1 =
Rex::Version.new('5.2.3790.1')
Server2003_SP2 =
Rex::Version.new('5.2.3790.2')
Vista_SP0 =
Server2008_SP0 = Rex::Version.new('6.0.6000.0')
Vista_SP1 =
Server2008_SP1 = Rex::Version.new('6.0.6001.1')
Vista_SP2 =
Server2008_SP2 = Rex::Version.new('6.0.6002.2')
Server2008_SP2_Update =
Rex::Version.new('6.0.6003.2')
Win7_SP0 =
Server2008_R2_SP0 = Rex::Version.new('6.1.7600.0')
Win7_SP1 =
Server2008_R2_SP1 = Rex::Version.new('6.1.7601.1')
Win8 =
Server2012 = Rex::Version.new('6.2.9200.0')
Win81 =
Server2012_R2 = Rex::Version.new('6.3.9600.0')
Win10_1507 =
Win10_InitialRelease = Rex::Version.new('10.0.10240.0')
Win10_1511 =
Rex::Version.new('10.0.10586.0')
Win10_1607 =
Server2016 = Rex::Version.new('10.0.14393.0')
Win10_1703 =
Rex::Version.new('10.0.15063.0')
Win10_1709 =
Rex::Version.new('10.0.16299.0')
Win10_1803 =
Rex::Version.new('10.0.17134.0')
Win10_1809 =
Server2019 = Rex::Version.new('10.0.17763.0')
Win10_1903 =
Rex::Version.new('10.0.18362.0')
Win10_1909 =
Rex::Version.new('10.0.18363.0')
Win10_2004 =
Rex::Version.new('10.0.19041.0')
Win10_20H2 =
Rex::Version.new('10.0.19042.0')
Win10_21H1 =
Rex::Version.new('10.0.19043.0')
Win10_21H2 =
Rex::Version.new('10.0.19044.0')
Win10_22H2 =
Rex::Version.new('10.0.19045.0')
Server2022 =
Rex::Version.new('10.0.20348.0')
Win11_21H2 =
Rex::Version.new('10.0.22000.0')
Win11_22H2 =
Rex::Version.new('10.0.22621.0')
Win11_23H2 =
Rex::Version.new('10.0.22631.0')
Server2022_23H2 =
Rex::Version.new('10.0.25398.0')

Instance Method Summary collapse

Constructor Details

#initialize(major, minor, build, service_pack, revision, product_type) ⇒ WindowsVersion

Returns a new instance of WindowsVersion.



75
76
77
78
79
80
81
82
# File 'lib/msf/core/windows_version.rb', line 75

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

Instance Method Details

#build_numberObject

The specific build number of this version (major.minor.build.service_pack)



91
92
93
# File 'lib/msf/core/windows_version.rb', line 91

def build_number
  Rex::Version.new("#{_major}.#{_minor}.#{_build}.#{_service_pack}")
end

#domain_controller?Boolean

This Windows Server has been promoted to a DC

Returns:

  • (Boolean)


109
110
111
# File 'lib/msf/core/windows_version.rb', line 109

def domain_controller?
  product_type == VER_NT_DOMAIN_CONTROLLER
end

#product_nameObject

The name of the OS, as it is most commonly rendered. Includes Service Pack if present, or build number if Win10 or higher.



114
115
116
117
118
119
120
121
122
# File 'lib/msf/core/windows_version.rb', line 114

def product_name
  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_numberObject

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.



86
87
88
# File 'lib/msf/core/windows_version.rb', line 86

def revision_number
  _revision
end

#to_sObject



124
125
126
# File 'lib/msf/core/windows_version.rb', line 124

def to_s
  product_name
end

#vista_or_2008?Boolean

Is this version number from the Vista/Server 2008 generation of Windows OSes

Returns:

  • (Boolean)


129
130
131
# File 'lib/msf/core/windows_version.rb', line 129

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

Returns:

  • (Boolean)


134
135
136
# File 'lib/msf/core/windows_version.rb', line 134

def win7_or_2008r2?
  build_number.between?(Win7_SP0, Win7_SP1)
end

#windows_server?Boolean

Is this OS a Windows Server instance?

Returns:

  • (Boolean)


96
97
98
99
100
101
# File 'lib/msf/core/windows_version.rb', line 96

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?

Returns:

  • (Boolean)


104
105
106
# File 'lib/msf/core/windows_version.rb', line 104

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

Returns:

  • (Boolean)


139
140
141
# File 'lib/msf/core/windows_version.rb', line 139

def xp_or_2003?
  build_number.between?(XP_SP0, Server2003_SP2)
end