Method: Rex::Post::Meterpreter::Channel#_write

Defined in:
lib/rex/post/meterpreter/channel.rb

#_write(buf, length = nil, addends = nil) ⇒ Object

Writes data to the remote half of the channel.



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/rex/post/meterpreter/channel.rb', line 216

def _write(buf, length = nil, addends = nil)

  if (self.cid == nil)
    raise IOError, "Channel has been closed.", caller
  end

  request = Packet.create_request('core_channel_write')

  # Truncation and celebration
  if ((length != nil) &&
      (buf.length >= length))
    buf = buf[0..length]
  else
    length = buf.length
  end

  # Populate the request
  request.add_tlv(TLV_TYPE_CHANNEL_ID, self.cid)

  cdata = request.add_tlv(TLV_TYPE_CHANNEL_DATA, buf)
  if( ( self.flags & CHANNEL_FLAG_COMPRESS ) == CHANNEL_FLAG_COMPRESS )
    cdata.compress = true
  end

  request.add_tlv(TLV_TYPE_LENGTH, length)
  request.add_tlvs(addends)

  response = self.client.send_request(request)
  written  = response.get_tlv(TLV_TYPE_LENGTH)

  return (written == nil) ? 0 : written.value
end