Class: Rex::Proto::MsTds::Channel

Inherits:
Object
  • Object
show all
Includes:
IO::StreamAbstraction
Defined in:
lib/rex/proto/ms_tds/channel.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Channel

Returns a new instance of Channel.

Raises:

  • (RuntimeError)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rex/proto/ms_tds/channel.rb', line 14

def initialize(opts = {})
  @params = Rex::Socket::Parameters.from_hash(opts)

  # it doesn't work this way so throw an exception so that's clear
  raise RuntimeError.new('SSL incompatible with MsTds::Socket') if @params.ssl
  raise ArgumentError.new('MsTds::Socket must be TCP') if @params.proto != 'tcp'

  @sock = Rex::Socket.create_param(@params)
  initialize_abstraction

  lsock.initinfo(@sock.peerinfo, @sock.localinfo)

  monitor_sock(@sock, sink: method(:_read_handler), name: 'MonitorLocal', on_exit: method(:_exit_handler))
end

Instance Attribute Details

#params ⇒ Object (readonly)

Returns the value of attribute params.



9
10
11
# File 'lib/rex/proto/ms_tds/channel.rb', line 9

def params
  @params
end

#sock ⇒ Object (readonly)

the socket that makes the outbound connection to the SQL server



12
13
14
# File 'lib/rex/proto/ms_tds/channel.rb', line 12

def sock
  @sock
end

Instance Method Details

#_exit_handler ⇒ Object (protected)



57
58
59
60
# File 'lib/rex/proto/ms_tds/channel.rb', line 57

def _exit_handler
  # Wake the socket-pair relay so it can close its own source socket.
  rsock.shutdown(::Socket::SHUT_RDWR) unless rsock.closed?
end

#_read_handler(buf) ⇒ Object (protected)



62
63
64
65
66
67
68
# File 'lib/rex/proto/ms_tds/channel.rb', line 62

def _read_handler(buf)
  if negotiating_ssl?
    Rex::IO::RelayManager.io_write_all(self.rsock, buf[8..]) + 8
  else
    Rex::IO::RelayManager.io_write_all(self.rsock, buf)
  end
end

#close_write ⇒ void

This method returns an undefined value.

Stop the transport when the local stream reaches EOF. Wake its reader so the server-socket relay can close its own source.



44
45
46
# File 'lib/rex/proto/ms_tds/channel.rb', line 44

def close_write
  sock.shutdown(::Socket::SHUT_RDWR) unless sock.closed?
end

#negotiating_ssl? ⇒ Boolean (protected)

Returns:

  • (Boolean)


50
51
52
53
54
55
# File 'lib/rex/proto/ms_tds/channel.rb', line 50

def negotiating_ssl?
  return false unless self.lsock.is_a?(Rex::Socket::SslTcp)
  return false if self.lsock.sslsock.state.start_with?('SSLOK')

  true
end

#starttls ⇒ Object



37
38
39
# File 'lib/rex/proto/ms_tds/channel.rb', line 37

def starttls
  self.lsock.starttls(params)
end

#write(buf, opts = {}) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/rex/proto/ms_tds/channel.rb', line 29

def write(buf, opts = {})
  if negotiating_ssl?
    Rex::IO::RelayManager.io_write_all(self.sock, [18, 0x01, buf.length + 8, 0x0000, 0x00, 0x00].pack('CCnnCC') + buf) - 8
  else
    Rex::IO::RelayManager.io_write_all(self.sock, buf)
  end
end