Module: Rex::Post::Meterpreter::Ui::Console::InteractiveChannel

Includes:
Ui::Interactive
Defined in:
lib/rex/post/meterpreter/ui/console/interactive_channel.rb

Overview

Mixin that is meant to extend the base channel class from meterpreter in a manner that adds interactive capabilities.

Instance Attribute Summary

Attributes included from Ui::Interactive

#completed, #interacting, #on_command_proc, #on_print_proc

Attributes included from Ui::Subscriber::Input

#user_input

Attributes included from Ui::Subscriber::Output

#user_output

Instance Method Summary collapse

Methods included from Ui::Interactive

#detach, #interact

Methods included from Ui::Subscriber

#copy_ui, #init_ui, #reset_ui

Methods included from Ui::Subscriber::Input

#gets

Methods included from Ui::Subscriber::Output

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

Instance Method Details

#_interactObject

Interacts with self.


20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rex/post/meterpreter/ui/console/interactive_channel.rb', line 20

def _interact
  # If the channel has a left-side socket, then we can interact with it.
  if (self.lsock)
    self.interactive(true)

    interact_stream(self)

    self.interactive(false)
  else
    print_error("Channel #{self.cid} does not support interaction.")

    self.interacting = false
  end
end

#_interact_completeObject

Closes the channel like it aint no thang.


57
58
59
60
61
62
63
64
# File 'lib/rex/post/meterpreter/ui/console/interactive_channel.rb', line 57

def _interact_complete
  begin
    self.interactive(false)

    self.close
  rescue IOError
  end
end

#_interruptObject

Called when an interrupt is sent.


38
39
40
# File 'lib/rex/post/meterpreter/ui/console/interactive_channel.rb', line 38

def _interrupt
  prompt_yesno("Terminate channel #{self.cid}?")
end

#_remote_fd(stream) ⇒ Object

Returns the remote file descriptor to select on


90
91
92
# File 'lib/rex/post/meterpreter/ui/console/interactive_channel.rb', line 90

def _remote_fd(stream)
  self.lsock
end

#_stream_read_local_write_remote(channel) ⇒ Object

Reads data from local input and writes it remotely.


69
70
71
72
73
74
75
# File 'lib/rex/post/meterpreter/ui/console/interactive_channel.rb', line 69

def _stream_read_local_write_remote(channel)
  data = user_input.gets
  return if not data

  self.on_command_proc.call(data.strip) if self.on_command_proc
  self.write(data)
end

#_stream_read_remote_write_local(channel) ⇒ Object

Reads from the channel and writes locally.


80
81
82
83
84
85
# File 'lib/rex/post/meterpreter/ui/console/interactive_channel.rb', line 80

def _stream_read_remote_write_local(channel)
  data = self.lsock.sysread(16384)

  self.on_print_proc.call(data.strip) if self.on_print_proc
  user_output.print(data)
end

#_suspendObject

Suspends interaction with the channel.


45
46
47
48
49
50
51
52
# File 'lib/rex/post/meterpreter/ui/console/interactive_channel.rb', line 45

def _suspend
  # Ask the user if they would like to background the session
  if (prompt_yesno("Background channel #{self.cid}?") == true)
    self.interactive(false)

    self.interacting = false
  end
end