2010-02-25 06:26:53 +00:00
|
|
|
require 'pp'
|
|
|
|
require 'rex'
|
|
|
|
require 'msf/ui/web/driver'
|
|
|
|
|
|
|
|
module Msf
|
|
|
|
module RPC
|
|
|
|
class Console < Base
|
|
|
|
|
|
|
|
def initialize(framework,tokens,users)
|
|
|
|
super(framework, tokens, users)
|
|
|
|
@console_driver = Msf::Ui::Web::Driver.new(:framework => framework)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create(token)
|
|
|
|
authenticate(token)
|
|
|
|
cid = @console_driver.create_console
|
2010-02-25 14:14:48 +00:00
|
|
|
{
|
|
|
|
'id' => cid,
|
2010-03-11 19:49:39 +00:00
|
|
|
'prompt' => Rex::Text.encode_base64(@console_driver.consoles[cid].prompt || ''),
|
|
|
|
'busy' => @console_driver.consoles[cid].busy || false,
|
|
|
|
'encoding' => "base64"
|
2010-02-25 14:14:48 +00:00
|
|
|
}
|
2010-02-25 06:26:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def list(token)
|
|
|
|
authenticate(token)
|
2010-02-25 14:14:48 +00:00
|
|
|
ret = []
|
2010-03-11 19:49:39 +00:00
|
|
|
@console_driver.consoles.each_key do |cid|
|
2010-02-25 14:14:48 +00:00
|
|
|
ret << {
|
2010-03-11 19:49:39 +00:00
|
|
|
'id' => cid,
|
|
|
|
'prompt' => Rex::Text.encode_base64(@console_driver.consoles[cid].prompt || ''),
|
|
|
|
'busy' => @console_driver.consoles[cid].busy || false,
|
|
|
|
'encoding' => "base64"
|
2010-02-25 14:14:48 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
{'consoles' => ret}
|
2010-02-25 06:26:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy(token, cid)
|
|
|
|
authenticate(token)
|
|
|
|
return { 'result' => 'failure' } if not @console_driver.consoles[cid]
|
|
|
|
res = @console_driver.destroy_console(cid)
|
|
|
|
{ 'result' => res ? 'success' : 'failure' }
|
|
|
|
end
|
|
|
|
|
|
|
|
def read(token, cid)
|
|
|
|
authenticate(token)
|
|
|
|
return { 'result' => 'failure' } if not @console_driver.consoles[cid]
|
|
|
|
{
|
2010-03-11 19:49:39 +00:00
|
|
|
"data" => Rex::Text.encode_base64(@console_driver.read_console(cid) || ''),
|
|
|
|
"prompt" => Rex::Text.encode_base64(@console_driver.consoles[cid].prompt || ''),
|
|
|
|
"busy" => @console_driver.consoles[cid].busy || false,
|
|
|
|
"encoding" => "base64"
|
2010-02-25 06:26:53 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def write(token, cid, data)
|
|
|
|
authenticate(token)
|
|
|
|
return { 'result' => 'failure' } if not @console_driver.consoles[cid]
|
2010-03-11 19:49:39 +00:00
|
|
|
{ "wrote" => @console_driver.write_console(cid, Rex::Text.decode_base64(data || '')) }
|
2010-02-25 06:26:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def tabs(token, cid, line)
|
|
|
|
authenticate(token)
|
|
|
|
return { 'result' => 'failure' } if not @console_driver.consoles[cid]
|
|
|
|
{ "tabs" => @console_driver.consoles[cid].tab_complete(line) }
|
|
|
|
end
|
|
|
|
|
2010-02-25 14:14:48 +00:00
|
|
|
def session_kill(token, cid)
|
2010-02-25 06:26:53 +00:00
|
|
|
authenticate(token)
|
|
|
|
return { 'result' => 'failure' } if not @console_driver.consoles[cid]
|
2010-02-25 14:14:48 +00:00
|
|
|
@console_driver.consoles[cid].session_kill
|
|
|
|
{ 'result' => 'success' }
|
2010-02-25 06:26:53 +00:00
|
|
|
end
|
|
|
|
|
2010-02-25 14:14:48 +00:00
|
|
|
def session_detach(token, cid)
|
2010-02-25 06:26:53 +00:00
|
|
|
authenticate(token)
|
|
|
|
return { 'result' => 'failure' } if not @console_driver.consoles[cid]
|
2010-02-25 14:14:48 +00:00
|
|
|
@console_driver.consoles[cid].session_detach
|
|
|
|
{ 'result' => 'success' }
|
2010-02-25 06:26:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|