Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A more robust implementation for Windows version comparisons #17336

Merged
merged 7 commits into from
Jun 13, 2023

Conversation

smashery
Copy link
Contributor

@smashery smashery commented Dec 5, 2022

This change resolves #16389, by implementing a new class that has logic and constants to sort out

To make sure that the API made sense, I replaced a bunch of usages of the previous pattern (e.g. if sysinfo['OS'] =~ /Windows [Vista|2008|7]) with this new approach.

In doing so, I discovered a bunch of modules that had incorrect checks - both compared against MSRC's advisories, and tested directly in a range of OSes. Largely these were modules that were configured to run on Workstation builds, but the implementation overlooked the Server versions. For example:

windows/local/bypass_injection_winsxs was configured to only run against Workstation builds, but I tested against 2016 and 2019 and it works fine. On 2012, the required binary (dccw.exe) wasn't present. Didn't test on 2012 R2. Worked all the way up until latest Win10 (22H2), although not against Server 2022.

  • appx_svc_hard_link_privesc crashed when it doesn't succeed, and complained about incorrect session types/platform, because those settings hadn't been configured. So I fixed that, though it uncovered a separate bug in meterp, which I'll log.
  • bypassuac_sluihijack was configured to only work against workstation builds, and every Win10. But I tested it against 2016 and 2019, and it worked fine. UACME gives a fix version for this technique, so I added that in.
  • bypassuac_dotnet_profiler seemed to overlook Server >2012. But I tested on 2016, 2019 and 2022 and it works fine.

I'm leaving this as a draft initially, as I'd appreciate feedback about whether the API is sufficiently intuitive.

I also need to go back through a bunch of the modules I changed, and do the needful with respect to rubocop.

@bcoles
Copy link
Contributor

bcoles commented Dec 5, 2022

The updates to modules/exploits/windows/local/s4u_persistence.rb in this PR likely fixes #16485.

TODO:

lib/msf/core/windows_version.rb Outdated Show resolved Hide resolved
lib/msf/core/windows_version.rb Show resolved Hide resolved
lib/msf/core/windows_version.rb Show resolved Hide resolved
lib/msf/core/post/windows/version.rb Show resolved Hide resolved
@adfoster-r7 adfoster-r7 mentioned this pull request Dec 5, 2022
@adfoster-r7
Copy link
Contributor

I fixed the linting issues in this PR - #17338

Should be able to rebase this PR against the latest master to get CI happy again (hopefully)

Win81 = "Windows 8.1"
Server2012R2 = "Windows Server 2012 R2"

Win10Plus = "Windows 10+"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want "Windows 11" as a separate entity?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On one hand this makes the most intuitive sense... on the other, the way Microsoft actually treats their version numbers makes this a less obvious choice in my opinion: Windows 10 is 10.0.x whereas Windows 11 is... also 10.0.x. Combine that with the versioning of Windows Server lately, wherein Server 2016 is effectively in line with Windows 10 v1607 (in terms of a shared build number), Server 2019 with Win10 1809 and Server 2022... well it's no longer in line with a specific workstation version, in terms of its build number... but they're all still "Windows 10.0.x". It seems to me that, if we ignore the marketing of what they call it, we're kind of in an era of incremental releases, rather than the former monolithic quantum leap.

The other consideration I had is around forwards-compatibility, which is what this PR aims to resolve. It's clear that Microsoft are changing their version numbering strategy, where everything is now 10.0.x; but it's not clear to me what it will be in the future, and so I can't say with confidence what a check for "Windows 11 in general" would actually look like? Would it check for "10.0.x where x is greater than 22000"? Could that misidentify something as Windows 12 in the future? I know playing the what-if game is maybe a little fraught, and hey, you can always change code in the future... but in the past, it was easy: a new "Major Release" means a new minor version number at least (Vista == 6.0, Win7 == 6.1, Win8 == 6.2, Win8.1 == 6.3). Now it seems much less clear.

I guess tl;dr I'm keen to see the dust settle a bit more on the version numbers before confidently proclaiming "This is Windows 11".

lib/msf/core/windows_version.rb Outdated Show resolved Hide resolved
lib/msf/core/windows_version.rb Outdated Show resolved Hide resolved
@smashery smashery force-pushed the feature/16389 branch 2 times, most recently from 79d448e to 5d39414 Compare December 9, 2022 01:08
@smashery smashery marked this pull request as ready for review December 9, 2022 03:05
@smashery
Copy link
Contributor Author

smashery commented Dec 9, 2022

Should be good for review now. Note that some of the modules that were modified have had subtle changes to the versions supported - I've tried to comment these in the relevant commit messages as I went, about the justifications for these.

Verification

  • Verify the version detection works on a range of Windows versions, using meterpreter
  • Verify the version detection works on a range of Windows versions, using a command shell
  • Sanity-check the modified modules that they match the existing functionality, or the changes are reasonable.

@old_os = true
unless sysinfo['OS'].include?('5.2 Build 3790, Service Pack 2')
if version.build_number < Msf::WindowsVersion::Server2003_SP1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the persistence_exe module that uses this mixin, and the /F flag worked on 2003 SP1 as well, so I adjusted the range to include that too.

Comment on lines +128 to +130
unless @rtf_path.nil?
write_file(@rtf_path, @original_data)
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meterpreter crashes if these are nil, which it is if the exploit didn't even start - decided to fix it while I was here.

Comment on lines +157 to +158
if version.build_number < Msf::WindowsVersion::Win8 && !version.windows_server?
print_bad("Operating system: #{version.product_name}")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to include Windows 2000 and earlier, based on the comment below "Windows 7 and previous...not vulnerable"

version = get_version_info
unless version.build_number.between?(Msf::WindowsVersion::Vista_SP0, Msf::WindowsVersion::Win81)
fail_with(Failure::NotVulnerable, "#{version.product_name} is not vulnerable.")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is technically a change in behaviour, since it never used to specify Server 2012, but it does support the equivalent workstation versions; and I actually tested it on Server 2012, and it works fine. I presume just a regex oversight - what this PR is intended to help with.

@bwatters-r7
Copy link
Contributor

I added a quick post module that just ran the get_version_info method and printed the results

Windows 10x64 releases

Meterpreter

