From fa6ce27b9cc41958ba298598756cb63ff04a04bb Mon Sep 17 00:00:00 2001 From: Zach Goldman Date: Tue, 23 Apr 2024 12:42:45 -0400 Subject: [PATCH] adds pattern to catch other arch and platform values --- lib/rex/proto/mssql/client.rb | 6 ++++-- spec/lib/rex/proto/mssql/client_spec.rb | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/rex/proto/mssql/client.rb b/lib/rex/proto/mssql/client.rb index d4beb01ee6df7..128c71b0e8a4e 100644 --- a/lib/rex/proto/mssql/client.rb +++ b/lib/rex/proto/mssql/client.rb @@ -116,9 +116,11 @@ def detect_platform_and_arch result = {} server_vars = query('select @@version')[:rows][0][0] + arch = server_vars.match(/\b\d+\.\d+\.\d+\.\d+\s\((?[^)]*)\)/)[:arch] || server_vars + plat = server_vars.match(/\bon\b\s+(?\w+)/)[:plat] || server_vars - result[:arch] = map_compile_arch_to_architecture(server_vars) - result[:platform] = map_compile_os_to_platform(server_vars) + result[:arch] = map_compile_arch_to_architecture(arch) + result[:platform] = map_compile_os_to_platform(plat) result end diff --git a/spec/lib/rex/proto/mssql/client_spec.rb b/spec/lib/rex/proto/mssql/client_spec.rb index fa68f461e87d1..5d1547a6e8df1 100644 --- a/spec/lib/rex/proto/mssql/client_spec.rb +++ b/spec/lib/rex/proto/mssql/client_spec.rb @@ -47,6 +47,7 @@ [ { version: 'Microsoft SQL Server 2022 (RTM-CU12) (KB5033663) - 16.0.4115.5 (X64) Mar 4 2024 08:56:10 Copyright (C) 2022 Microsoft Corporation Developer Edition (64-bit) on Linux (Ubuntu 22.04.4 LTS) ', expected: { arch: 'x86_64', platform: 'Linux' } }, { version: 'Microsoft SQL Server 2022 (RTM) - 16.0.1000.6 (X64) Oct 8 2022 05:58:25 Copyright (C) 2022 Microsoft Corporation Developer Edition (64-bit) on Windows Server 2022 Standard 10.0 (Build 20348: ) (Hypervisor)', expected: { arch: 'x86_64', platform: 'Windows' } }, + { version: 'Microsoft SQL Server 2022 (RTM) - 16.0.1000.6 (32) Oct 8 2022 05:58:25 Copyright (C) 2022 Microsoft Corporation Developer Edition (2-bit) on Mac Standard 10.0 (Build 20348: ) (Hypervisor)', expected: { arch: '32', platform: 'mac' } }, ].each do |test| context "when the database is version #{test[:version]}" do it "returns #{test[:expected]}" do