1
mirror of https://github.com/rapid7/metasploit-framework synced 2024-11-12 11:52:01 +01:00

Prepare the Gtk Meterpreter console

Gtk Console swicth to Gtk::Window
Now, in the same time, we could open multiple sessions
Remove old console stuff (code and glade)



git-svn-id: file:///home/svn/framework3/trunk@4500 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
fab 2007-03-01 22:09:01 +00:00
parent 36ae1a736e
commit 8f6498038a
7 changed files with 196 additions and 330 deletions

View File

@ -615,166 +615,4 @@
</child>
</widget>
<widget class="GtkDialog" id="console2">
<property name="visible">True</property>
<property name="title" translatable="yes"></property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<property name="has_separator">True</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox8">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area8">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="cancelbutton5">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-close</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">-7</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
<child>
<widget class="GtkVBox" id="vbox7">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow15">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">GTK_POLICY_ALWAYS</property>
<property name="vscrollbar_policy">GTK_POLICY_ALWAYS</property>
<property name="shadow_type">GTK_SHADOW_IN</property>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkTextView" id="textview">
<property name="width_request">400</property>
<property name="height_request">300</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="overwrite">False</property>
<property name="accepts_tab">True</property>
<property name="justification">GTK_JUSTIFY_LEFT</property>
<property name="wrap_mode">GTK_WRAP_NONE</property>
<property name="cursor_visible">True</property>
<property name="pixels_above_lines">0</property>
<property name="pixels_below_lines">0</property>
<property name="pixels_inside_wrap">0</property>
<property name="left_margin">0</property>
<property name="right_margin">0</property>
<property name="indent">0</property>
<property name="text" translatable="yes"></property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkHBox" id="hbox4">
<property name="border_width">15</property>
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkLabel" id="label24">
<property name="visible">True</property>
<property name="label" translatable="yes">&gt;&gt;&gt;</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="cmd_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="has_frame">True</property>
<property name="invisible_char">*</property>
<property name="activates_default">False</property>
<signal name="activate" handler="on_cmd_entry_activate"/>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>

View File

@ -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"

193
lib/msf/ui/gtk2/console.rb Normal file
View File

@ -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

View File

@ -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'

View File

@ -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
#

View File

@ -1,11 +0,0 @@
module Msf
module Ui
module Gtk2
module Stream
require 'msf/ui/gtk2/stream/console'
end
end
end
end

View File

@ -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