msf6 exploit(windows/smb/psexec) > sessions -C sysinfo
[*] Running 'sysinfo' on meterpreter session 1 (10.5.134.102)
Computer        : WIN10X64_1803
OS              : Windows 10 (10.0 Build 17134).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x64/windows
[*] Running 'sysinfo' on meterpreter session 2 (10.5.134.108)
Computer        : WIN10X64_1511
OS              : Windows 10 (10.0 Build 10586).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x64/windows
[*] Running 'sysinfo' on meterpreter session 3 (10.5.134.111)
Computer        : WIN10X64_1703
OS              : Windows 10 (10.0 Build 15063).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x64/windows
[*] Running 'sysinfo' on meterpreter session 4 (10.5.134.112)
Computer        : WIN10X64_1809
OS              : Windows 10 (10.0 Build 17763).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x64/windows
[*] Running 'sysinfo' on meterpreter session 5 (10.5.134.113)
Computer        : WIN10X64_1607
OS              : Windows 10 (10.0 Build 14393).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x64/windows
[*] Running 'sysinfo' on meterpreter session 6 (10.5.134.116)
Computer        : WIN10X64_1709
OS              : Windows 10 (10.0 Build 16299).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x64/windows
[*] Running 'sysinfo' on meterpreter session 7 (10.5.134.118)
Computer        : WIN10X64
OS              : Windows 10 (10.0 Build 10240).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x64/windows
[*] Running 'sysinfo' on meterpreter session 8 (10.5.134.136)
Computer        : WIN10X64_2004
OS              : Windows 10 (10.0 Build 19041).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x64/windows
[*] Running 'sysinfo' on meterpreter session 9 (10.5.134.151)
Computer        : WIN10X64_20H2
OS              : Windows 10 (10.0 Build 19042).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x64/windows
[*] Running 'sysinfo' on meterpreter session 10 (10.5.134.192)
Computer        : WIN10X64_21H1
OS              : Windows 10 (10.0 Build 19043).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x64/windows
msf6 exploit(windows/smb/psexec) > use post/windows/manage/get_version_info
msf6 post(windows/manage/get_version_info) > set verbose true
verbose => true
msf6 post(windows/manage/get_version_info) > set session 1
session => 1
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 17134
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 2
session => 2
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 10586
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 3
session => 3
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 15063
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 4
session => 4
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 17763
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 5
session => 5
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 14393
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 6
session => 6
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 16299
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 7
session => 7
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 10240
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 8
session => 8
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 19041
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 9
session => 9
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 19042
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 10
session => 10
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 19043
[*] Post module execution completed

Shell

msf6 exploit(windows/smb/psexec) > sessions  -l

Active sessions
===============

  Id  Name  Type               Information                                        Connection
  --  ----  ----               -----------                                        ----------
  1         shell x64/windows  Shell Banner: Microsoft Windows [Version 10.0.171  10.5.135.201:4567 -> 10.5.134.102:49679 (10.5.134
                               34.1] -----                                        .102)
  2         shell x64/windows  Shell Banner: Microsoft Windows [Version 10.0.150  10.5.135.201:4567 -> 10.5.134.111:49677 (10.5.134
                               63] (c) 2017 Microsoft Corp...                     .111)
  3         shell x64/windows  Shell Banner: Microsoft Windows [Version 10.0.177  10.5.135.201:4567 -> 10.5.134.112:49682 (10.5.134
                               63.107] -----                                      .112)
  4         shell x64/windows  Shell Banner: Microsoft Windows [Version 10.0.143  10.5.135.201:4567 -> 10.5.134.113:49680 (10.5.134
                               93] -----                                          .113)
  5         shell x64/windows  Shell Banner: Microsoft Windows [Version 10.0.162  10.5.135.201:4567 -> 10.5.134.116:49677 (10.5.134
                               99.15] -----                                       .116)
  6         shell x64/windows  Shell Banner: Microsoft Windows [Version 10.0.102  10.5.135.201:4567 -> 10.5.134.118:49422 (10.5.134
                               40] -----                                          .118)
  7         shell x64/windows  Shell Banner: Microsoft Windows [Version 10.0.190  10.5.135.201:4567 -> 10.5.134.136:49712 (10.5.134
                               41.208] -----                                      .136)
  8         shell x64/windows  Shell Banner: Microsoft Windows [Version 10.0.190  10.5.135.201:4567 -> 10.5.134.151:49745 (10.5.134
                               42.631] -----                                      .151)
  9         shell x64/windows  Shell Banner: Microsoft Windows [Version 10.0.190  10.5.135.201:4567 -> 10.5.134.192:50096 (10.5.134
                               43.928] (c) Microsoft Corpo...                     .192)

msf6 exploit(windows/smb/psexec) > use post/windows/manage/get_version_info
msf6 post(windows/manage/get_version_info) > set verbose true
verbose => true
msf6 post(windows/manage/get_version_info) > set session 1
session => 1
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 17134
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 2
session => 2
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 15063
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 3
session => 3
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 17763
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 4
session => 4
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 14393
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 5
session => 5
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 16299
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 6
session => 6
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 10240
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 7
session => 7
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 19041
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 8
session => 8
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 19042
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 9
session => 9
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 19043
[*] Post module execution completed

Powershell

msf6 exploit(windows/smb/psexec) > sessions -l

Active sessions
===============

  Id  Name  Type                Information                     Connection
  --  ----  ----                -----------                     ----------
  1         powershell windows  WIN10X64_1803$ @ WIN10X64_1803  10.5.135.201:4567 -> 10.5.134.102:49679 (10.5.134.102)
  2         powershell windows  WIN10X64_1511$ @ WIN10X64_1511  10.5.135.201:4567 -> 10.5.134.108:49671 (10.5.134.108)
  3         powershell windows  WIN10X64_1703$ @ WIN10X64_1703  10.5.135.201:4567 -> 10.5.134.111:49678 (10.5.134.111)
  4         powershell windows  WIN10X64_1809$ @ WIN10X64_1809  10.5.135.201:4567 -> 10.5.134.112:49681 (10.5.134.112)
  5         powershell windows  WIN10X64_1607$ @ WIN10X64_1607  10.5.135.201:4567 -> 10.5.134.113:49676 (10.5.134.113)
  6         powershell windows  WIN10X64_1709$ @ WIN10X64_1709  10.5.135.201:4567 -> 10.5.134.116:49677 (10.5.134.116)
  7         powershell windows  WIN10X64$ @ WIN10X64            10.5.135.201:4567 -> 10.5.134.118:49420 (10.5.134.118)
  8         powershell windows  WIN10X64_2004$ @ WIN10X64_2004  10.5.135.201:4567 -> 10.5.134.136:49694 (10.5.134.136)
  9         powershell windows  WIN10X64_20H2$ @ WIN10X64_20H2  10.5.135.201:4567 -> 10.5.134.151:49733 (10.5.134.151)
  10        powershell windows  WIN10X64_21H1$ @ WIN10X64_21H1  10.5.135.201:4567 -> 10.5.134.192:49991 (10.5.134.192)

