Module: Rex::Ui::Interactive

Includes:
Subscriber
Included in:
Post::Meterpreter::Ui::Console::InteractiveChannel
Defined in:
lib/rex/ui/interactive.rb

Overview

This class implements the stubs that are needed to provide an interactive user interface that is backed against something arbitrary.

Instance Attribute Summary collapse

Attributes included from Subscriber::Input

#user_input

Attributes included from Subscriber::Output

#user_output

Instance Method Summary collapse

Methods included from Subscriber

#copy_ui, #init_ui, #reset_ui

Methods included from Subscriber::Input

#gets

Methods included from Subscriber::Output

#flush, #print, #print_error, #print_good, #print_line, #print_status, #print_warning

Instance Attribute Details

#completedObject

Whether or not the session has completed interaction



110
111
112
# File 'lib/rex/ui/interactive.rb', line 110

def completed
  @completed
end

#interactingObject

Whether or not the session is currently being interacted with



105
106
107
# File 'lib/rex/ui/interactive.rb', line 105

def interacting
  @interacting
end

#on_command_procObject

Returns the value of attribute on_command_proc.



113
114
115
# File 'lib/rex/ui/interactive.rb', line 113

def on_command_proc
  @on_command_proc
end

#on_print_procObject

Returns the value of attribute on_print_proc.



112
113
114
# File 'lib/rex/ui/interactive.rb', line 112

def on_print_proc
  @on_print_proc
end

Instance Method Details

#detachObject

Stops the current interaction



93
94
95
96
97
98
99
100
# File 'lib/rex/ui/interactive.rb', line 93

def detach
  if (self.interacting)
    self.interacting = false
    while(not self.completed)
      ::IO.select(nil, nil, nil, 0.25)
    end
  end
end

#interact(user_input, user_output) ⇒ Object

Starts interacting with the session at the most raw level, simply forwarding input from user_input to rstream and forwarding input from rstream to user_output.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/rex/ui/interactive.rb', line 24

def interact(user_input, user_output)

  # Detach from any existing console
  if(self.interacting)
    detach()
  end

  init_ui(user_input, user_output)

  self.interacting = true
  self.completed = false

  eof = false

  # Start the readline stdin monitor
  # XXX disabled
  # user_input.readline_start() if user_input.supports_readline

  # Handle suspend notifications
  handle_suspend

  # As long as we're interacting...
  while (self.interacting == true)

    begin
      _interact

    rescue Interrupt
      # If we get an interrupt exception, ask the user if they want to
      # abort the interaction.  If they do, then we return out of
      # the interact function and call it a day.
      eof = true if (_interrupt)

    rescue EOFError, Errno::ECONNRESET, IOError
      # If we reach EOF or the connection is reset...
      eof = true

    end

    break if eof
  end

  begin

    # Restore the suspend handler
    restore_suspend

    # If we've hit eof, call the interact complete handler
    _interact_complete if (eof == true)

    # Shutdown the readline thread
		# XXX disabled
    # user_input.readline_stop() if user_input.supports_readline

    # Detach from the input/output handles
    reset_ui()

  ensure
    # Mark this as completed
    self.completed = true
  end

  # Return whether or not EOF was reached
  return eof
end