From 6547fdb4c4946ff46603a94d11bc90a24042e650 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 | 8 +++++--- spec/lib/rex/proto/mssql/client_spec.rb | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/rex/proto/mssql/client.rb b/lib/rex/proto/mssql/client.rb index d4beb01ee6df..af679caf3e6d 100644 --- a/lib/rex/proto/mssql/client.rb +++ b/lib/rex/proto/mssql/client.rb @@ -115,10 +115,12 @@ def map_compile_arch_to_architecture(server_info) def detect_platform_and_arch result = {} - server_vars = query('select @@version')[:rows][0][0] + version_string = query('select @@version')[:rows][0][0] + arch = version_string[/\b\d+\.\d+\.\d+\.\d+\s\(([^)]*)\)/, 1] || version_string + plat = version_string[/\bon\b\s+(\w+)/, 1] || version_string - 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 fa68f461e87d..27a7203e1945 100644 --- a/spec/lib/rex/proto/mssql/client_spec.rb +++ b/spec/lib/rex/proto/mssql/client_spec.rb @@ -47,6 +47,8 @@ [ { 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' } }, + { version: 'unknown', expected: { arch: 'unknown', platform: 'unknown' } }, ].each do |test| context "when the database is version #{test[:version]}" do it "returns #{test[:expected]}" do