msf6 exploit(windows/smb/psexec) > use post/windows/manage/get_version_info
msf6 post(windows/manage/get_version_info) > set verbose true
verbose => true
msf6 post(windows/manage/get_version_info) > set session 1
session => 1
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows 10+ Build 17134
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 2
session => 2
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows 10+ Build 10586
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 3
session => 3
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows 10+ Build 15063
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 4
session => 4
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows 10+ Build 17763
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 5
session => 5
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows 10+ Build 14393
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 6
session => 6
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows 10+ Build 16299
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 7
session => 7
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows 10+ Build 10240
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 8
session => 8
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows 10+ Build 19041
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 9
session => 9
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows 10+ Build 19042
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 10
session => 10
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows 10+ Build 19043
[*] Post module execution completed

@bwatters-r7
Copy link
Contributor

Windows 10 x86 Releases

Meterpreter

msf6 exploit(windows/smb/psexec) > sessions -l

Active sessions
===============

  Id  Name  Type                     Information                          Connection
  --  ----  ----                     -----------                          ----------
  1         meterpreter x86/windows  NT AUTHORITY\SYSTEM @ WIN10X86_1803  10.5.135.201:4567 -> 10.5.134.103:50103 (10.5.134.103)
  2         meterpreter x86/windows  NT AUTHORITY\SYSTEM @ WIN10X86       10.5.135.201:4567 -> 10.5.134.109:49431 (10.5.134.109)
  5         meterpreter x86/windows  NT AUTHORITY\SYSTEM @ WIN10X86_2004  10.5.135.201:4567 -> 10.5.134.131:50595 (10.5.134.131)
  6         meterpreter x86/windows  NT AUTHORITY\SYSTEM @ WIN10X86_1703  10.5.135.201:4567 -> 10.5.134.144:49691 (10.5.134.144)
  7         meterpreter x86/windows  NT AUTHORITY\SYSTEM @ WIN10X86_1607  10.5.135.201:4567 -> 10.5.134.147:49690 (10.5.134.147)
  8         meterpreter x86/windows  NT AUTHORITY\SYSTEM @ WIN10X86_1511  10.5.135.201:4567 -> 10.5.134.162:49696 (10.5.134.162)
  9         meterpreter x86/windows  NT AUTHORITY\SYSTEM @ WIN10X86_1709  10.5.135.201:4567 -> 10.5.134.119:49706 (10.5.134.119)
  10        meterpreter x86/windows  NT AUTHORITY\SYSTEM @ WIN10X86_1809  10.5.135.201:4567 -> 10.5.134.117:50439 (10.5.134.117)
  11        meterpreter x86/windows  NT AUTHORITY\SYSTEM @ WIN10X86_21H1  10.5.135.201:4567 -> 10.5.134.189:49748 (10.5.134.189)

msf6 exploit(windows/smb/psexec) > sessions -C sysinfo
[*] Running 'sysinfo' on meterpreter session 1 (10.5.134.103)
Computer        : WIN10X86_1803
OS              : Windows 10 (10.0 Build 17134).
Architecture    : x86
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
[*] Running 'sysinfo' on meterpreter session 2 (10.5.134.109)
Computer        : WIN10X86
OS              : Windows 10 (10.0 Build 10240).
Architecture    : x86
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
[*] Running 'sysinfo' on meterpreter session 5 (10.5.134.131)
Computer        : WIN10X86_2004
OS              : Windows 10 (10.0 Build 19041).
Architecture    : x86
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
[*] Running 'sysinfo' on meterpreter session 6 (10.5.134.144)
Computer        : WIN10X86_1703
OS              : Windows 10 (10.0 Build 15063).
Architecture    : x86
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
[*] Running 'sysinfo' on meterpreter session 7 (10.5.134.147)
Computer        : WIN10X86_1607
OS              : Windows 10 (10.0 Build 14393).
Architecture    : x86
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
[*] Running 'sysinfo' on meterpreter session 8 (10.5.134.162)
Computer        : WIN10X86_1511
OS              : Windows 10 (10.0 Build 10586).
Architecture    : x86
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
[*] Running 'sysinfo' on meterpreter session 9 (10.5.134.119)
Computer        : WIN10X86_1709
OS              : Windows 10 (10.0 Build 16299).
Architecture    : x86
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
[*] Running 'sysinfo' on meterpreter session 10 (10.5.134.117)
Computer        : WIN10X86_1809
OS              : Windows 10 (10.0 Build 17763).
Architecture    : x86
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
[*] Running 'sysinfo' on meterpreter session 11 (10.5.134.189)
Computer        : WIN10X86_21H1
OS              : Windows 10 (10.0 Build 19043).
Architecture    : x86
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
msf6 exploit(windows/smb/psexec) > use post/windows/manage/get_version_info
msf6 post(windows/manage/get_version_info) > set verbose true
verbose => true
msf6 post(windows/manage/get_version_info) > set session 1
session => 1
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 17134
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 2
session => 2
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 10240
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 3
session => 3
msf6 post(windows/manage/get_version_info) > run

[-] Msf::OptionValidateError The following options failed to validate: SESSION
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 4
session => 4
msf6 post(windows/manage/get_version_info) > run

[-] Msf::OptionValidateError The following options failed to validate: SESSION
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 5
session => 5
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 19041
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 6
session => 6
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 15063
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 7
session => 7
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 14393
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 8
session => 8
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 10586
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 9
session => 9
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 16299
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 10
session => 10
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 17763
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 11
session => 11
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 19043
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > 

Shell

msf6 exploit(windows/smb/psexec) > sessions -l

Active sessions
===============

  Id  Name  Type               Information                                        Connection
  --  ----  ----               -----------                                        ----------
  1         shell x86/windows  Shell Banner: Microsoft Windows [Version 10.0.171  10.5.135.201:4567 -> 10.5.134.103:49679 (10.5.134
                               34.1] -----                                        .103)
  2         shell x86/windows  Shell Banner: Microsoft Windows [Version 10.0.102  10.5.135.201:4567 -> 10.5.134.109:49423 (10.5.134
                               40] -----                                          .109)
  3         shell x86/windows  Shell Banner: Microsoft Windows [Version 10.0.177  10.5.135.201:4567 -> 10.5.134.117:49695 (10.5.134
                               63.107] -----                                      .117)
  4         shell x86/windows  Shell Banner: Microsoft Windows [Version 10.0.162  10.5.135.201:4567 -> 10.5.134.119:49685 (10.5.134
                               99.15] -----                                       .119)
  5         shell x86/windows  Shell Banner: Microsoft Windows [Version 10.0.190  10.5.135.201:4567 -> 10.5.134.131:49731 (10.5.134
                               41.208] -----                                      .131)
  6         shell x86/windows  Shell Banner: Microsoft Windows [Version 10.0.150  10.5.135.201:4567 -> 10.5.134.144:49685 (10.5.134
                               63] -----                                          .144)
  7         shell x86/windows  Shell Banner: Microsoft Windows [Version 10.0.143  10.5.135.201:4567 -> 10.5.134.147:49689 (10.5.134
                               93] -----                                          .147)
  8         shell x86/windows  Shell Banner: Microsoft Windows [Version 10.0.105  10.5.135.201:4567 -> 10.5.134.162:49690 (10.5.134
                               86] -----                                          .162)
  9         shell x86/windows  Shell Banner: Microsoft Windows [Version 10.0.190  10.5.135.201:4567 -> 10.5.134.189:49705 (10.5.134
                               43.928] -----                                      .189)
  10        shell x86/windows  Shell Banner: Microsoft Windows [Version 10.0.190  10.5.135.201:4567 -> 10.5.134.193:49788 (10.5.134
                               42.631] -----                                      .193)

