2007-06-26 21:09:30 +00:00
|
|
|
module Msf
|
|
|
|
module Ui
|
|
|
|
module Gtk2
|
|
|
|
|
|
|
|
class Console
|
|
|
|
|
2007-07-02 15:57:36 +00:00
|
|
|
###
|
2007-06-26 21:09:30 +00:00
|
|
|
#
|
2007-07-02 15:57:36 +00:00
|
|
|
# Classic console herited from SkeletonConsole
|
2007-06-26 21:09:30 +00:00
|
|
|
#
|
2007-07-02 15:57:36 +00:00
|
|
|
###
|
2007-06-26 21:09:30 +00:00
|
|
|
class Shell < Msf::Ui::Gtk2::SkeletonConsole
|
2007-07-03 20:55:24 +00:00
|
|
|
|
2007-06-26 21:09:30 +00:00
|
|
|
def initialize(iter)
|
2007-07-03 20:55:24 +00:00
|
|
|
session = iter[3]
|
2007-06-26 21:09:30 +00:00
|
|
|
super(iter)
|
2007-07-03 20:55:24 +00:00
|
|
|
|
2007-07-04 21:23:30 +00:00
|
|
|
# When the session type is meterperter
|
2007-07-03 20:55:24 +00:00
|
|
|
if (session.type == "meterpreter")
|
2007-07-03 23:01:50 +00:00
|
|
|
require 'msf/ui/gtk2/console/interactive_channel.rb'
|
|
|
|
|
2007-07-03 20:55:24 +00:00
|
|
|
self.type = "shell"
|
|
|
|
|
|
|
|
meterconsole = Rex::Post::Meterpreter::Ui::Console.new(session)
|
|
|
|
meterconsole.extend(Pipe)
|
|
|
|
cmd_exec = "cmd.exe"
|
|
|
|
cmd_args = nil
|
|
|
|
channelized = true
|
|
|
|
hidden = true
|
|
|
|
from_mem = false
|
|
|
|
dummy_exec = "cmd"
|
|
|
|
p = session.sys.process.execute(cmd_exec, cmd_args,
|
|
|
|
'Channelized' => channelized,
|
|
|
|
'Hidden' => hidden,
|
|
|
|
'InMemory' => (from_mem) ? dummy_exec : nil)
|
|
|
|
|
2007-07-03 23:01:50 +00:00
|
|
|
# Create a new pipe to not use the pipe class
|
2007-07-03 20:55:24 +00:00
|
|
|
@pipe = Rex::IO::BidirectionalPipe.new
|
2007-07-03 23:01:50 +00:00
|
|
|
|
2007-07-03 20:55:24 +00:00
|
|
|
# Create a subscriber with a callback for the UI
|
|
|
|
@pipe.create_subscriber_proc() do |data|
|
|
|
|
self.insert_text(Rex::Text.to_utf8(data))
|
|
|
|
end
|
|
|
|
|
2007-07-04 21:23:30 +00:00
|
|
|
# When the close button was clicked ...
|
|
|
|
self.button_close.signal_connect('clicked') do
|
|
|
|
begin
|
|
|
|
iter[4] = nil
|
|
|
|
p.channel.close
|
|
|
|
session.sys.process.kill(p.pid)
|
|
|
|
self.destroy
|
|
|
|
session.channels.each_pair { |cid, channel|
|
|
|
|
puts "#{cid}: #{channel.class.cls}"
|
|
|
|
}
|
|
|
|
rescue IOError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-07-03 23:01:50 +00:00
|
|
|
# Interact with the supplied channel
|
|
|
|
meterconsole.interact_with_channel(p.channel, @pipe)
|
2007-07-04 21:23:30 +00:00
|
|
|
|
|
|
|
else
|
|
|
|
# Bind the signal to the close button
|
|
|
|
self.button_close.signal_connect('clicked') do
|
|
|
|
self.close_console
|
|
|
|
end
|
2007-07-03 20:55:24 +00:00
|
|
|
end
|
2007-07-03 23:01:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Send command to bidirectionnal_pipe
|
|
|
|
#
|
|
|
|
def send_cmd(cmd)
|
|
|
|
# Write the command plus a newline to the input
|
|
|
|
@pipe.write_input(cmd + "\n")
|
2007-06-26 21:09:30 +00:00
|
|
|
end
|
|
|
|
|
2007-07-02 15:57:36 +00:00
|
|
|
end # Console::Shell
|
2007-06-26 21:09:30 +00:00
|
|
|
|
2007-07-02 15:57:36 +00:00
|
|
|
###
|
2007-06-26 21:09:30 +00:00
|
|
|
#
|
2007-07-02 15:57:36 +00:00
|
|
|
# Meterpreter Console herited from SkeletonConsole
|
2007-06-26 21:09:30 +00:00
|
|
|
#
|
2007-07-02 15:57:36 +00:00
|
|
|
###
|
2007-06-26 21:09:30 +00:00
|
|
|
class Meterpreter < Msf::Ui::Gtk2::SkeletonConsole
|
2007-06-27 21:41:44 +00:00
|
|
|
def initialize(iter)
|
|
|
|
# meterpreter client
|
2007-07-03 23:01:50 +00:00
|
|
|
session = iter[3]
|
2007-06-26 21:09:30 +00:00
|
|
|
|
2007-06-27 21:41:44 +00:00
|
|
|
# call the parent
|
2007-06-26 21:09:30 +00:00
|
|
|
super(iter)
|
2007-07-03 20:55:24 +00:00
|
|
|
|
2007-07-03 23:01:50 +00:00
|
|
|
meterconsole = Rex::Post::Meterpreter::Ui::Console.new(session)
|
|
|
|
|
|
|
|
# Create a new pipe to not use the pipe class
|
|
|
|
@pipe = Rex::IO::BidirectionalPipe.new
|
|
|
|
|
|
|
|
# Create a subscriber with a callback for the UI
|
|
|
|
@pipe.create_subscriber_proc() do |data|
|
|
|
|
self.insert_text(Rex::Text.to_utf8(data))
|
|
|
|
end
|
2007-07-04 21:23:30 +00:00
|
|
|
|
2007-07-03 23:01:50 +00:00
|
|
|
meterconsole.init_ui(@pipe, @pipe)
|
|
|
|
|
|
|
|
@t_run = Thread.new do
|
|
|
|
meterconsole.interact { self.interacting != true }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Send command to bidirectionnal_pipe
|
|
|
|
#
|
|
|
|
def send_cmd(cmd)
|
|
|
|
# Write the command plus a newline to the input
|
|
|
|
@pipe.write_input(cmd + "\n")
|
2007-06-26 21:09:30 +00:00
|
|
|
end
|
|
|
|
|
2007-07-02 15:57:36 +00:00
|
|
|
end # Console::Meterpreter
|
2007-06-27 21:41:44 +00:00
|
|
|
|
2007-06-26 21:09:30 +00:00
|
|
|
end # Console
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
2008-10-19 21:03:39 +00:00
|
|
|
end
|