diff --git a/data/msfgui/msfgui.glade b/data/msfgui/msfgui.glade index a1cbc20f76..bb5aa56193 100644 --- a/data/msfgui/msfgui.glade +++ b/data/msfgui/msfgui.glade @@ -615,166 +615,4 @@ - - True - - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - True - False - True - False - False - GDK_WINDOW_TYPE_HINT_DIALOG - GDK_GRAVITY_NORTH_WEST - True - False - True - - - - True - False - 0 - - - - True - GTK_BUTTONBOX_END - - - - True - True - True - gtk-close - True - GTK_RELIEF_NORMAL - True - -7 - - - - - 0 - False - True - GTK_PACK_END - - - - - - True - False - 0 - - - - True - True - GTK_POLICY_ALWAYS - GTK_POLICY_ALWAYS - GTK_SHADOW_IN - GTK_CORNER_TOP_LEFT - - - - 400 - 300 - True - True - True - False - True - GTK_JUSTIFY_LEFT - GTK_WRAP_NONE - True - 0 - 0 - 0 - 0 - 0 - 0 - - - - - - 0 - True - True - - - - - - 15 - True - False - 0 - - - - True - >>> - False - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - True - True - True - True - 0 - - True - * - False - - - - 0 - True - True - - - - - 0 - False - True - - - - - 0 - True - True - - - - - - diff --git a/data/msfgui/style/console.rc b/data/msfgui/style/console.rc index f250d529be..aec229faa8 100644 --- a/data/msfgui/style/console.rc +++ b/data/msfgui/style/console.rc @@ -10,4 +10,4 @@ style "console2" } # Attach style with the specific widget name -widget "console2.*.textview" style "console2" +widget_class "GtkWindow.GtkVBox.GtkScrolledWindow.GtkTextView" style "console2" diff --git a/lib/msf/ui/gtk2/console.rb b/lib/msf/ui/gtk2/console.rb new file mode 100644 index 0000000000..7ac5dc172c --- /dev/null +++ b/lib/msf/ui/gtk2/console.rb @@ -0,0 +1,193 @@ +module Msf +module Ui +module Gtk2 + +class Console + require 'rex/io/bidirectional_pipe' + + ID_SESSION, PEER, PAYLOAD, O_SESSION, O_BUFFER = *(0..5).to_a + + # + # Classic console herited from Gtk::Window + # + class Basic < Gtk::Window + include Msf::Ui::Gtk2::MyControls + + def initialize(iter) + + # Style + console_style = File.join(driver.resource_directory, 'style', 'console.rc') + Gtk::RC.parse(console_style) + + super(Gtk::Window::TOPLEVEL) + + @session = iter[O_SESSION] + @buffer = iter[O_BUFFER] + + # Layout stuff + self.set_default_size(500, 400) + self.set_border_width(10) + + # Set title with the tunnel peer + self.set_title(@session.tunnel_peer) + + # Skeleton ;-) + vbox = Gtk::VBox.new(false, 5) + self.add(vbox) + + @textview = Gtk::TextView.new + scrolled_window = Gtk::ScrolledWindow.new + scrolled_window.add(@textview) + vbox.pack_start(scrolled_window, true, true, 5) + scrolled_window.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC) + + @cmd_entry = Gtk::Entry.new + vbox.pack_start(@cmd_entry, false, false, 0) + + hbox = Gtk::HButtonBox.new + hbox.layout_style = Gtk::ButtonBox::END + button = Gtk::Button.new(Gtk::Stock::CLOSE) + button.signal_connect("clicked") do + close_console + end + hbox.pack_end(button, false, false, 5) + vbox.pack_start(hbox, false, false, 0) + + @textview.set_buffer(@buffer) + @textview.editable = false + @textview.set_cursor_visible(false) + @buffer.create_mark('end_mark', @buffer.end_iter, false) + + # Give focus to Gtk::Entry + @cmd_entry.can_focus = true + @cmd_entry.grab_focus() + + # Signal + @cmd_entry.signal_connect('activate') do + on_cmd_entry_activate + end + + # Create the pipe interface + @pipe = Rex::IO::BidirectionalPipe.new + + # Start the session interaction + @t_run = Thread.new do + @session.interact(@pipe, @pipe) + end + + # Create a subscriber with a callback for the UI + @sid = @pipe.create_subscriber_proc() do |data| + @buffer.insert(@buffer.end_iter, Rex::Text.to_utf8(data)) + @buffer.move_mark('end_mark', @buffer.end_iter) + @textview.scroll_mark_onscreen(@buffer.get_mark('end_mark')) + end + + #Gtk::RC.parse(console_style) + + self.show_all + + # Kill the interaction thread + #@t_run.kill + + # Close the pipes + #@pipe.close + + end + + # + # update access + # + def update_access + last_access = Time.now + end + + # + # Signal for user entry + # + def on_cmd_entry_activate + send_cmd(@cmd_entry.text) + end + + # + # Send command to bidirectionnal_pipe + # + def send_cmd(cmd) + + update_access + + # Write the command plus a newline to the input + @pipe.write_input(cmd + "\n") + + # Clear the text entry + @cmd_entry.set_text("") + end + + # + # Just close the console, not kill ! + # + def close_console + self.destroy + end + end + + # + # Meterpreter Console + # TODO: Motivated to code it, hehe ... Ho YESSS ;-) + # + class MeterBasic < Gtk::Window + + def inititialize + nil + end + end +end + + + +class GtkConsolePipe < Rex::IO::BidirectionalPipe + + + attr_accessor :input + attr_accessor :output + attr_accessor :prompt + attr_accessor :buffer + attr_accessor :tree + + def initialize(buffer) + self.buffer = buffer + super() + end + + def eof? + self.pipe_input.eof? + end + + def intrinsic_shell? + true + end + + def supports_readline + false + end + + def _print_prompt + end + + def pgets + self.pipe_input.gets + end + + def print_line(msg = "") + print(msg + "\n") + end + + def print(msg = "") + self.buffer.insert(self.buffer.end_iter, Time.now.strftime("%H:%m:%S") + " " + Rex::Text.to_utf8(msg)) + end + +end + +end +end +end + diff --git a/lib/msf/ui/gtk2/driver.rb b/lib/msf/ui/gtk2/driver.rb index 65b222b975..296a937983 100644 --- a/lib/msf/ui/gtk2/driver.rb +++ b/lib/msf/ui/gtk2/driver.rb @@ -7,7 +7,7 @@ require 'msf/ui/gtk2/app' require 'msf/ui/gtk2/about' require 'msf/ui/gtk2/frame' require 'msf/ui/gtk2/dialogs' -require 'msf/ui/gtk2/stream' +require 'msf/ui/gtk2/console' require 'msf/ui/gtk2/view' require 'msf/ui/gtk2/search' diff --git a/lib/msf/ui/gtk2/frame.rb b/lib/msf/ui/gtk2/frame.rb index 68b13fb91f..c28b87f56e 100644 --- a/lib/msf/ui/gtk2/frame.rb +++ b/lib/msf/ui/gtk2/frame.rb @@ -396,7 +396,6 @@ class MyJobTree < MyGlade # Stop job and remove it from the job tree # def stop_job(iter) - puts iter[REFNAME] framework.jobs.each_key do |i| if (framework.jobs[i].name.split(": ")[1] == iter[REFNAME]) @@ -576,7 +575,7 @@ class MySessionTree # Open the session with the selected iter # def open_session(iter) - Msf::Ui::Gtk2::Stream::Console.new(iter) + Msf::Ui::Gtk2::Console::Basic.new(iter) end # diff --git a/lib/msf/ui/gtk2/stream.rb b/lib/msf/ui/gtk2/stream.rb deleted file mode 100644 index 5d176fa157..0000000000 --- a/lib/msf/ui/gtk2/stream.rb +++ /dev/null @@ -1,11 +0,0 @@ -module Msf -module Ui -module Gtk2 -module Stream - -require 'msf/ui/gtk2/stream/console' - -end -end -end -end diff --git a/lib/msf/ui/gtk2/stream/console.rb b/lib/msf/ui/gtk2/stream/console.rb deleted file mode 100644 index a9f443f5aa..0000000000 --- a/lib/msf/ui/gtk2/stream/console.rb +++ /dev/null @@ -1,153 +0,0 @@ -module Msf -module Ui -module Gtk2 -module Stream - -class Console < MyGlade - - require 'rex/io/bidirectional_pipe' - - ID_SESSION, PEER, PAYLOAD, O_SESSION, O_BUFFER = *(0..5).to_a - - def initialize(iter) - - # Style - console_style = File.join(driver.resource_directory, 'style', 'console.rc') - Gtk::RC.parse(console_style) - - super('console2') - - @session = iter[O_SESSION] - @buffer = iter[O_BUFFER] - - @textview.set_buffer(@buffer) - @textview.editable = false - @textview.set_cursor_visible(false) - @buffer.create_mark('end_mark', @buffer.end_iter, false) - - # Give focus to Gtk::Entry - @cmd_entry.can_focus = true - @cmd_entry.grab_focus() - - # Create the pipe interface - @pipe = Rex::IO::BidirectionalPipe.new - - # Start the session interaction - @t_run = Thread.new do - @session.interact(@pipe, @pipe) - end - - # Create a subscriber with a callback for the UI - @sid = @pipe.create_subscriber_proc() do |data| - @buffer.insert(@buffer.end_iter, Rex::Text.to_utf8(data)) - @buffer.move_mark('end_mark', @buffer.end_iter) - @textview.scroll_mark_onscreen(@buffer.get_mark('end_mark')) - end - - # Run the console interface - res = @console2.run - - # Kill the interaction thread - @t_run.kill - - # Close the pipes - @pipe.close - - # Determine how we were closed - case res - when Gtk::Dialog::RESPONSE_CLOSE - close_console - else - end - - - end - - # - # update access - # - def update_access - last_access = Time.now - end - - # - # Signal for user entry - # - def on_cmd_entry_activate - send_cmd(@cmd_entry.text) - end - - # - # Send command to bidirectionnal_pipe - # - def send_cmd(cmd) - - update_access - - # Write the command plus a newline to the input - @pipe.write_input(cmd + "\n") - - # Clear the text entry - @cmd_entry.set_text("") - end - - # - # Just close the console, not kill ! - # - def close_console - @console2.destroy - end -end - - - -class GtkConsolePipe < Rex::IO::BidirectionalPipe - - - attr_accessor :input - attr_accessor :output - attr_accessor :prompt - attr_accessor :buffer - attr_accessor :tree - - def initialize(buffer) - self.buffer = buffer - super() - end - - def eof? - self.pipe_input.eof? - end - - def intrinsic_shell? - true - end - - def supports_readline - false - end - - def _print_prompt - end - - def pgets - self.pipe_input.gets - end - - def print_line(msg = "") - print(msg + "\n") - end - - def print(msg = "") - self.buffer.insert(self.buffer.end_iter, Time.now.strftime("%H:%m:%S") + " " + Rex::Text.to_utf8(msg)) - end - -end - - - -end -end -end -end -