msf6 exploit(windows/smb/psexec) > use post/windows/manage/get_version_info
msf6 post(windows/manage/get_version_info) > set verbose true
verbose => true
msf6 post(windows/manage/get_version_info) > set session 1
session => 1
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 17134
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 2
session => 2
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 10240
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 3
session => 3
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 17763
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 4
session => 4
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 16299
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 5
session => 5
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 19041
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 6
session => 6
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 15063
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 7
session => 7
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 14393
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 8
session => 8
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 10586
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 9
session => 9
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 19043
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 10
session => 10
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 19042
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 11
session => 11
msf6 post(windows/manage/get_version_info) > run

[-] Msf::OptionValidateError The following options failed to validate: SESSION
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > 

Powershell

msf6 exploit(windows/smb/psexec) > sessions -l

Active sessions
===============

  Id  Name  Type                Information                     Connection
  --  ----  ----                -----------                     ----------
  1         powershell windows  WIN10X86_1803$ @ WIN10X86_1803  10.5.135.201:4567 -> 10.5.134.103:50112 (10.5.134.103)
  2         powershell windows  WIN10X86$ @ WIN10X86            10.5.135.201:4567 -> 10.5.134.109:49431 (10.5.134.109)
  3         powershell windows  WIN10X86_1709$ @ WIN10X86_1709  10.5.135.201:4567 -> 10.5.134.119:49694 (10.5.134.119)
  4         powershell windows  WIN10X86_2004$ @ WIN10X86_2004  10.5.135.201:4567 -> 10.5.134.131:50352 (10.5.134.131)
  5         powershell windows  WIN10X86_1903$ @ WIN10X86_1903  10.5.135.201:4567 -> 10.5.134.135:49777 (10.5.134.135)
  6         powershell windows  WIN10X86_1703$ @ WIN10X86_1703  10.5.135.201:4567 -> 10.5.134.144:49694 (10.5.134.144)
  7         powershell windows  WIN10X86_1607$ @ WIN10X86_1607  10.5.135.201:4567 -> 10.5.134.147:49693 (10.5.134.147)
  8         powershell windows  WIN10X86_1511$ @ WIN10X86_1511  10.5.135.201:4567 -> 10.5.134.162:49693 (10.5.134.162)
  9         powershell windows  WIN10X86_21H1$ @ WIN10X86_21H1  10.5.135.201:4567 -> 10.5.134.189:49745 (10.5.134.189)
  10        powershell windows  WIN10X86_20H2$ @ WIN10X86_20H2  10.5.135.201:4567 -> 10.5.134.193:50110 (10.5.134.193)

msf6 exploit(windows/smb/psexec) > use post/windows/manage/get_version_info
msf6 post(windows/manage/get_version_info) > set verbose true
verbose => true
msf6 post(windows/manage/get_version_info) > set session 1
session => 1
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows 10+ Build 17134
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 2
session => 2
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows 10+ Build 10240
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 3
session => 3
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows 10+ Build 16299
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 4
session => 4
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows 10+ Build 19041
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 5
session => 5
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows 10+ Build 18362
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 6
session => 6
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows 10+ Build 15063
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 7
session => 7
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows 10+ Build 14393
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 8
session => 8
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows 10+ Build 10586
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 9
session => 9
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows 10+ Build 19043
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 10
session => 10
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows 10+ Build 19042
[*] Post module execution completed

@bwatters-r7
Copy link
Contributor

XP:

msf6 post(windows/manage/get_version_info) > sessions -l

Active sessions
===============

  Id  Name  Type               Information                                        Connection
  --  ----  ----               -----------                                        ----------
  1         shell x86/windows  Shell Banner: Microsoft Windows XP [Version 5.1.2  10.5.135.201:6789 -> 10.5.132.196:1053 (10.5.132.
                               600] -----                                         196)

msf6 post(windows/manage/get_version_info) > run

[*] Windows XP Service Pack 3
[*] Post module execution completed

@bwatters-r7
Copy link
Contributor

Windows Servers with Meterpreter

msf6 exploit(windows/smb/psexec) > sessions -C sysinfo
[*] Running 'sysinfo' on meterpreter session 2 (10.5.134.104)
Computer        : WIN2004X64_2004
OS              : Windows 2016+ (10.0 Build 19041).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
[*] Running 'sysinfo' on meterpreter session 3 (10.5.134.120)
Computer        : WIN2012R2X64
OS              : Windows 2012 R2 (6.3 Build 9600).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
[*] Running 'sysinfo' on meterpreter session 5 (10.5.134.129)
Computer        : WIN2012X64
OS              : Windows 2012 (6.2 Build 9200).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
[*] Running 'sysinfo' on meterpreter session 6 (10.5.134.127)
Computer        : WIN2019X64
OS              : Windows 2016+ (10.0 Build 17763).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
[*] Running 'sysinfo' on meterpreter session 8 (10.5.134.160)
Computer        : WIN1909X64_1909
OS              : Windows 2016+ (10.0 Build 18363).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
[*] Running 'sysinfo' on meterpreter session 9 (10.5.134.168)
[*] 10.5.134.168 - Meterpreter session 9 closed.  Reason: Died
[-] Error running command sysinfo: Rex::TimeoutError Operation timed out.
[*] Running 'sysinfo' on meterpreter session 10 (10.5.134.169)
Computer        : WIN2012R2X64SP1
OS              : Windows 2012 R2 (6.3 Build 9600).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
[*] Running 'sysinfo' on meterpreter session 11 (10.5.134.176)
[*] 10.5.134.176 - Meterpreter session 11 closed.  Reason: Died
[-] Error running command sysinfo: Rex::TimeoutError Operation timed out.
[*] Running 'sysinfo' on meterpreter session 12 (10.5.134.168)
Computer        : WIN1709X64
OS              : Windows 2016+ (10.0 Build 16299).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
[*] Running 'sysinfo' on meterpreter session 13 (10.5.134.176)
Computer        : WIN1903X64_1903
OS              : Windows 2016+ (10.0 Build 18362).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
[*] Running 'sysinfo' on meterpreter session 14 (10.5.134.187)
[-] Error running command sysinfo: Rex::TimeoutError Operation timed out.
[*] Running 'sysinfo' on meterpreter session 15 (10.5.134.187)
Computer        : WIN2016X64
OS              : Windows 2016+ (10.0 Build 14393).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
[*] Running 'sysinfo' on meterpreter session 16 (10.5.134.199)
Computer        : WIN1803X64
OS              : Windows 2016+ (10.0 Build 17134).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
[*] Running 'sysinfo' on meterpreter session 17 (10.5.134.200)
Computer        : WIN1809X64
OS              : Windows 2016+ (10.0 Build 17763).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
msf6 exploit(windows/smb/psexec) > use post/windows/manage/get_version_info
msf6 post(windows/manage/get_version_info) > set verbose true
verbose => true
msf6 post(windows/manage/get_version_info) > set session 1
session => 1
msf6 post(windows/manage/get_version_info) > run

