Method: Msf::Sessions::Meterpreter#shell_read

Defined in:
lib/msf/base/sessions/meterpreter.rb

#shell_read(length = nil, timeout = 1) ⇒ Object

:category: Msf::Session::Provider::SingleCommandShell implementors

Read from the command shell.

[View source] [View on GitHub]

224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/msf/base/sessions/meterpreter.rb', line 224

def shell_read(length=nil, timeout=1)
  shell_init

  length = nil if length.nil? or length < 0
  begin
    rv = nil
    # Meterpreter doesn't offer a way to timeout on the victim side, so
    # we have to do it here.  I'm concerned that this will cause loss
    # of data.
    Timeout.timeout(timeout) {
      rv = @shell.channel.read(length)
    }
    framework.events.on_session_output(self, rv) if rv
    return rv
  rescue ::Timeout::Error
    return nil
  rescue ::Exception => e
    shell_close
    raise e
  end
end