2007-05-12 15:36:37 +00:00
|
|
|
module Msf
|
2007-05-12 16:10:22 +00:00
|
|
|
module Ui
|
|
|
|
module Gtk2
|
2007-05-12 15:36:37 +00:00
|
|
|
|
2007-05-12 16:10:22 +00:00
|
|
|
class MyJobTree < MyGlade
|
2007-06-24 19:48:09 +00:00
|
|
|
PIX, JID, NAME = *(0..3).to_a
|
2007-05-12 16:10:22 +00:00
|
|
|
|
|
|
|
include Msf::Ui::Gtk2::MyControls
|
|
|
|
|
2007-06-24 19:48:09 +00:00
|
|
|
#
|
|
|
|
# This module help us to modify the Rex::JobContainer class behavior
|
|
|
|
#
|
|
|
|
module ModifiedJobContainer
|
|
|
|
|
|
|
|
#
|
|
|
|
# Adds an already running task as a symbolic job to the container.
|
|
|
|
#
|
|
|
|
def add_job(name, ctx, run_proc, clean_proc)
|
|
|
|
real_name = name
|
|
|
|
count = 0
|
|
|
|
jid = job_id_pool
|
|
|
|
|
|
|
|
self.job_id_pool += 1
|
|
|
|
|
|
|
|
# If we were not supplied with a job name, pick one from the hat
|
|
|
|
if (real_name == nil)
|
|
|
|
real_name = '#' + jid.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
# Find a unique job name
|
|
|
|
while (j = self[real_name])
|
|
|
|
real_name = name + " #{count}"
|
|
|
|
count += 1
|
|
|
|
end
|
|
|
|
|
|
|
|
j = Rex::Job.new(self, jid, real_name, ctx, run_proc, clean_proc)
|
|
|
|
|
|
|
|
$gtk2driver.job_tree.add_oneshot(jid, name)
|
|
|
|
self[jid.to_s] = j
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Removes a job that was previously running. This is typically called when
|
|
|
|
# a job completes its task.
|
|
|
|
#
|
|
|
|
def remove_job(inst)
|
|
|
|
self.delete(inst.jid.to_s)
|
|
|
|
$gtk2driver.job_tree.remove_job(inst.jid.to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
end # module
|
|
|
|
|
2007-05-12 16:10:22 +00:00
|
|
|
def initialize(treeview)
|
2007-06-24 19:48:09 +00:00
|
|
|
framework.jobs.extend(ModifiedJobContainer)
|
|
|
|
|
2007-05-12 16:10:22 +00:00
|
|
|
@treeview2 = treeview
|
|
|
|
|
2007-06-24 19:48:09 +00:00
|
|
|
@model = Gtk::TreeStore.new(
|
|
|
|
Gdk::Pixbuf, # Pix rhost
|
|
|
|
String, # process JID
|
|
|
|
String # module name
|
2007-05-12 16:10:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Renderer
|
|
|
|
renderer_pix = Gtk::CellRendererPixbuf.new
|
2007-06-24 19:48:09 +00:00
|
|
|
renderer_JID = Gtk::CellRendererText.new
|
2007-05-12 16:10:22 +00:00
|
|
|
renderer_name = Gtk::CellRendererText.new
|
|
|
|
|
2007-06-24 19:48:09 +00:00
|
|
|
# JID Gtk::TreeViewColumn
|
|
|
|
column_JID = Gtk::TreeViewColumn.new
|
|
|
|
column_JID.set_title("Job ID")
|
|
|
|
column_JID.pack_start(renderer_pix, false)
|
|
|
|
column_JID.set_cell_data_func(renderer_pix) do |column, cell, model, iter|
|
2007-05-12 16:10:22 +00:00
|
|
|
cell.pixbuf = iter[PIX]
|
|
|
|
end
|
2007-06-24 19:48:09 +00:00
|
|
|
column_JID.pack_start(renderer_JID, true)
|
|
|
|
column_JID.set_cell_data_func(renderer_JID) do |column, cell, model, iter|
|
|
|
|
cell.text = iter[JID]
|
2007-05-12 16:10:22 +00:00
|
|
|
end
|
2007-06-24 19:48:09 +00:00
|
|
|
column_JID.sort_column_id = JID
|
2007-05-12 16:10:22 +00:00
|
|
|
|
|
|
|
# Name Gtk::TreeViewColumn
|
|
|
|
column_name = Gtk::TreeViewColumn.new
|
|
|
|
column_name.set_title("Module")
|
|
|
|
column_name.pack_start(renderer_name, true)
|
|
|
|
column_name.set_cell_data_func(renderer_name) do |column, cell, model, iter|
|
|
|
|
cell.text = iter[NAME]
|
|
|
|
end
|
|
|
|
|
|
|
|
#set model to treeview
|
|
|
|
@treeview2.set_model(@model)
|
|
|
|
|
|
|
|
@selection = @treeview2.selection
|
|
|
|
@treeview2.selection.mode = Gtk::SELECTION_BROWSE
|
|
|
|
@treeview2.rules_hint = true
|
|
|
|
|
|
|
|
# Add Gtk::TreeViewColumn
|
2007-06-24 19:48:09 +00:00
|
|
|
@treeview2.append_column(column_JID)
|
2007-05-12 16:10:22 +00:00
|
|
|
@treeview2.append_column(column_name)
|
|
|
|
|
|
|
|
# Add AutoPWN
|
|
|
|
@autopwn_iter = @model.append(nil)
|
|
|
|
@autopwn_iter.set_value(PIX, driver.get_icon("menu_autopwn.png"))
|
2007-06-24 19:48:09 +00:00
|
|
|
@autopwn_iter.set_value(JID, "AutoPWN")
|
2007-05-12 16:10:22 +00:00
|
|
|
|
|
|
|
# Add Parent "One shot"
|
|
|
|
@oneshot_iter = @model.append(nil)
|
|
|
|
@oneshot_iter.set_value(PIX, driver.get_icon("menu_oneshot.png"))
|
2007-06-24 19:48:09 +00:00
|
|
|
@oneshot_iter.set_value(JID, "One shot")
|
2007-05-12 16:10:22 +00:00
|
|
|
|
|
|
|
# Job Gtk::Menu
|
|
|
|
@menu_job = Gtk::Menu.new
|
2007-06-24 19:48:09 +00:00
|
|
|
@menu_refresh = Gtk::Menu.new
|
|
|
|
|
2007-05-12 16:10:22 +00:00
|
|
|
# Stop job
|
|
|
|
kill_job_item_shell = Gtk::ImageMenuItem.new("Kill Job")
|
|
|
|
kill_job_image_shell = Gtk::Image.new
|
|
|
|
kill_job_image_shell.set(Gtk::Stock::CLOSE, Gtk::IconSize::MENU)
|
|
|
|
kill_job_item_shell.set_image(kill_job_image_shell)
|
|
|
|
@menu_job.append(kill_job_item_shell)
|
|
|
|
|
|
|
|
# Refresh
|
|
|
|
refresh_job_item_shell = Gtk::ImageMenuItem.new("Refresh")
|
|
|
|
refresh_job_image_shell = Gtk::Image.new
|
|
|
|
refresh_job_image_shell.set(Gtk::Stock::REFRESH, Gtk::IconSize::MENU)
|
|
|
|
refresh_job_item_shell.set_image(refresh_job_image_shell)
|
|
|
|
@menu_job.append(refresh_job_item_shell)
|
2007-06-24 19:48:09 +00:00
|
|
|
|
|
|
|
refresh_job_item_shell2 = Gtk::ImageMenuItem.new("Refresh")
|
|
|
|
refresh_job_image_shell2 = Gtk::Image.new
|
|
|
|
refresh_job_image_shell2.set(Gtk::Stock::REFRESH, Gtk::IconSize::MENU)
|
|
|
|
refresh_job_item_shell2.set_image(refresh_job_image_shell2)
|
|
|
|
@menu_refresh.append(refresh_job_item_shell2)
|
2007-05-12 16:10:22 +00:00
|
|
|
|
2007-06-24 19:48:09 +00:00
|
|
|
@menu_job.show_all
|
|
|
|
@menu_refresh.show_all
|
2007-05-12 16:10:22 +00:00
|
|
|
|
|
|
|
# TreeView Signals
|
|
|
|
@treeview2.signal_connect('button_press_event') do |treeview, event|
|
|
|
|
if event.kind_of? Gdk::EventButton
|
|
|
|
if (event.button == 3)
|
|
|
|
path, column, x, y = treeview.get_path_at_pos(event.x, event.y)
|
|
|
|
|
|
|
|
begin
|
|
|
|
iter = @treeview2.model.get_iter(path)
|
|
|
|
treeview.selection.select_path(path)
|
|
|
|
@menu_job.popup(nil, nil, event.button, event.time)
|
|
|
|
rescue
|
2007-06-24 19:48:09 +00:00
|
|
|
@menu_refresh.popup(nil, nil, event.button, event.time)
|
2007-05-12 16:10:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Menu Signals
|
|
|
|
kill_job_item_shell.signal_connect('activate') do |item|
|
|
|
|
if current = @selection.selected
|
|
|
|
stop_job(current)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
refresh_job_item_shell.signal_connect('activate') do |item|
|
|
|
|
refresh_job()
|
|
|
|
end
|
2007-06-24 19:48:09 +00:00
|
|
|
|
|
|
|
refresh_job_item_shell2.signal_connect('activate') do |item|
|
|
|
|
refresh_job()
|
|
|
|
end
|
2007-05-12 16:10:22 +00:00
|
|
|
|
|
|
|
end # def initialize
|
|
|
|
|
|
|
|
#
|
|
|
|
# Add One Shot
|
|
|
|
#
|
2007-06-24 19:48:09 +00:00
|
|
|
def add_oneshot(id, name)
|
2007-05-12 16:10:22 +00:00
|
|
|
oneshot_childiter = @model.append(@oneshot_iter)
|
2007-06-24 19:48:09 +00:00
|
|
|
oneshot_childiter.set_value(JID, id.to_s)
|
|
|
|
oneshot_childiter.set_value(NAME, name.split(":")[1])
|
2007-05-12 16:10:22 +00:00
|
|
|
@treeview2.expand_all()
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2007-06-24 19:48:09 +00:00
|
|
|
# Stop job and and let the framework remove it from the job tree
|
2007-05-12 16:10:22 +00:00
|
|
|
#
|
|
|
|
def stop_job(iter)
|
|
|
|
|
2007-06-24 19:48:09 +00:00
|
|
|
# Isolate the job ID
|
|
|
|
jid = iter[JID]
|
2007-05-12 16:10:22 +00:00
|
|
|
|
2007-06-24 19:48:09 +00:00
|
|
|
# Informing the user
|
|
|
|
$gtk2driver.append_log_view("[*] Stopping exploit: #{iter[NAME]}\n")
|
2007-05-12 16:10:22 +00:00
|
|
|
|
2007-06-24 19:48:09 +00:00
|
|
|
# Stopping job
|
|
|
|
framework.jobs.stop_job(jid)
|
2007-05-12 16:10:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2007-06-24 19:48:09 +00:00
|
|
|
# Refresh jobs tree
|
2007-05-12 16:10:22 +00:00
|
|
|
#
|
|
|
|
def refresh_job
|
2007-06-24 19:48:09 +00:00
|
|
|
clear_tree()
|
2007-05-12 16:10:22 +00:00
|
|
|
framework.jobs.keys.sort.each do |k|
|
2007-06-24 19:48:09 +00:00
|
|
|
add_oneshot(framework.jobs[k].jid, framework.jobs[k].name)
|
2007-05-12 16:10:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2007-06-24 19:48:09 +00:00
|
|
|
# Remove job by id and remote it from jobs tree
|
2007-05-12 16:10:22 +00:00
|
|
|
#
|
2007-06-24 19:48:09 +00:00
|
|
|
def remove_job(id)
|
2007-05-12 16:10:22 +00:00
|
|
|
found = nil
|
|
|
|
@model.each do |model,path,iter|
|
2007-06-24 19:48:09 +00:00
|
|
|
if (iter[JID] == id)
|
2007-05-12 16:10:22 +00:00
|
|
|
found = iter
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@model.remove(found) if found
|
|
|
|
end
|
|
|
|
|
2007-06-24 19:48:09 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
#
|
|
|
|
# Clear tree and add parents iter
|
|
|
|
#
|
|
|
|
def clear_tree
|
|
|
|
@model.clear
|
|
|
|
# Add AutoPWN
|
|
|
|
@autopwn_iter = @model.append(nil)
|
|
|
|
@autopwn_iter.set_value(PIX, driver.get_icon("menu_autopwn.png"))
|
|
|
|
@autopwn_iter.set_value(JID, "AutoPWN")
|
|
|
|
|
|
|
|
# Add Parent "One shot"
|
|
|
|
@oneshot_iter = @model.append(nil)
|
|
|
|
@oneshot_iter.set_value(PIX, driver.get_icon("menu_oneshot.png"))
|
|
|
|
@oneshot_iter.set_value(JID, "One shot")
|
|
|
|
end
|
|
|
|
|
2007-05-12 16:10:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
2007-05-12 15:36:37 +00:00
|
|
|
end
|