[-] Msf::OptionValidateError The following options failed to validate: SESSION
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 2
session => 2
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2016+ Build 19041
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 3
session => 3
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2012 R2
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 4
session => 4
msf6 post(windows/manage/get_version_info) > run

[-] Msf::OptionValidateError The following options failed to validate: SESSION
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 5
session => 5
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2012
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 6
session => 6
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2016+ Build 17763
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 7
session => 7
msf6 post(windows/manage/get_version_info) > run

[-] Msf::OptionValidateError The following options failed to validate: SESSION
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 8
session => 8
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2016+ Build 18363
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 9
session => 9
msf6 post(windows/manage/get_version_info) > run

[-] Msf::OptionValidateError The following options failed to validate: SESSION
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 10
session => 10
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2012 R2
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 11
session => 11
msf6 post(windows/manage/get_version_info) > run

[-] Msf::OptionValidateError The following options failed to validate: SESSION
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 12
session => 12
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2016+ Build 16299
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 13
session => 13
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2016+ Build 18362
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 14
session => 14
msf6 post(windows/manage/get_version_info) > run
[*] 10.5.134.187 - Meterpreter session 14 closed.  Reason: Died

[-] Post interrupted by the console user
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 15
session => 15
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2016+ Build 14393
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 16
session => 16
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2016+ Build 17134
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 17
session => 17
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2016+ Build 17763
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 18
session => 18
msf6 post(windows/manage/get_version_info) > run

[-] Msf::OptionValidateError The following options failed to validate: SESSION
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > 

@bwatters-r7
Copy link
Contributor

Windows Servers: Shell

msf6 exploit(windows/smb/psexec) > use post/windows/manage/get_version_info
msf6 post(windows/manage/get_version_info) > set verbose true
verbose => true
msf6 post(windows/manage/get_version_info) > set session 1
session => 1
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2016+ Build 19041
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 2
session => 2
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2012 R2
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 3
session => 3
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2016+ Build 17763
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 4
session => 4
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2012
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 5
session => 5
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2016+ Build 18363
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 6
session => 6
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2016+ Build 16299
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 7
session => 7
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2012 R2
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 8
session => 8
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2016+ Build 18362
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 9
session => 9
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2016+ Build 14393
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 10
session => 10
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2016+ Build 17134
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 11
session => 11
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2016+ Build 17763
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 12
session => 12
msf6 post(windows/manage/get_version_info) > run

[-] Msf::OptionValidateError The following options failed to validate: SESSION
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > 

Windows Servers: Powershell

msf6 exploit(windows/smb/psexec) > use post/windows/manage/get_version_info
msf6 post(windows/manage/get_version_info) > set verbose true
verbose => true
msf6 post(windows/manage/get_version_info) > set session 1
session => 1
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows Server 2016+ Build 19041
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 2
session => 2
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows Server 2012 R2
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 3
session => 3
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows Server 2016+ Build 17763
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 4
session => 4
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows Server 2012
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 5
session => 5
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows Server 2016+ Build 18363
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 6
session => 6
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows Server 2016+ Build 16299
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 7
session => 7
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows Server 2012 R2
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 8
session => 8
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows Server 2016+ Build 18362
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 9
session => 9
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows Server 2016+ Build 14393
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 10
session => 10
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows Server 2016+ Build 17134
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > set session 11
session => 11
msf6 post(windows/manage/get_version_info) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: powershell
[!]  * incompatible session architecture: 
[*] Windows Server 2016+ Build 17763
[*] Post module execution completed

@bwatters-r7
Copy link
Contributor

I noticed that this fails to recognize Windows 2000 because the systeminfo command is not present. I tried to code up a quick fix: smashery#1

@bwatters-r7
Copy link
Contributor

I just realized this does not appear to work on non-english versions of Windows:
image

msf6 post(windows/gather/enum_shares) > sessions -i -1
[*] Starting interaction with 1...


Shell Banner:
Microsoft Windows [version 10.0.19044.2006]
-----


C:\Users\H�l�ne\Desktop>
C:\Users\H�l�ne\Desktop>systeminfo
systeminfo

Nom de l'h�te:                              DESKTOP-VUAS6N9
Nom du syst�me d'exploitation:              Microsoft Windows 10 Professionnel
Version du syst�me:                         10.0.19044 N/A build 19044
Fabricant du syst�me d'exploitation:        Microsoft Corporation
Configuration du syst�me d'exploitation:    Station de travail autonome
Type de build du syst�me d'exploitation:    Multiprocessor Free
Propri�taire enregistr�:                    Utilisateur Windows
Organisation enregistr�e:
Identificateur de produit:                  00330-80000-00000-AA199
Date d'installation originale:              04/10/2022, 10:58:03
Heure de d�marrage du syst�me:              04/10/2022, 10:59:55
Fabricant du syst�me:                       VMware, Inc.
Mod�le du syst�me:                          VMware7,1
Type du syst�me:                            x64-based PC
Processeur(s):                              2 processeur(s) install�(s).
                                            [01]�: Intel64 Family 6 Model 158 Stepping 13 GenuineIntel ~2400 MHz
                                            [02]�: Intel64 Family 6 Model 158 Stepping 13 GenuineIntel ~2400 MHz
