Skip to content

Commit

Permalink
Add postgres client specs
Browse files Browse the repository at this point in the history
  • Loading branch information
dwelch-r7 committed Apr 4, 2024
1 parent 9e722ba commit 6388350
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 61 deletions.
18 changes: 0 additions & 18 deletions lib/msf/base/sessions/mssql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

class Msf::Sessions::MSSQL < Msf::Sessions::Sql

# @return [String] The address MSSQL is running on
attr_accessor :address
# @return [Integer] The port MSSQL is running on
attr_accessor :port
attr_reader :framework

def initialize(rstream, opts = {})
Expand Down Expand Up @@ -40,18 +36,4 @@ def self.can_cleanup_files
def desc
'MSSQL'
end

def address
return @address if @address

@address, @port = client.peerinfo.split(':')
@address
end

def port
return @port if @port

@address, @port = client.peerinfo.split(':')
@port
end
end
16 changes: 0 additions & 16 deletions lib/msf/base/sessions/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,4 @@ def self.can_cleanup_files
def desc
'MySQL'
end

# @return [Object] The peer address
def address
return @address if @address

@address, @port = @client.peerinfo.split(':')
@address
end

# @return [Object] The peer host
def port
return @port if @port

@address, @port = @client.peerinfo.split(':')
@port
end
end
14 changes: 0 additions & 14 deletions lib/msf/base/sessions/postgresql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,4 @@ def self.can_cleanup_files
def desc
'PostgreSQL'
end

def address
return @address if @address

@address, @port = @client.peerinfo.split(':')
@address
end

def port
return @port if @port

@address, @port = @client.peerinfo.split(':')
@port
end
end
8 changes: 4 additions & 4 deletions lib/msf/base/sessions/sql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ def desc
raise ::NotImplementedError
end

# @return [Object] The peer address
# @return [String] The peer address
def address
raise ::NotImplementedError
client.peerhost
end

# @return [Object] The peer host
# @return [Integer] The peer port
def port
raise ::NotImplementedError
client.peerport
end

# Initializes the console's I/O handles.
Expand Down
2 changes: 1 addition & 1 deletion modules/auxiliary/scanner/mysql/mysql_login.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def int_version(str)
def session_setup(result, client)
return unless (result && client)

my_session = Msf::Sessions::MySQL.new(client.socket, { client: client })
my_session = Msf::Sessions::MySQL.new(client.io, { client: client })
merging = {
'USERPASS_FILE' => nil,
'USER_FILE' => nil,
Expand Down
4 changes: 3 additions & 1 deletion spec/lib/msf/base/sessions/mssql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
let(:description) { 'MSSQL' }
let(:can_cleanup_files) { false }
let(:address) { '192.0.2.1' }
let(:port) { '1433' }
let(:port) { 1433 }
let(:peer_info) { "#{address}:#{port}" }
let(:console) do
console = Rex::Post::MSSQL::Ui::Console.new(session)
Expand All @@ -29,6 +29,8 @@
allow(user_input).to receive(:output=)
allow(client).to receive(:initial_info_for_envchange).with({ envchange: 1 }).and_return(envchange_result)
allow(client).to receive(:peerinfo).and_return(peer_info)
allow(client).to receive(:peerport).and_return(port)
allow(client).to receive(:peerhost).and_return(address)
end

it_behaves_like 'client session'
Expand Down
4 changes: 3 additions & 1 deletion spec/lib/msf/base/sessions/mysql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
let(:description) { 'MySQL' }
let(:can_cleanup_files) { false }
let(:address) { '192.0.2.1' }
let(:port) { '3306' }
let(:port) { 3306 }
let(:peerinfo) { "#{address}:#{port}" }
let(:current_database) { 'database_name' }

before(:each) do
allow(user_input).to receive(:output=)
allow(user_input).to receive(:intrinsic_shell?).and_return(true)
allow(client).to receive(:peerinfo).and_return(peerinfo)
allow(client).to receive(:peerport).and_return(port)
allow(client).to receive(:peerhost).and_return(address)
allow(client).to receive(:current_database).and_return(current_database)
allow(::Rex::Proto::MySQL::Client).to receive(:connect).and_return(client)
end
Expand Down
2 changes: 2 additions & 0 deletions spec/lib/msf/base/sessions/postgresql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
allow(user_input).to receive(:intrinsic_shell?).and_return(true)
allow(user_input).to receive(:output=)
allow(client).to receive(:peerinfo).and_return(peer_info)
allow(client).to receive(:peerhost).and_return(address)
allow(client).to receive(:peerport).and_return(port)
allow(client).to receive(:params).and_return({ 'database' => current_database })
allow(client).to receive(:current_database).and_return(current_database)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/msf/base/sessions/smb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
let(:description) { 'SMB' }
let(:can_cleanup_files) { false }
let(:address) { '192.0.2.1' }
let(:port) { '1337' }
let(:port) { 1337 }
let(:peer_info) { "#{address}:#{port}" }

before(:each) do
Expand Down
10 changes: 5 additions & 5 deletions spec/lib/msf/core/option_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
end

it 'validates the options in the group' do
expect { subject.validate(options, datastore) }.not_to raise_error(Msf::OptionValidateError)
expect { subject.validate(options, datastore) }.not_to raise_error
end
end

Expand All @@ -78,7 +78,7 @@
end

it 'validates the options in the group' do
expect { subject.validate(options, datastore) }.not_to raise_error(Msf::OptionValidateError)
expect { subject.validate(options, datastore) }.not_to raise_error
end
end

Expand All @@ -89,7 +89,7 @@
end

it 'does not attempt to validate the options' do
expect { subject.validate(options, datastore) }.not_to raise_error(Msf::OptionValidateError)
expect { subject.validate(options, datastore) }.not_to raise_error
end
end
end
Expand Down Expand Up @@ -118,7 +118,7 @@
end

it 'validates the options in the group' do
expect { subject.validate(options, datastore) }.not_to raise_error(Msf::OptionValidateError)
expect { subject.validate(options, datastore) }.not_to raise_error
end
end

Expand All @@ -129,7 +129,7 @@
end

it 'does not attempt to validate the options' do
expect { subject.validate(options, datastore) }.not_to raise_error(Msf::OptionValidateError)
expect { subject.validate(options, datastore) }.not_to raise_error
end
end
end
Expand Down
23 changes: 23 additions & 0 deletions spec/lib/rex/proto/postgresql/client_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: binary -*-

require 'spec_helper'
require 'postgres/postgres-pr/connection'

RSpec.describe Msf::Db::PostgresPR::Connection do
let(:host) { '127.0.0.1' }
let(:port) { 1234 }
let(:info) { "#{host}:#{port}" }
let(:db_name) { 'my_db_name' }
let(:socket) { double(Rex::Socket, peerhost: host, peerport: port) }
let(:message) { Msf::Db::PostgresPR::ReadyForQuery.new('') }

subject do
allow(socket).to receive(:<<)
allow(Msf::Db::PostgresPR::Message).to receive(:read).and_return(message)
allow(Rex::Socket).to receive(:create).and_return(socket)
client = described_class.new(db_name, 'username', 'password', "tcp://#{host}:#{port}")
client
end

it_behaves_like 'session compatible SQL client'
end

0 comments on commit 6388350

Please sign in to comment.