From 360260ee90d5cf2ce0e6c7205276284ee9e376fd Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Sat, 23 Jul 2005 05:13:27 +0000 Subject: [PATCH] added migrate ui git-svn-id: file:///home/svn/incoming/trunk@2820 4d416f70-5f16-0410-b530-b9f4589650da --- documentation/bugs | 3 + lib/rex/post/meterpreter/client_core.rb | 4 +- lib/rex/post/meterpreter/packet_dispatcher.rb | 1 - lib/rex/post/meterpreter/packet_parser.rb | 1 - lib/rex/post/meterpreter/ui/console.rb | 6 +- .../ui/console/command_dispatcher/core.rb | 60 ++++++++++++++----- .../console/command_dispatcher/stdapi/sys.rb | 2 +- 7 files changed, 54 insertions(+), 23 deletions(-) create mode 100644 documentation/bugs diff --git a/documentation/bugs b/documentation/bugs new file mode 100644 index 0000000000..5992289090 --- /dev/null +++ b/documentation/bugs @@ -0,0 +1,3 @@ +meterpreter + - migration sometimes does partial reads of stages leading to crashes + - should switch to inlined staging in request packet. diff --git a/lib/rex/post/meterpreter/client_core.rb b/lib/rex/post/meterpreter/client_core.rb index 0b66eb4755..5108c5b304 100644 --- a/lib/rex/post/meterpreter/client_core.rb +++ b/lib/rex/post/meterpreter/client_core.rb @@ -142,7 +142,7 @@ class ClientCore < Extension path = opts['ExtensionPath'] end - path = File.expand_path(path) + path = ::File.expand_path(path) # Load the extension DLL if (load_library( @@ -334,7 +334,7 @@ class ClientCore < Extension wrote = client.sock.write(buf) # Re-load the STDAPI extension server-side - client.core.use('Stdapi') + client.core.use('stdapi') ### ### ### TEMPORARY ### diff --git a/lib/rex/post/meterpreter/packet_dispatcher.rb b/lib/rex/post/meterpreter/packet_dispatcher.rb index 519b95a6d1..7774db2afe 100644 --- a/lib/rex/post/meterpreter/packet_dispatcher.rb +++ b/lib/rex/post/meterpreter/packet_dispatcher.rb @@ -118,7 +118,6 @@ module PacketDispatcher begin packet = receive_packet rescue EOFError - puts "EOF reached on socket\n" break end diff --git a/lib/rex/post/meterpreter/packet_parser.rb b/lib/rex/post/meterpreter/packet_parser.rb index c42119673f..80bb6a4667 100644 --- a/lib/rex/post/meterpreter/packet_parser.rb +++ b/lib/rex/post/meterpreter/packet_parser.rb @@ -69,7 +69,6 @@ class PacketParser # TODO: cipher decryption if (cipher) - puts "TODO: decryption\n" end # Serialize the packet from the raw buffer diff --git a/lib/rex/post/meterpreter/ui/console.rb b/lib/rex/post/meterpreter/ui/console.rb index 494c29ff95..6f8dae3be5 100644 --- a/lib/rex/post/meterpreter/ui/console.rb +++ b/lib/rex/post/meterpreter/ui/console.rb @@ -75,9 +75,11 @@ class Console begin super rescue TimeoutError - output.print_line("Operation timed out.") + output.print_error("Operation timed out.") rescue RequestError => info - output.print_line(info.to_s) + output.print_error(info.to_s) + rescue + output.print_error("Error running command #{method}: #{$!}") end end diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb index 2f3dfb5334..19b253d6c3 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb @@ -21,6 +21,7 @@ class Console::CommandDispatcher::Core super self.extensions = [] + self.ext_hash = {} end @@use_opts = Rex::Parser::Arguments.new( @@ -31,11 +32,12 @@ class Console::CommandDispatcher::Core # def commands { - "?" => "Help menu", - "exit" => "Terminate the meterpreter session", - "help" => "Help menu", - "use" => "Load a one or more meterpreter extensions", - "quit" => "Terminate the meterpreter session", + "?" => "Help menu", + "exit" => "Terminate the meterpreter session", + "help" => "Help menu", + "migrate" => "Migrate the server to another process", + "use" => "Load a one or more meterpreter extensions", + "quit" => "Terminate the meterpreter session", } end @@ -62,6 +64,30 @@ class Console::CommandDispatcher::Core print(shell.help_to_s) end + alias cmd_? cmd_help + + # + # Migrates the server to the supplied process identifier. + # + def cmd_migrate(*args) + if (args.length == 0) + print_line( + "Usage: migrate pid\n\n" + + "Migrates the server instance to another process.\n" + + "Note: Any open channels or other dynamic state will be lost.") + return true + end + + pid = args[0].to_i + + print_status("Migrating to #{pid}...") + + # Do this thang. + client.core.migrate(pid) + + print_status("Migration completed successfully.") + end + # # Loads one or more meterpreter extensions # @@ -112,7 +138,7 @@ class Console::CommandDispatcher::Core protected - attr_accessor :extensions + attr_accessor :extensions, :ext_hash CommDispatcher = Console::CommandDispatcher @@ -122,20 +148,22 @@ protected def add_extension_client(mod) clirb = File.join(Rex::Root, "post/meterpreter/ui/console/command_dispatcher/#{mod}.rb") - old = CommDispatcher.constants + old = CommDispatcher.constants - require(clirb) + if (require(clirb) == true) + new = CommDispatcher.constants + diff = new - old + + if (diff.empty? == true) + print_error("Failed to load client portion of #{mod}.") + return false + end - new = CommDispatcher.constants - diff = new - old - - if (diff.empty? == true) - print_error("Failed to load client portion of #{mod}.") - return false + self.ext_hash[mod] = CommDispatcher.const_get(diff[0]) end - + # Create the dispatcher - klass = CommDispatcher.const_get(diff[0]) + klass = self.ext_hash[mod] # Enstack the dispatcher self.shell.enstack_dispatcher(klass) diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/sys.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/sys.rb index d1a181bad8..e52dc6078b 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/sys.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/sys.rb @@ -125,7 +125,7 @@ class Console::CommandDispatcher::Stdapi::Sys # def cmd_kill(*args) if (args.length == 0) - print( + print_line( "Usage: kill pid1 pid2 pid3 ...\n\n" + "Terminate one or more processes.") return true