Module: Rex::Post::HWBridge::Ui::Console::InteractiveChannel

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

Overview

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

Instance Attribute Summary collapse

Attributes included from Ui::Interactive

#completed, #interacting, #next_session, #on_command_proc, #on_print_proc, #on_run_command_error_proc, #orig_suspend, #orig_usr1, #orig_winch

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

#_local_fd, #_winch, #detach, #handle_suspend, #handle_usr1, #handle_winch, #interact, #interact_stream, #prompt, #prompt_yesno, #restore_suspend, #restore_usr1, #restore_winch

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_blank_line, #print_error, #print_good, #print_line, #print_status, #print_warning

Instance Attribute Details

#on_log_procObject

Returns the value of attribute on_log_proc.



95
96
97
# File 'lib/rex/post/hwbridge/ui/console/interactive_channel.rb', line 95

def on_log_proc
  @on_log_proc
end

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/hwbridge/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/hwbridge/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/hwbridge/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



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

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/hwbridge/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
86
# File 'lib/rex/post/hwbridge/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
  self.on_log_proc.call(data.strip) if self.on_log_proc
  user_output.print(data)
end

#_suspendObject

Suspends interaction with the channel.



45
46
47
48
49
50
51
52
# File 'lib/rex/post/hwbridge/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