Version du BIOS:                            VMware, Inc. VMW71.00V.18452719.B64.2108091906, 09/08/2021
R�pertoire Windows:                         C:\Windows
R�pertoire syst�me:                         C:\Windows\system32
P�riph�rique d'amor�age:                    \Device\HarddiskVolume1
Option r�gionale du syst�me:                fr;Fran�ais (France)
Param�tres r�gionaux d'entr�e:              fr;Fran�ais (France)
Fuseau horaire:                             (UTC+00:00) Dublin, �dimbourg, Lisbonne, Londres
M�moire physique totale:                    2�047 Mo
M�moire physique disponible:                381 Mo
M�moire virtuelle�: taille maximale:        4�250 Mo
M�moire virtuelle�: disponible:             730 Mo
M�moire virtuelle�: en cours d'utilisation: 3�520 Mo
Emplacements des fichiers d'�change:        C:\pagefile.sys
Domaine:                                    WORKGROUP
Serveur d'ouverture de session:             \\DESKTOP-VUAS6N9
Correctif(s):                               6 Corrections install�es.
                                            [01]: KB5017262
                                            [02]: KB5003791
                                            [03]: KB5012170
                                            [04]: KB5018410
                                            [05]: KB5014032
                                            [06]: KB5016705
Carte(s) r�seau:                            2 carte(s) r�seau install�e(s).
                                            [01]: Intel(R) 82574L Gigabit Network Connection
                                                  Nom de la connexion�: Ethernet0
                                                  DHCP activ��:         Oui
                                                  Serveur DHCP�:        192.168.175.254
                                                  Adresse(s) IP
                                                  [01]: 192.168.175.132
                                                  [02]: fe80::400e:cba:b193:9eee
                                            [02]: Bluetooth Device (Personal Area Network)
                                                  Nom de la connexion�: Connexion r�seau Bluetooth
                                                  �tat�:                Support d�connect�
Configuration requise pour Hyper-V:         Un hyperviseur a �t� d�tect�. Les fonctionnalit�s n�cessaires � Hyper-V ne seront pas affich�es.

C:\Users\H�l�ne\Desktop>

The bright side is that at least in the French version, the ver command change in the above PR to this PR looks like it would still work get the base information like in Windows 2000, but again, not the service pack version.

C:\Users\H�l�ne\Desktop>ver
ver

Microsoft Windows [version 10.0.19044.2006]

C:\Users\H�l�ne\Desktop>

@bwatters-r7
Copy link
Contributor

I have some ideas on how to fix this, but I don't have time right now. I'm going to mark this as delayed and try and get some time next week to work on it.

@bwatters-r7 bwatters-r7 added the blocked Blocked by one or more additional tasks label Feb 3, 2023
@adfoster-r7
Copy link
Contributor

I've just converted the PR to a draft for now until the PR is rebased against master and the smarter fallback logic is implemented, as well as language-pack agnostic version detection 👍

I'll not add the attic label to this though so we can keep this PR open without losing the comment trail, as sometimes Github gets confused when a PR is closed when there's merge conflicts that get resolved locally and pushed up when the PR is closed

Hopefully Smashery will be free in a few months to pick this up again 🤞

Utilised it in various existing modules - this should fix some subtle bugs in specific modules' version detection.
@smashery smashery marked this pull request as ready for review June 1, 2023 00:47
@smashery
Copy link
Contributor Author

smashery commented Jun 1, 2023

Alright, I re-worked this to succeed on non-English locales. The approach has been to make requests of the registry, as these values are not locale-dependent. Most are just numbers, with the exception of the "Service Pack" registry key, which in my testing on various different OSes and language packs, always says "Service Pack".

Given the duration since the initial work, there was a bit of merging - mostly rubocop stuff. I squashed, rebased and force-pushed since the initial work, but it's all in the first new commit.

I coded up a module like @bwatters-r7 did above, to test just this bit of work, and ran it on various OSes and locales:

Shell

Windows Server 2022 (Spanish)

msf6 post(windows/manage/get_version_info) > run session=4

Windows Server 2016+ Build 20348
(Build number 10.0.20348.0)

Windows 10 22H2 (French)

msf6 post(windows/manage/get_version_info) > run session=2

Windows 10+ Build 19045
(Build number 10.0.19045.0)

Windows Server 2012 (English)

msf6 post(windows/manage/get_version_info) > run session=3

Windows Server 2012
(Build number 6.2.9200.0)

Windows Server 2008 R2 SP1 (English)

msf6 post(windows/manage/get_version_info) > run session=4

Windows 2008 R2 Service Pack 1
(Build number 6.1.7601.1)

Windows Server 2008 SP 2(English)

msf6 post(windows/manage/get_version_info) > run session=1

Windows Server 2008 Service Pack 2
(Build number 6.0.6002.2)

Windows XP SP3 (Italian)

msf6 post(windows/manage/get_version_info) > run session=7

Windows XP Service Pack 3
(Build number 5.1.2600.3)

Windows Server 2003

msf6 post(windows/manage/get_version_info) > run session=10

Windows Server 2003 Service Pack 1
(Build number 5.2.3790.1)

Windows 2000 (German)

msf6 post(windows/manage/get_version_info) > run session=6

Windows 2000
(Build number 5.0.2195.0)

PowerShell

Windows Server 2022 (Spanish)

msf6 post(windows/manage/get_version_info) > run session=29

Windows Server 2016+ Build 20348
(Build number 10.0.20348.0)

Windows Server 2012 (English)

msf6 post(windows/manage/get_version_info) > run session=26

Windows Server 2012
(Build number 6.2.9200.0)

Windows Server 2008 R2 SP1 (English)

msf6 post(windows/manage/get_version_info) > run session=5

Windows 2008 R2 Service Pack 1
(Build number 6.1.7601.1)

Meterpreter

Windows Server 2022 (Spanish)

msf6 post(windows/manage/get_version_info) > run session=18

Windows Server 2016+ Build 20348
(Build number 10.0.20348.0)

Windows 10 22H2 (French)

msf6 post(windows/manage/get_version_info) > run session=14

Windows 10+ Build 19045
(Build number 10.0.19045.0)

Windows Server 2012 (English)

msf6 post(windows/manage/get_version_info) > run session=13

Windows Server 2012
(Build number 6.2.9200.0)

Windows Server 2008 R2 SP1 (English)

msf6 post(windows/manage/get_version_info) > run session=21

Windows 2008 R2 Service Pack 1
(Build number 6.1.7601.1)

Windows Server 2008 (English)

msf6 post(windows/manage/get_version_info) > run session=15

Windows Server 2008 Service Pack 2
(Build number 6.0.6002.2)

Windows XP SP3 (Italian)

msf6 post(windows/manage/get_version_info) > run session=8

Windows XP Service Pack 3
(Build number 5.1.2600.3)

Windows Server 2003

msf6 post(windows/manage/get_version_info) > run session=22

Windows Server 2003 Service Pack 1
(Build number 5.2.3790.1)

@bwatters-r7
Copy link
Contributor

Testing on modern OSs with meterpreter

