Class: Rex::Post::Meterpreter::Extensions::Stdapi::Net::SocketSubsystem::UdpChannel

Inherits:
Datagram
  • Object
show all
Defined in:
lib/rex/post/meterpreter/extensions/stdapi/net/socket_subsystem/udp_channel.rb

Instance Attribute Summary

Attributes inherited from Channel

#cid, #client, #cls, #flags, #params, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Datagram

#dio_write_handler

Methods included from SocketAbstraction

#_write, #cleanup, #dio_close_handler, #dio_write_handler

Methods inherited from Channel

_close, #_close, #_read, #_write, #cleanup, #close, #close_read, #close_write, #closed?, create, #dio_close_handler, #dio_handler, #dio_map, #dio_read_handler, #dio_write_handler, finalize, #flag?, #interactive, #read, request_handler, #synchronous?, #write

Methods included from InboundPacketHandler

#request_handler, #response_handler

Constructor Details

#initialize(client, cid, type, flags, packet, sock_params: nil) ⇒ UdpChannel

Simply initialize this instance.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/rex/post/meterpreter/extensions/stdapi/net/socket_subsystem/udp_channel.rb', line 64

def initialize(client, cid, type, flags, packet, sock_params: nil)
  super(client, cid, type, flags, packet)

  lsock.extend(Rex::Socket::Udp)
  lsock.initsock
  lsock.extend(SocketInterface)
  lsock.extend(DirectChannelWrite)
  lsock.channel = self

  # rsock.extend( Rex::Socket::Udp )
  rsock.extend(SocketInterface)
  rsock.channel = self

  unless sock_params.nil?
    @params = sock_params.merge(Socket.parameters_from_response(packet))
  end
end

Class Method Details

.clsObject

We are a datagram channel.



23
24
25
# File 'lib/rex/post/meterpreter/extensions/stdapi/net/socket_subsystem/udp_channel.rb', line 23

def self.cls
  CHANNEL_CLASS_DATAGRAM
end

.open(client, params) ⇒ Channel

Open a new UDP channel on the remote end. The local host/port are optional, if none are specified the remote end will bind to INADDR_ANY with a random port number. The peer host/port are also optional, if specified all default send(), write() call will sendto the specified peer. If no peer host/port is specified you must use sendto() and specify the remote peer you wish to send to. This effectivly lets us create bound/unbound and connected/unconnected UDP sockets with ease.

Returns:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rex/post/meterpreter/extensions/stdapi/net/socket_subsystem/udp_channel.rb', line 37

def self.open(client, params)
  Channel.create(client, 'stdapi_net_udp_client', self, CHANNEL_FLAG_SYNCHRONOUS,
  [
      {
        'type'  => TLV_TYPE_LOCAL_HOST,
        'value' => params.localhost
      },
      {
        'type'  => TLV_TYPE_LOCAL_PORT,
        'value' => params.localport
      },
      {
        'type'  => TLV_TYPE_PEER_HOST,
        'value' => params.peerhost
      },
      {
        'type'  => TLV_TYPE_PEER_PORT,
        'value' => params.peerport
      }
    ],
    sock_params: params
  )
end

Instance Method Details

#send(buf, flags, a = nil, b = nil) ⇒ Object

This function is called by Rex::Socket::Udp.sendto and writes data to a specified remote peer host/port via the remote end of the channel.

This should work just like a UDPSocket.send method

send(mesg, flags, host, port) => numbytes_sent click to toggle source send(mesg, flags, sockaddr_to) => numbytes_sent send(mesg, flags) => numbytes_sent



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/rex/post/meterpreter/extensions/stdapi/net/socket_subsystem/udp_channel.rb', line 92

def send(buf, flags, a = nil, b = nil)
  host = nil
  port = nil

  if a && b.nil?
    _, host, port = Rex::Socket.from_sockaddr(a)
  elsif a && b
    host = a
    port = b
  end

  addends = nil
  if host && port
    addends = [
      {
        'type'  => TLV_TYPE_PEER_HOST,
        'value' => host
      },
      {
        'type'  => TLV_TYPE_PEER_PORT,
        'value' => port
      }
    ]
  end

  _write(buf, buf.length, addends)
end