Class: Rex::Proto::MsTds::Channel
- Inherits:
-
Object
- Object
- Rex::Proto::MsTds::Channel
- Includes:
- IO::StreamAbstraction
- Defined in:
- lib/rex/proto/ms_tds/channel.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#sock ⇒ Object
readonly
the socket that makes the outbound connection to the SQL server.
Instance Method Summary collapse
- #_exit_handler ⇒ Object protected
- #_read_handler(buf) ⇒ Object protected
-
#initialize(opts = {}) ⇒ Channel
constructor
A new instance of Channel.
- #negotiating_ssl? ⇒ Boolean protected
- #starttls ⇒ Object
- #write(buf, opts = {}) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Channel
Returns a new instance of Channel.
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)
50 51 52 |
# File 'lib/rex/proto/ms_tds/channel.rb', line 50 def _exit_handler self.rsock.close end |
#_read_handler(buf) ⇒ Object (protected)
54 55 56 57 58 59 60 |
# File 'lib/rex/proto/ms_tds/channel.rb', line 54 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 |
#negotiating_ssl? ⇒ Boolean (protected)
43 44 45 46 47 48 |
# File 'lib/rex/proto/ms_tds/channel.rb', line 43 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 |