Windows 10x64
meterpreter > sysinfo
Computer        : WIN10X64_1703
OS              : Windows 10 (10.0 Build 15063).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x64/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 15063
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN10X64_1803
OS              : Windows 10 (10.0 Build 17134).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x64/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 17134
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN10X64_1511
OS              : Windows 10 (10.0 Build 10586).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x64/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 10586
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN10X64
OS              : Windows 10 (10.0 Build 10240).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x64/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 10240
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN10X64_1709
OS              : Windows 10 (10.0 Build 16299).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x64/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 16299
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN10X64_20H2
OS              : Windows 10 (10.0 Build 19042).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x64/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 19042
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN10X64_1809
OS              : Windows 10 (10.0 Build 17763).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x64/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 17763
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN10X64_2004
OS              : Windows 10 (10.0 Build 19041).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x64/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 19041
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN10X64_1607
OS              : Windows 10 (10.0 Build 14393).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x64/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 14393
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN10X64_21H1
OS              : Windows 10 (10.0 Build 19043).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x64/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 19043
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > 

Windows 10x86
meterpreter > sysinfo
Computer        : WIN10X86
OS              : Windows 10 (10.0 Build 10240).
Architecture    : x86
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 10240
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN10X86_1809
OS              : Windows 10 (10.0 Build 17763).
Architecture    : x86
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 17763
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN10X86_2004
OS              : Windows 10 (10.0 Build 19041).
Architecture    : x86
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 19041
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN10X86_1703
OS              : Windows 10 (10.0 Build 15063).
Architecture    : x86
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 15063
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN10X86_1607
OS              : Windows 10 (10.0 Build 14393).
Architecture    : x86
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 14393
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN10X86_1511
OS              : Windows 10 (10.0 Build 10586).
Architecture    : x86
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 10586
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN10X86_1511
OS              : Windows 10 (10.0 Build 10586).
Architecture    : x86
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 10586
[*] Post module execution completed


meterpreter > sysinfo
Computer        : WIN10X86_1709
OS              : Windows 10 (10.0 Build 16299).
Architecture    : x86
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 16299
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN10X86_21H1
OS              : Windows 10 (10.0 Build 19043).
Architecture    : x86
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 19043
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN10X86_20H2
OS              : Windows 10 (10.0 Build 19042).
Architecture    : x86
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 19042
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN10X86_1803
OS              : Windows 10 (10.0 Build 17134).
Architecture    : x86
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 17134
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > 

Servers
meterpreter > sysinfo
Computer        : WIN1809X64
OS              : Windows 2016+ (10.0 Build 17763).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2016+ Build 17763
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN2012X64
OS              : Windows 2012 (6.2 Build 9200).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2012
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN2012R2X64
OS              : Windows 2012 R2 (6.3 Build 9600).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2012 R2
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN2019X64
OS              : Windows 2016+ (10.0 Build 17763).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2016+ Build 17763
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN1709X64
OS              : Windows 2016+ (10.0 Build 16299).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2016+ Build 16299
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN2012R2X64SP1
OS              : Windows 2012 R2 (6.3 Build 9600).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2012 R2
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN2016X64
OS              : Windows 2016+ (10.0 Build 14393).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2016+ Build 14393
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN1803X64
OS              : Windows 2016+ (10.0 Build 17134).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows Server 2016+ Build 17134
[*] Post module execution completed

Windows 8
meterpreter > sysinfo
Computer        : WIN8X86
OS              : Windows 8 (6.2 Build 9200).
Architecture    : x86
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows 8
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN8X64
OS              : Windows 8 (6.2 Build 9200).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows 8
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN81X64SP1
OS              : Windows 8.1 (6.3 Build 9600).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
msf6 post(windows/manage/get_version_info) > run

[*] Windows 8.1
[*] Post module execution completed

meterpreter > sysinfo
Computer        : WIN81X64
OS              : Windows 8.1 (6.3 Build 9600).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
meterpreter > background
[*] Backgrounding session 69...
msf6 exploit(windows/smb/psexec) > use post/windows/manage/get_version_info
msf6 post(windows/manage/get_version_info) > run

[*] Windows 8.1
[*] Post module execution completed
msf6 post(windows/manage/get_version_info) > 

@adfoster-r7
Copy link
Contributor

@smashery Just for visibility; Is it possible to correctly map the details of the 2022 boxes, i.e.

Windows Server 2022 (Spanish)

From:

msf6 post(windows/manage/get_version_info) > run session=4

Windows Server 2016+ Build 20348
(Build number 10.0.20348.0)

To be Windows Server 2022? Instead of 2016+ 👀

@bwatters-r7
Copy link
Contributor

@adfoster-r7 Yes, and no. I can speak from the Meterpreter side, which is what I think @smashery is mimicking. Previously, we would get the friendly name (at least in Meterpreter) by grabbing the versions and then entering a case statement to find the friendly name based off the numeric version.
That was a great thing back when Microsoft only had a new version every couple years and bumped the major or minor release for every new version; it kept breaking when Microsoft decided to go the marketing route and call a new build number of Kernel 10.0 something else, so we'd say "This is kernel 10.0, so it is Windows 2016," but in reality, it was kernel 10.0 and Windows 2019, or Kernel 10.0, Windows 1809 because the major/minor releases were the same.
All Windows servers for most of the last decade- Win15XX to Win20H2 and all the specialized server releases like 2022 all have a major kernel release of 10.0, so basically we have about a dozen or two new names for different builds of the same OS. Rather than play the marketing game of creating a new name for a new build number of the same OS by keeping a table, we just say "this is a Server version 2016+", AKA Kernel 10,0, and here's the build number. That way, we did not have to add a new entry a couple times a year a year to track the "new" server versions.
It also kept us from being wrong because if MS released a Windows Server 23H1, we'd tag it as 22H2 until we edited the code; we ID'd every Server version of Windows 2016 well into 2019, IIRC.
Was this the right call? I think so. We've entered a time when the build number is more important the the name, so I'd be happy with just giving Major/minor/build number values, but that would be a lot less backward compatible, so we kept the friendly names in place, but added the build number.

@adfoster-r7
Copy link
Contributor

Thanks for the context 👍

It looks like I was after the ProductName which is in the registry for the newer versions of windows that I checked, but not sure how far back that support goes - or how reliable it is, and wouldn't be useful for the current meterpreter/railgun implementation

