Permalink
Browse files

cleaned up core, added stdapi/sys

  • Loading branch information...
1 parent 089845c commit d1daaef6f03cb1f8eb691d81fee9cf3dc70c59b9 alhazred committed Dec 27, 2011
View
@@ -0,0 +1 @@
+* Ports must remain forwarded by the ssh client until metaSSH session closes, removing the forwarded ports kills pivoted sessions
@@ -20,7 +20,7 @@ class Channel
- attr_accessor :channel, :thread, :error, :ssh, :on_exit_signal, :on_exit_status
+ attr_accessor :channel, :thread, :error, :ssh, :on_exit_signal, :on_exit_status, :type, :info
attr_accessor :lsock, :rsock, :cid, :client, :monitor
module PeerInfo
@@ -35,7 +35,9 @@ def initialize(client, cleanup = false, &block)
self.lsock.extend(Rex::IO::Stream)
self.lsock.extend(PeerInfo)
self.rsock.extend(Rex::IO::Stream)
- self.client=client
+ self.type=""
+ self.info=""
+ self.client=client
self.client.add_channel(self)
self.thread = Thread.new(client.ssh, cleanup) do |rssh,rcleanup|
@@ -127,6 +129,7 @@ def exec(*args)
def close
begin
+ self.client.remove_channel(self)
self.monitor.kill if self.monitor
self.thread.kill if self.thread
self.channel.close
@@ -87,7 +87,15 @@ def cleanup_ssh
def add_channel(c)
c.cid=new_cid
- self.channels << c
+ self.channels[c.cid.to_s]=c
+ end
+
+ def remove_channel(c)
+ self.channels.delete(c.cid.to_s)
+ end
+
+ def find_channel(c)
+ return self.channels[c.to_s]
end
def new_cid
@@ -102,7 +110,7 @@ def new_cid
def init_ssh(ssh,opts={})
@cid_n=0
self.ssh = ssh
- self.channels=[]
+ self.channels={}
self.expiration = opts[:expiration]
self.comm_timeout = opts[:comm_timeout]
self.ext = ObjectAliases.new
@@ -7,6 +7,7 @@
require 'rex/post/meta_ssh/extensions/stdapi/fs/file'
require 'rex/post/meta_ssh/extensions/stdapi/fs/file_stat'
require 'rex/post/meta_ssh/extensions/stdapi/fs/dir'
+require 'rex/post/meta_ssh/extensions/stdapi/sys'
module Rex
module Post
@@ -47,10 +48,14 @@ def initialize(client)
{
'sftp' => Rex::Post::MetaSSH::Extensions::Stdapi::Fs::Sftp.new(client),
'file' => self.file,
- 'filestat' => self.file_stat,
+ 'filestat' => self.file_stat,
'dir' => self.dir
})
- }
+ },
+
+ { 'name' => 'sys',
+ 'ext' => Rex::Post::MetaSSH::Extensions::Stdapi::Sys.new(client)
+ },
])
end
@@ -0,0 +1,52 @@
+#!/usr/bin/env ruby
+
+require 'thread'
+require 'rex/socket'
+require 'rex/post/meta_ssh/extensions/stdapi/net/socket_subsystem/tcp_client_channel'
+require 'rex/post/meta_ssh/extensions/stdapi/net/socket_subsystem/tcp_server_channel'
+require 'rex/logging'
+
+module Rex
+module Post
+module MetaSSH
+module Extensions
+module Stdapi
+
+
+###
+#
+# This class provides an interface to interacting the system itself
+#
+###
+
+
+class Sys
+
+public
+
+ def initialize(client)
+ self.client=client
+ end
+
+ def exec(cmd,args=[])
+ args=[] if args.nil?
+ full_cmd="#{cmd} #{args.map{|a| "\"#{a}\""}.join(' ')}"
+ out=""
+ chan=self.client.ssh.exec(full_cmd) do |ch, stream, data|
+ out+=data
+ end
+ loop do
+ Rex::ThreadSafe.sleep(0.2)
+ break if chan.eof? or !chan.active?
+ end
+ return out
+ end
+
+protected
+
+ attr_accessor :client # :nodoc:
+
+end
+
+end; end; end; end; end;
+
Oops, something went wrong.

0 comments on commit d1daaef

Please sign in to comment.