Command shell now working in the GUI

git-svn-id: file:///home/svn/framework3/trunk@4340 4d416f70-5f16-0410-b530-b9f4589650da
unstable
HD Moore 2007-02-10 05:01:48 +00:00
parent 590fede74c
commit 1bf2db7a56
4 changed files with 84 additions and 42 deletions

View File

@ -11,26 +11,39 @@ class BidirectionalPipe < Rex::IO::BidirectionalPipe
def initialize(buffer)
@buffer = buffer
if (not @buffer.get_mark('end_mark')
@buffer.create_mark('end_mark', @buffer.end_iter, false)
end
super()
end
def print_error(msg)
@buffer.insert_at_cursor('[-] ' + msg)
@buffer.insert(@buffer.end_iter, '[-] ' + msg)
print_line
scroll_line
end
def print_line(msg = "")
@buffer.insert_at_cursor(msg + "\n")
@buffer.insert(@buffer.end_iter, msg + "\n")
scroll_line
end
def print_good(msg)
@buffer.insert_at_cursor('[+] ' + msg)
@buffer.insert(@buffer.end_iter, '[+] ' + msg)
print_line
scroll_line
end
def print_status(msg)
@buffer.insert_at_cursor('[*] ' + msg)
@buffer.insert(@buffer.end_iter, '[*] ' + msg)
print_line
scroll_line
end
def scroll_line
@buffer.move_mark('end_mark', @buffer.end_iter)
@textview.scroll_mark_onscreen(@buffer.get_mark('end_mark'))
end
protected

View File

@ -420,7 +420,7 @@ class MsfAssistant
pipe = Msf::Ui::Gtk2::Stream::GtkConsolePipe.new(@buffer)
input = pipe.fd
input = pipe.pipe_input
output = pipe
@mydriver.exploit.init_ui(input, output)

View File

@ -9,12 +9,14 @@ class Console < MyGlade
super('console2')
@textview.set_buffer(buffer)
@textview.editable = false
@buffer = buffer
@buffer = buffer
@session = session
@input = input
@output = output
@pipe = pipe
@input = input
@output = output
@pipe = pipe
# Create a read subscriber
@pipe.create_subscriber(@session.sid)
@ -23,13 +25,42 @@ class Console < MyGlade
@output.print_line("\n")
@session.init_ui(@input, @output)
Thread.new{@session.interact}
# One thread to interact
@t_mon = Thread.new do
@session.interact
end
# Another to monitor the output and update the UI
@t_rdr = Thread.new do
if (not @buffer.get_mark('end_mark'))
@buffer.create_mark('end_mark', @buffer.end_iter, false)
end
while(true)
data = @pipe.read_subscriber(@session.sid)
if (data and data.length > 0)
@buffer.insert(@buffer.end_iter, data)
@buffer.move_mark('end_mark', @buffer.end_iter)
@textview.scroll_mark_onscreen(@buffer.get_mark('end_mark'))
else
select(nil, nil, nil, 0.10)
end
end
end
if @console2.run == Gtk::Dialog::RESPONSE_OK
puts "ok"
@console2.destroy
end
# Kill off the helper threads
@t_rdr.kill
@t_mon.kill
update_access
@ -57,17 +88,16 @@ class Console < MyGlade
update_access
# Puts cmd
puts cmd
@input.put(cmd)
@pipe.read_subscriber(@session.sid)
# Write the command plus a newline to the input
@input.put(cmd + "\n")
# Clear entry
@cmd_entry.set_text("")
end
end
require 'rex/io/bidirectional_pipe'
class GtkConsolePipe < Rex::IO::BidirectionalPipe
attr_accessor :input

View File

@ -7,7 +7,6 @@ module Msf
module Ui
module Web
require 'msf/ui/web/comm'
require 'rex/io/bidirectional_pipe'
###
@ -30,7 +29,7 @@ class WebConsole
attr_accessor :output
attr_accessor :prompt
attr_accessor :killed
def eof?
self.pipe_input.eof?
end
@ -42,24 +41,24 @@ class WebConsole
def supports_readline
false
end
def _print_prompt
end
def pgets
self.pipe_input.gets
end
end
#
# Provides some overrides for web-based consoles
#
module WebConsoleShell
def supports_color?
false
end
end
@ -70,7 +69,7 @@ class WebConsole
# Configure the ID
self.console_id = console_id
# Create a new pipe
# Create a new pipe
self.pipe = WebConsolePipe.new
self.pipe.input = self.pipe.pipe_input
@ -83,16 +82,16 @@ class WebConsole
'>',
{
'Framework' => self.framework,
'LocalInput' => self.pipe,
'LocalInput' => self.pipe,
'LocalOutput' => self.pipe,
'AllowCommandPassthru' => false,
}
)
self.console.extend(WebConsoleShell)
self.thread = Thread.new { self.console.run }
update_access()
end
@ -110,26 +109,26 @@ class WebConsole
update_access
self.pipe.write_input(buf)
end
def execute(cmd)
self.console.run_single(cmd)
end
def prompt
self.pipe.prompt
end
def tab_complete(cmd)
self.console.tab_complete(cmd)
end
def shutdown
self.pipe.killed = true
self.pipe.close
self.thread.kill
end
end
###
#
# This class implements a user interface driver on a web interface.
@ -140,7 +139,7 @@ class Driver < Msf::Ui::Driver
attr_accessor :framework # :nodoc:
attr_accessor :consoles # :nodoc:
attr_accessor :last_console # :nodoc:
attr_accessor :last_console # :nodoc:
ConfigCore = "framework/core"
ConfigGroup = "framework/ui/web"
@ -162,39 +161,39 @@ class Driver < Msf::Ui::Driver
# Initialize configuration
Msf::Config.init
# Initialize logging
initialize_logging
# Initialize attributes
self.framework = Msf::Simple::Framework.create
# Initialize the console count
self.last_console = 0
# Give the comm an opportunity to set up so that it can receive
# notifications about session creation and so on.
# notifications about session creation and so on.
Comm.setup(framework)
end
def create_console
# Destroy any unused consoles
clean_consoles
console = WebConsole.new(self.framework, self.last_console)
self.last_console += 1
self.consoles[console.console_id.to_s] = console
self.consoles[console.console_id.to_s] = console
console.console_id.to_s
end
def write_console(id, buf)
self.consoles[id] ? self.consoles.write(buf) : nil
end
def read_console(id)
self.consoles[id] ? self.consoles.read() : nil
end
def clean_consoles(timeout=300)
self.consoles.each_pair do |id, con|
if (con.last_access + timeout < Time.now)
@ -203,7 +202,7 @@ class Driver < Msf::Ui::Driver
end
end
end
#
# Stub
#