Skip to content

Commit

Permalink
scripting support
Browse files Browse the repository at this point in the history
  • Loading branch information
alhazred committed Dec 27, 2011
1 parent 22fe88e commit 701f209
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 15 deletions.
13 changes: 13 additions & 0 deletions meta_ssh/lib/msf/scripts/meta_ssh.rb
@@ -0,0 +1,13 @@
require 'msf/scripts/meta_ssh/common'
require 'msf/scripts/meta_ssh/file'
require 'msf/scripts/meta_ssh/accounts'

module Msf
module Scripts
module MetaSSH



end
end
end
16 changes: 16 additions & 0 deletions meta_ssh/lib/msf/scripts/meta_ssh/accounts.rb
@@ -0,0 +1,16 @@
require 'msf/core/post/linux/system'
require 'msf/core/post/linux/priv'

module Msf
module Scripts
module MetaSSH
module Common

include ::Msf::Post::Linux::System
include ::Msf::Post::Linux::Priv

end
end
end
end

17 changes: 17 additions & 0 deletions meta_ssh/lib/msf/scripts/meta_ssh/common.rb
@@ -0,0 +1,17 @@

module Msf
module Scripts
module MetaSSH
module Common

def cmd_exec(cmd,opts=nil,timeout=15)
::Timeout::timeout(timeout) {
return session.sys.execute(cmd,opts)
}
end

end
end
end
end

42 changes: 42 additions & 0 deletions meta_ssh/lib/msf/scripts/meta_ssh/file.rb
@@ -0,0 +1,42 @@
require 'msf/core/post/file'

module Msf
module Scripts
module MetaSSH
module Common

include ::Msf::Post::File

def write_file(file_name, data)
fd = session.fs.file.new(file_name, "wb")
fd.write(data)
fd.close
return true
end

def append_file(file_name, data)
fd = session.fs.file.new(file_name, "wab")
fd.write(data)
fd.close
return true
end

def read_file(file_name)
fd = session.fs.file.new(file_name, "rb")
data = ''
begin
until fd.eof?
data << fd.read
end
ensure
fd.close
end
data
end


end
end
end
end

16 changes: 4 additions & 12 deletions meta_ssh/lib/rex/post/meta_ssh/client.rb
Expand Up @@ -6,6 +6,7 @@
require 'rex/post/meta_ssh/client_core'
require 'rex/post/meta_ssh/object_aliases'
require 'rex/script'
require 'rex/script/meta_ssh'
require 'rex/logging'

module Rex
Expand All @@ -20,10 +21,10 @@ module Extensions

###
#
# This class represents a logical meterpreter client class. This class
# This class represents a logical metaSSH client class. This class
# provides an interface that is compatible with the Rex post-exploitation
# interface in terms of the feature set that it attempts to expose. This
# class is meant to drive a single meterpreter client session.
# class is meant to drive a single metaSSH client session.
#
###
class Client
Expand Down Expand Up @@ -74,7 +75,6 @@ def initialize(ssh,opts={})
# Cleans up the meterpreter instance, terminating the dispatcher thread.
#
def cleanup_ssh
puts "klean up"
self.fs.sftp.cleanup unless self.fs.nil? or self.fs.sftp.nil?
ext.aliases.each_value do | extension |
extension.cleanup if extension.respond_to?( 'cleanup' )
Expand Down Expand Up @@ -314,15 +314,7 @@ def unicode_filter_decode(str)
#
# The Communication Timeout
#
attr_accessor :comm_timeout
#
# The Passive Dispatcher
#
attr_accessor :passive_dispatcher
#
# Flag indicating whether to hex-encode UTF-8 file names and other strings
#
attr_accessor :encode_unicode
attr_accessor :comm_timeout

protected
attr_accessor :parser, :ext_aliases # :nodoc:
Expand Down
Expand Up @@ -165,7 +165,6 @@ def File.download_file(dest_file, src_file)
def initialize(name, mode = "r", perms = nil)
self.client = self.class.client
self.filed = _open(name, mode, perms)
STDOUT.puts "file created class #{self.filed.class.name}"
end

##
Expand Down
2 changes: 2 additions & 0 deletions meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/sys.rb
Expand Up @@ -42,6 +42,8 @@ def exec(cmd,args=[])
return out
end

alias :execute :exec

protected

attr_accessor :client # :nodoc:
Expand Down
@@ -1,6 +1,9 @@
require 'rex/post/meta_ssh'

require 'msf/scripts/meta_ssh'
require 'msf/scripts/meta_ssh/common'
require 'msf/scripts/meta_ssh/file'
require 'rex/parser/arguments'
require 'msf/base/simple/post'

module Rex
module Post
Expand Down Expand Up @@ -261,7 +264,13 @@ def cmd_run(*args)
return
end
opts = (args + [ "SESSION=#{client.sid}" ]).join(',')
mod.run_simple(

# monkeypatch the mod to use our cmd_exec etc

mod=mod.dup
mod.extend(Msf::Scripts::MetaSSH::Common)
mod.extend(Msf::Simple::Post)
mod.run_simple(
#'RunAsJob' => true,
'LocalInput' => shell.input,
'LocalOutput' => shell.output,
Expand Down
15 changes: 15 additions & 0 deletions meta_ssh/lib/rex/script/meta_ssh.rb
@@ -0,0 +1,15 @@

module Rex
module Script
class MetaSSH < Base

begin
require 'msf/scripts/meta_ssh'
include Msf::Scripts::MetaSSH::Common
rescue ::LoadError
end

end
end
end

0 comments on commit 701f209

Please sign in to comment.