Class: Msf::Sessions::SshCommandShellBind::TcpClientChannel
- Inherits:
-
Object
- Object
- Msf::Sessions::SshCommandShellBind::TcpClientChannel
- Includes:
- Rex::Post::Channel::StreamAbstraction
- Defined in:
- lib/msf/base/sessions/ssh_command_shell_bind.rb
Overview
This is a Metasploit Framework channel object that wraps a Net::SSH native channel object.
Defined Under Namespace
Modules: SocketInterface
Instance Attribute Summary collapse
-
#cid ⇒ Object
readonly
Returns the value of attribute cid.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #close ⇒ Object
- #close_write ⇒ Object
- #closed? ⇒ Boolean
-
#initialize(client, cid, ssh_channel, params) ⇒ TcpClientChannel
constructor
Create a new TcpClientChannel instance.
-
#write(buf, length = nil) ⇒ Object
Write buf to the channel, optionally truncating it to length bytes.
Methods included from Rex::Post::Channel::StreamAbstraction
Constructor Details
#initialize(client, cid, ssh_channel, params) ⇒ TcpClientChannel
Create a new TcpClientChannel instance.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/msf/base/sessions/ssh_command_shell_bind.rb', line 55 def initialize(client, cid, ssh_channel, params) initialize_abstraction @client = client @cid = cid @ssh_channel = ssh_channel @params = params @mutex = Mutex.new ssh_channel.on_close do |_ch| dlog('ssh_channel#on_close closing the sock') close end ssh_channel.on_data do |_ch, data| # dlog("ssh_channel#on_data received #{data.length} bytes") rsock.syswrite(data) end ssh_channel.on_eof do |_ch| dlog('ssh_channel#on_eof shutting down the socket') rsock.shutdown(Socket::SHUT_WR) end lsock.extend(SocketInterface) lsock.channel = self rsock.extend(SocketInterface) rsock.channel = self lsock.extend(Rex::Socket::SslTcp) if params.ssl && !params.server # synchronize access so the socket isn't closed while initializing, this is particularly important for SSL lsock.synchronize_access { lsock.initsock(params) } rsock.synchronize_access { rsock.initsock(params) } client.add_channel(self) end |
Instance Attribute Details
#cid ⇒ Object (readonly)
Returns the value of attribute cid.
138 139 140 |
# File 'lib/msf/base/sessions/ssh_command_shell_bind.rb', line 138 def cid @cid end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
138 139 140 |
# File 'lib/msf/base/sessions/ssh_command_shell_bind.rb', line 138 def client @client end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
138 139 140 |
# File 'lib/msf/base/sessions/ssh_command_shell_bind.rb', line 138 def params @params end |
Instance Method Details
#close ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/msf/base/sessions/ssh_command_shell_bind.rb', line 98 def close cid = @cid @mutex.synchronize do return if closed? @cid = nil end @client.remove_channel(cid) cleanup_abstraction @ssh_channel.close end |
#close_write ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/msf/base/sessions/ssh_command_shell_bind.rb', line 111 def close_write if closed? raise IOError, 'Channel has been closed.', caller end @ssh_channel.eof! end |
#closed? ⇒ Boolean
94 95 96 |
# File 'lib/msf/base/sessions/ssh_command_shell_bind.rb', line 94 def closed? @cid.nil? end |
#write(buf, length = nil) ⇒ Object
Write buf to the channel, optionally truncating it to length bytes.
125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/msf/base/sessions/ssh_command_shell_bind.rb', line 125 def write(buf, length = nil) if closed? raise IOError, 'Channel has been closed.', caller end if !length.nil? && buf.length >= length buf = buf[0..length] end @ssh_channel.send_data(buf) buf.length end |