Remove the temporary msgpack client/server, this is replaced by v10/client.rb and v10/service.rb respectively
git-svn-id: file:///home/svn/framework3/trunk@12759 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
3a4b5a02fb
commit
c1996206f2
|
@ -1,78 +0,0 @@
|
|||
require "xmlrpc/client"
|
||||
require "msgpack"
|
||||
|
||||
require "rex"
|
||||
require "rex/proto/http"
|
||||
|
||||
module Msf
|
||||
module RPC
|
||||
|
||||
# Loosely based on the XMLRPC::ClientS class
|
||||
# Reimplemented for Metasploit
|
||||
|
||||
class MessagePackClient
|
||||
|
||||
attr_accessor :sock, :token, :info
|
||||
|
||||
|
||||
def initialize(info={})
|
||||
self.info = {
|
||||
:host => '127.0.0.1',
|
||||
:port => 55552,
|
||||
:uri => '/api',
|
||||
:ssl => false,
|
||||
:ssl_version => 'SSLv3'
|
||||
}.merge(info)
|
||||
|
||||
self.token = self.info[:token]
|
||||
end
|
||||
|
||||
|
||||
def login(user,pass)
|
||||
res = self.call("auth.login", user, pass)
|
||||
if(not (res and res['result'] == "success"))
|
||||
raise RuntimeError, "authentication failed"
|
||||
end
|
||||
self.token = res['token']
|
||||
true
|
||||
end
|
||||
|
||||
# Prepend the authentication token as the first parameter
|
||||
# of every call except auth.login. Requires the
|
||||
def call(meth, *args)
|
||||
if(meth != "auth.login")
|
||||
if(not self.token)
|
||||
raise RuntimeError, "client not authenticated"
|
||||
end
|
||||
args.unshift(self.token)
|
||||
end
|
||||
|
||||
args.unshift(meth)
|
||||
|
||||
cli = Rex::Proto::Http::Client.new(info[:host], info[:port], info[:ssl], info[:ssl_version])
|
||||
cli.set_config(:vhost => info[:host])
|
||||
req = cli.request_cgi(
|
||||
'method' => 'POST',
|
||||
'uri' => self.info[:uri],
|
||||
'ctype' => 'binary/message-pack',
|
||||
'data' => args.to_msgpack
|
||||
)
|
||||
|
||||
res = cli.send_recv(req)
|
||||
|
||||
if res and res.code == 200
|
||||
return MessagePack.unpack(res.body)
|
||||
else
|
||||
raise RuntimeError, res.inspect
|
||||
end
|
||||
end
|
||||
|
||||
def close
|
||||
self.sock.close rescue nil
|
||||
self.sock = nil
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,151 +0,0 @@
|
|||
|
||||
# We reuse the XMLRPC::Exception class for fault handling
|
||||
require 'xmlrpc/server'
|
||||
|
||||
require 'msgpack'
|
||||
|
||||
require 'rex'
|
||||
require 'rex/service_manager'
|
||||
|
||||
|
||||
module Msf
|
||||
module RPC
|
||||
|
||||
class MessagePackService
|
||||
|
||||
attr_accessor :service, :state, :srvhost, :srvport, :uri, :options
|
||||
attr_accessor :handlers, :default_handler, :method_blacklist
|
||||
attr_accessor :dispatcher_timeout, :debug
|
||||
|
||||
def initialize(host, port, options={})
|
||||
self.dispatcher_timeout = 7200
|
||||
self.handlers = {}
|
||||
self.options = {
|
||||
:ssl => false,
|
||||
:cert => nil,
|
||||
:key => nil,
|
||||
:uri => "/uri"
|
||||
}.merge(options)
|
||||
|
||||
self.srvhost = host
|
||||
self.srvport = port
|
||||
self.uri = self.options[:uri]
|
||||
self.debug = self.options[:debug]
|
||||
self.method_blacklist = (Object.methods + Object.new.methods).uniq.map{|x| x.to_s }
|
||||
self.state
|
||||
end
|
||||
|
||||
def start
|
||||
self.state = {}
|
||||
self.service = Rex::ServiceManager.start(
|
||||
Rex::Proto::Http::Server,
|
||||
self.srvport,
|
||||
self.srvhost,
|
||||
{}
|
||||
)
|
||||
|
||||
uopts = {
|
||||
'Proc' => Proc.new { |cli, req|
|
||||
on_request_uri(cli, req)
|
||||
},
|
||||
'Path' => self.uri
|
||||
}
|
||||
|
||||
self.service.add_resource(self.uri,uopts)
|
||||
end
|
||||
|
||||
def stop
|
||||
self.state = {}
|
||||
self.service.stop
|
||||
end
|
||||
|
||||
def wait
|
||||
self.service.wait
|
||||
end
|
||||
|
||||
def on_request_uri(cli, req)
|
||||
res = Rex::Proto::Http::Response.new()
|
||||
res["Content-Type"] = "binary/message-pack"
|
||||
|
||||
begin
|
||||
res.body = process(req.body).to_msgpack
|
||||
rescue XMLRPC::FaultException => e
|
||||
elog("RPC Exception: #{e.class} #{e} #{e.backtrace} #{cli.inspect} #{req.inspect}")
|
||||
res.body = process_exception(e).to_msgpack
|
||||
end
|
||||
cli.send_response(res)
|
||||
end
|
||||
|
||||
def add_handler(group, handler)
|
||||
self.handlers[group] = handler
|
||||
end
|
||||
|
||||
|
||||
def process(data)
|
||||
msg = nil
|
||||
|
||||
begin
|
||||
msg = MessagePack.unpack(data)
|
||||
|
||||
if not (msg and msg.kind_of?(::Array) and msg.length > 0)
|
||||
raise ArgumentError, "Invalid Message Format"
|
||||
end
|
||||
|
||||
group, funct = msg.shift.split(".", 2)
|
||||
|
||||
|
||||
if self.debug and group == "debug" and funct == "methods"
|
||||
res = []
|
||||
self.handlers.each_pair do |k,v|
|
||||
(v.methods.sort.map{|x| x.to_s} - self.method_blacklist).each do |m|
|
||||
res << "#{k}.#{m}"
|
||||
end
|
||||
end
|
||||
return res
|
||||
end
|
||||
|
||||
if not self.handlers[group]
|
||||
raise ArgumentError, "Unknown API Call"
|
||||
end
|
||||
|
||||
if not ( self.handlers[group] and self.handlers[group].respond_to?(funct) )
|
||||
raise ArgumentError, "Unknown API Call"
|
||||
end
|
||||
|
||||
if self.method_blacklist.include?(funct)
|
||||
raise ArgumentError, "Prohibited Method Call"
|
||||
end
|
||||
|
||||
|
||||
::Timeout.timeout(self.dispatcher_timeout) { self.handlers[group].send(funct, *msg) }
|
||||
|
||||
rescue ::Exception => e
|
||||
elog("RPC Exception: #{e.class} #{e} #{e.backtrace} #{msg.inspect} #{data.inspect}")
|
||||
process_exception(e)
|
||||
end
|
||||
end
|
||||
|
||||
def process_exception(e)
|
||||
r = {
|
||||
:result => 'error',
|
||||
:error_class => e.class.to_s,
|
||||
:error_string => e.to_s,
|
||||
:error_backtrace => e.backtrace
|
||||
}
|
||||
|
||||
if e.respond_to?(:faultString)
|
||||
r[:fault_string] = e.faultString
|
||||
end
|
||||
|
||||
if e.respond_to?(:faultCode)
|
||||
r[:fault_code] = e.faultCode
|
||||
end
|
||||
|
||||
r
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue