CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/spec/lib/rex/proto/mssql/client_spec.rb
Views: 11789
1
# -*- coding: binary -*-
2
3
require 'spec_helper'
4
require 'rex/proto/mysql/client'
5
6
RSpec.describe Rex::Proto::MSSQL::Client do
7
let(:host) { '127.0.0.1' }
8
let(:port) { 1234 }
9
let(:info) { "#{host}:#{port}" }
10
let(:db_name) { 'my_db_name' }
11
let(:framework_module) { ::Msf::Module.new }
12
13
subject do
14
client = described_class.new(framework_module, nil, host, port)
15
client.current_database = db_name
16
client
17
end
18
19
it_behaves_like 'session compatible SQL client'
20
21
describe '#map_compile_os_to_platform' do
22
[
23
{ info: 'linux', expected: Msf::Platform::Linux.realname },
24
{ info: 'windows', expected: Msf::Platform::Windows.realname },
25
{ info: 'win', expected: Msf::Platform::Windows.realname },
26
].each do |test|
27
it "correctly identifies '#{test[:info]}' as '#{test[:expected]}'" do
28
expect(subject.map_compile_os_to_platform(test[:info])).to eq(test[:expected])
29
end
30
end
31
end
32
33
describe '#map_compile_arch_to_architecture' do
34
[
35
{ info: 'x64', expected: ARCH_X86_64 },
36
{ info: 'x86', expected: ARCH_X86 },
37
{ info: '64', expected: ARCH_X86_64 },
38
{ info: '32-bit', expected: ARCH_X86 },
39
].each do |test|
40
it "correctly identifies '#{test[:info]}' as '#{test[:expected]}'" do
41
expect(subject.map_compile_arch_to_architecture(test[:info])).to eq(test[:expected])
42
end
43
end
44
end
45
46
describe '#detect_platform_and_arch' do
47
[
48
{ 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) <X64>', expected: { arch: 'x86_64', platform: 'Linux' } },
49
{ 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 <X64> (Build 20348: ) (Hypervisor)', expected: { arch: 'x86_64', platform: 'Windows' } },
50
{ 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' } },
51
{ version: 'unknown', expected: { arch: 'unknown', platform: 'unknown' } },
52
].each do |test|
53
context "when the database is version #{test[:version]}" do
54
it "returns #{test[:expected]}" do
55
mock_query_result = { rows: [[test[:version]]] }
56
allow(subject).to receive(:query).with('select @@version').and_return(mock_query_result)
57
58
expect(subject.detect_platform_and_arch).to eq test[:expected]
59
end
60
end
61
end
62
end
63
describe '#current_database' do
64
context 'we have not selected a database yet' do
65
subject do
66
described_class.new(framework_module, nil, host, port)
67
end
68
69
it 'returns an empty database name' do
70
expect(subject.current_database).to eq('')
71
end
72
end
73
end
74
75
context '#parse_prelogin_response' do
76
let(:buf) { "\x00\x00\x15\x00\x06\x01\x00\e\x00\x01\x02\x00\x1C\x00\x01\x03\x00\x1D\x00\x00\xFF\x10\x00\x03\xE8\x00\x00\x02\x00" }
77
let(:client) { Rex::Proto::MSSQL::Client.allocate }
78
79
it 'correctly parses a prelogin response' do
80
result = client.parse_prelogin_response(buf)
81
expect(result).to eq({ version: '16.0.1000', encryption: 2 })
82
end
83
end
84
end
85
86