From a453760aa4d2e922583c0be7d4b04a75a0302687 Mon Sep 17 00:00:00 2001 From: William Vu Date: Wed, 17 Oct 2018 15:19:31 -0500 Subject: [PATCH 1/3] Add PTY option to Net::SSH::CommandStream This allows us to spawn a PTY for our shell session. Note that this will write us to {u,w}tmp and lastlog, so use this option with care. And yes, I did change the API, but up until now, we've been using only the first two parameters. We should be using keyword args. /shrug --- lib/net/ssh/command_stream.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/net/ssh/command_stream.rb b/lib/net/ssh/command_stream.rb index 18642896ed..e908d33e5f 100644 --- a/lib/net/ssh/command_stream.rb +++ b/lib/net/ssh/command_stream.rb @@ -38,16 +38,14 @@ class CommandStream self.channel = channel end - def initialize(ssh, cmd = nil, cleanup = false) - + def initialize(ssh, cmd = nil, pty = false, cleanup = false) self.lsock, self.rsock = Rex::Socket.tcp_socket_pair() self.lsock.extend(Rex::IO::Stream) self.lsock.extend(PeerInfo) self.rsock.extend(Rex::IO::Stream) self.ssh = ssh - self.thread = Thread.new(ssh,cmd,cleanup) do |rssh, rcmd, rcleanup| - + self.thread = Thread.new(ssh,cmd,pty,cleanup) do |rssh, rcmd, rpty, rcleanup| begin info = rssh.transport.socket.getpeername_as_array self.lsock.peerinfo = "#{info[1]}:#{info[2]}" @@ -56,6 +54,8 @@ class CommandStream self.lsock.localinfo = "#{info[1]}:#{info[2]}" rssh.open_channel do |rch| + # A PTY will write us to {u,w}tmp and lastlog + rch.request_pty if rpty if rcmd.nil? rch.send_channel_request("shell", &method(:shell_requested)) else From 1e1950c83d6e525c403ccd1b2713bf2426557f30 Mon Sep 17 00:00:00 2001 From: William Vu Date: Wed, 17 Oct 2018 15:40:46 -0500 Subject: [PATCH 2/3] Prefer keyword args after all SINCE we've been using only the first two params, we're fine! --- lib/net/ssh/command_stream.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/net/ssh/command_stream.rb b/lib/net/ssh/command_stream.rb index e908d33e5f..5f639d6a6d 100644 --- a/lib/net/ssh/command_stream.rb +++ b/lib/net/ssh/command_stream.rb @@ -38,7 +38,7 @@ class CommandStream self.channel = channel end - def initialize(ssh, cmd = nil, pty = false, cleanup = false) + def initialize(ssh, cmd = nil, pty: false, cleanup: false) self.lsock, self.rsock = Rex::Socket.tcp_socket_pair() self.lsock.extend(Rex::IO::Stream) self.lsock.extend(PeerInfo) From 6fd53fcb6a047e7bdcb628cdc597ade7dd8e3f9a Mon Sep 17 00:00:00 2001 From: William Vu Date: Wed, 17 Oct 2018 15:45:02 -0500 Subject: [PATCH 3/3] Fix whitespace further --- lib/net/ssh/command_stream.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/net/ssh/command_stream.rb b/lib/net/ssh/command_stream.rb index 5f639d6a6d..0bf40ff864 100644 --- a/lib/net/ssh/command_stream.rb +++ b/lib/net/ssh/command_stream.rb @@ -45,7 +45,7 @@ class CommandStream self.rsock.extend(Rex::IO::Stream) self.ssh = ssh - self.thread = Thread.new(ssh,cmd,pty,cleanup) do |rssh, rcmd, rpty, rcleanup| + self.thread = Thread.new(ssh, cmd, pty, cleanup) do |rssh, rcmd, rpty, rcleanup| begin info = rssh.transport.socket.getpeername_as_array self.lsock.peerinfo = "#{info[1]}:#{info[2]}"