Changeset 5544

Show
Ignore:
Timestamp:
06/27/08 15:51:36 (3 months ago)
Author:
hdm
Message:

Implements the readline workaround, tested with regular and meterpreter sessions

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • framework3/trunk/lib/msf/ui/console/command_dispatcher/core.rb

    r5536 r5544  
    737737 
    738738                                                session.interact(driver.input.dup, driver.output) 
    739                                                                                                 
     739                 
    740740                                                self.active_session = nil 
    741741                                                 
     
    757757                rescue IOError, EOFError, Rex::StreamClosedError 
    758758                        print_status("Session stream closed.") 
    759                 rescue 
     759                rescue ::Interrupt 
     760                        raise $! 
     761                rescue ::Exception 
    760762                        log_error("Session manipulation failed: #{$!} #{$!.backtrace.inspect}") 
    761763                end 
  • framework3/trunk/lib/rex/ui/text/input/readline.rb

    r5543 r5544  
    3838                def child_readline(wtr, prompt, history) 
    3939                        $0 = "<readline>" 
     40                         
    4041                        line = ::Readline.readline(prompt, history) 
    4142                        line = "\n" if (line and line.strip.length == 0) 
     43 
    4244                        wtr.write(line || "exit\n") 
    4345                        wtr.flush 
    4446                        wtr.close 
    45                         exit(0) 
     47                         
     48                        # Self-destruct mechanism activated 
     49                        Process.kill(9, $$) 
    4650                end 
    4751                 
     
    5862                def sysread(len = 1) 
    5963                        $stdin.sysread(len) 
    60  
    6164                end 
    6265                 
     
    7679                def pgets 
    7780                 
    78                         # if(Rex::Compat.is_windows()) 
    79                         if(true) 
     81                        if(Rex::Compat.is_windows()) 
    8082                                output.prompting 
    8183                                line = ::Readline.readline(prompt, true) 
     
    8486                        end 
    8587 
    86                         # Wrap readline in a child process and secure with a mutex 
    87                         # This prevents threading hangs in the calling process. 
    88                         require "thread" 
    89                         @@child_mutex ||= Mutex.new 
    90                         @@child_mutex.synchronize do 
     88 
     89                        line = "" 
    9190                         
    9291                        output.prompting 
     
    112111                        ::Process.waitpid(pid, 0) 
    113112 
     113                        # Parse the results 
    114114                        if line 
    115115                                HISTORY.push(line) if (not line.empty?) 
     
    118118                                eof = true 
    119119                                return line 
    120                         end 
    121                          
    122                         # Release the readline mutex 
    123                         end 
     120                        end                      
     121 
    124122                end 
    125123