(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ProductName
image

@bwatters-r7
Copy link
Contributor

Russian

msf6 payload(windows/x64/meterpreter/reverse_tcp) > sessions -i -1
[*] Starting interaction with 14...

meterpreter > sysinfo
Computer        : DESKTOP-PVL0VR5
OS              : Windows 10 (10.0 Build 10240).
Architecture    : x64
System Language : ru_RU
Domain          : WORKGROUP
Logged On Users : 2
Meterpreter     : x64/windows
meterpreter > background
[*] Backgrounding session 14...
msf6 payload(windows/x64/meterpreter/reverse_tcp) > use post/windows/manage/get_version_info 
msf6 post(windows/manage/get_version_info) > set session -1
session => -1
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 10240
[*] Post module execution completed

French:

msf6 post(windows/manage/get_version_info) > sessions -i -1
[*] Starting interaction with 15...

meterpreter > sysinfo
Computer        : DESKTOP-7FU6S36
OS              : Windows 10 (10.0 Build 10240).
Architecture    : x64
System Language : fr_FR
Domain          : WORKGROUP
Logged On Users : 2
Meterpreter     : x64/windows
meterpreter > background
[*] Backgrounding session 15...
msf6 post(windows/manage/get_version_info) > set session -1
session => -1
msf6 post(windows/manage/get_version_info) > run

[*] Windows 10+ Build 10240
[*] Post module execution completed

@bwatters-r7
Copy link
Contributor

I think this is ready to land, but to be super safe I'm going to hold off until tomorrow after we cut the release. That'll give us a couple more opportunities to shake out anything before we tag it.

@smashery
Copy link
Contributor Author

smashery commented Jun 8, 2023

@adfoster-r7 - Yeah, we could certainly look up the ProductName value - I can see that is present as far back as Windows 2000. For this mixin, though, I'd say the primary purpose is to be able to do checks for vulnerable ranges, and so doesn't really help us achieve that.

result = get_version_info_impl
if result.nil?
print_error("Couldn't retrieve the target's build number!")
raise RuntimeError.new("Couldn't retrieve the target's build number!")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if this would be useful to use specific exception classes instead of the generic RuntimeError? Maybe something like Msf::Post::Windows::Version::Error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call - have done this.

return nil
end

major, minor, build, unused, revision = groups.captures
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but the convention in ruby is to use underscore for unused variables:

Suggested change
major, minor, build, unused, revision = groups.captures
major, minor, build, _unused, revision = groups.captures

or

Suggested change
major, minor, build, unused, revision = groups.captures
major, minor, build, _, revision = groups.captures

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized the capture group is there only because it is optional and it is never used. You can use (?:…) syntax to group without capturing:

groups = build_num_raw.match(/.*Version\s+(\d+)\.(\d+)\.(\d+)(?:\.(\d+))?/)
major, minor, build, revision = groups.captures

end

major, minor, build, unused, revision = groups.captures
revision = 0 if revision.nil?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like revision is not used anywhere. I might be missing something though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, there are a few places throughout the rest of the codebase where Revision is actually used. I intend to integrate it into the WindowsVersion code, and then use it in those specific locations, but this PR is getting big enough that I will circle back around and just do that. For now I'll remove it.

Comment on lines 79 to 83
when /WinNT/
product_type = Msf::WindowsVersion::VER_NT_WORKSTATION
when /LanmanNT/
product_type = Msf::WindowsVersion::VER_NT_DOMAIN_CONTROLLER
when /ServerNT/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need regex here? I'm under the impression this is a simple string comparison, which is usually preferred when not needed:

Suggested change
when /WinNT/
product_type = Msf::WindowsVersion::VER_NT_WORKSTATION
when /LanmanNT/
product_type = Msf::WindowsVersion::VER_NT_DOMAIN_CONTROLLER
when /ServerNT/
when 'WinNT'
product_type = Msf::WindowsVersion::VER_NT_WORKSTATION
when 'LanmanNT'
product_type = Msf::WindowsVersion::VER_NT_DOMAIN_CONTROLLER
when 'ServerNT'

also, maybe using constants would make sense instead of raw strings here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call.

lib/msf/core/post/windows/version.rb Outdated Show resolved Hide resolved
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? and major >= 6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if service_pack_raw.nil? and major >= 6
if service_pack_raw.nil? && major >= 6

private

def empty_os_version_info_ex
result = [0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result local variable doesn't seem to be used.

Suggested change
result = [0,
[
0,

There is also an indentation issue, it should be 2 spaces:

    [
      0,
      0,
      0,
      ...

0,
0,
0,
"",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"",
'',

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'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a possibility that Railgun raise an exception? or maybe result could be nil? I believe this should be handled to avoid breaking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's certainly conceivable that railgun fails. Looking through the code, this could perhaps be either a Rex::TimeoutError (for a dead session), or a RequestError (e.g. extension failed to load); maybe some other ones - I'd have to look further.

Given it won't be a graceful handling (i.e. we'd need to throw an exception anyway), do you think it's much clearer handling and re-throwing?

I'm also a bit hesitant just because, looking at other usages of railgun throughout the codebase, I don't see that pattern anywhere else; most other places I looked let the exception bubble up, and handle it at the module level anyway.

begin
return session.railgun.shell32.IsUserAnAdmin()['return']
rescue StandardError
true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be out of scope since it was the previous behavior, but I'm wondering if there is a way to distinguish between an error in case the API is not exposed and a Railgun error due to something else (communication failure, process died, etc.). This might not be possible, but I'm worried about always assuming the session is an admin session if something goes wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm a bit concerned about how much this PR already contains - happy to look at this afterwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although thinking about this a bit more, the one case that this is described as being applicable (Windows 2000) doesn't support Meterpreter anymore anyway. It feels like the exception handling here is a bit misguided - it's inferring from the presence of an exception that it's on Windows 2000, and returning true, perhaps because Windows 2000 just treated everyone as an admin? I'd be inclined just to remove that exception handling, given the documented reason for it existing no longer applies.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like the exception handling here is a bit misguided - it's inferring from the presence of an exception that it's on Windows 2000

The intention of the rescue here is to presume the user is an admin if shell32.IsUserAnAdmin() fails. Windows 2000 is not inferred.

This code is in the is_admin? method which is used as a privilege check to bail out prior to attempting operations on the host which are doomed to failure. Historically, in instances where the check failed, it was expected to fail safe so as to not prevent further execution, hence the greedy rescue.

One potential reason that IsUserAnAdmin may fail is due to using an old operating system such as Windows 2000.

Granted, the code is sloppy. If we wanted to always fail safe, we should rescue from method.

@smashery
Copy link
Contributor Author

Thanks for looking at this @cdelafuente-r7 . Most of these came out in a Rubocop; a few other responses above.

@bwatters-r7 bwatters-r7 merged commit 38f5421 into rapid7:master Jun 13, 2023
28 checks passed
@bwatters-r7
Copy link
Contributor

Release Notes

This PR adds new code to simplify and standardize windows version checking and comparisons.

@adfoster-r7 adfoster-r7 added the rn-enhancement release notes enhancement label Jun 16, 2023
@gwillcox-r7 gwillcox-r7 removed the blocked Blocked by one or more additional tasks label Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add library for Windows version normalization and version comparison
7 participants