Module: Ronin::Exploits::Mixins::RemoteUDP

Includes:
Support::Network::UDP::Mixin
Defined in:
lib/ronin/exploits/mixins/remote_udp.rb

Overview

Adds UDP helper methods for communicating with a remote host.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(exploit) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Includes Params::Host, Params::Port, Params::BindHost, and Params::BindPort into the exploit class that is including Ronin::Exploits::Mixins::RemoteUDP.

Parameters:

Since:

  • 1.0.0



53
54
55
56
57
58
# File 'lib/ronin/exploits/mixins/remote_udp.rb', line 53

def self.included(exploit)
  exploit.include Params::Host
  exploit.include Params::Port
  exploit.include Params::BindHost
  exploit.include Params::BindPort
end

Instance Method Details

#udp_banner(host = params[:host], port = params[:port], bind_host: params[:bind_host], bind_port: params[:bind_port]) {|banner| ... } ⇒ String

Reads the banner from the service running on the given host and port.

Parameters:

  • host (String) (defaults to: params[:host])

    The host to connect to.

  • port (Integer) (defaults to: params[:port])

    The port to connect to.

  • bind_host (String, nil) (defaults to: params[:bind_host])

    The local host to bind to.

  • bind_port (Integer, nil) (defaults to: params[:bind_port])

    The local port to bind to.

Yields:

  • (banner)

    If a block is given, it will be passed the grabbed banner.

Yield Parameters:

  • banner (String)

    The grabbed banner.

Returns:

  • (String)

    The grabbed banner.

Since:

  • 1.0.0



222
223
224
225
226
227
228
# File 'lib/ronin/exploits/mixins/remote_udp.rb', line 222

def udp_banner(host=params[:host],port=params[:port], bind_host: params[:bind_host], bind_port: params[:bind_port])
  if debug?
    print_debug "Fetching the banner for #{host}:#{port} ..."
  end

  super(host,port,bind_host: bind_host, bind_port: bind_port)
end

#udp_connect(host = params[:host], port = params[:port], bind_host: params[:bind_host], bind_port: params[:bind_port]) {|socket| ... } ⇒ UDPSocket?

Creates a new UDPSocket object connected to a given host and port.

Examples:

udp_connect
# => #<UDPSocket:fd 5, AF_INET, 192.168.122.165, 48313>
udp_connect do |socket|
  # ...
end

Parameters:

  • host (String) (defaults to: params[:host])

    The host to connect to.

  • port (Integer) (defaults to: params[:port])

    The port to connect to.

  • bind_host (String, nil) (defaults to: params[:bind_host])

    The local host to bind to.

  • bind_port (Integer, nil) (defaults to: params[:bind_port])

    The local port to bind to.

Yields:

  • (socket)

    If a block is given, it will be passed the newly created socket. Once the block returns the socket will be closed.

Yield Parameters:

  • socket (UDPsocket)

    The newly created UDP socket.

Returns:

  • (UDPSocket, nil)

    The newly created UDP socket object. If a block is given a nil will be returned.

See Also:

Since:

  • 1.0.0



143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/ronin/exploits/mixins/remote_udp.rb', line 143

def udp_connect(host=params[:host],port=params[:port],
                bind_host: params[:bind_host],
                bind_port: params[:bind_port],
                &block)
  if debug?
    print_debug "Connecting to #{host}:#{port} ..."
  end

  super(host,port, bind_host: bind_host,
                   bind_port: bind_port,
                   &block)
end

#udp_connect_and_send(data, host = params[:host], port = params[:port], bind_host: params[:bind_host], bind_port: params[:bind_port]) {|socket| ... } ⇒ UDPSocket

Creates a new UDPSocket object, connected to a given host and port. The given data will then be written to the newly created UDPSocket.

Parameters:

  • data (String)

    The data to send through the connection.

  • host (String) (defaults to: params[:host])

    The host to connect to.

  • port (Integer) (defaults to: params[:port])

    The port to connect to.

  • bind_host (String, nil) (defaults to: params[:bind_host])

    The local host to bind to.

  • bind_port (Integer, nil) (defaults to: params[:bind_port])

    The local port to bind to.

Yields:

  • (socket)

    If a block is given, it will be passed the newly created socket.

Yield Parameters:

  • socket (UDPsocket)

    The newly created UDPSocket object.

Returns:

  • (UDPSocket)

    The newly created UDPSocket object.

Since:

  • 1.0.0



184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/ronin/exploits/mixins/remote_udp.rb', line 184

def udp_connect_and_send(data,host=params[:host],port=params[:port],
                         bind_host: params[:bind_host],
                         bind_port: params[:bind_port],
                         &block)
  if debug?
    print_debug "Connecting to #{host}:#{port} and sending #{data.inspect} ..."
  end

  super(data,host,port, bind_host: bind_host,
                        bind_port: bind_port,
                        &block)
end

#udp_open?(host = params[:host], port = params[:port], bind_host: params[:bind_host], bind_port: params[:bind_port], **kwargs) ⇒ Boolean?

Tests whether a remote UDP port is open.

Examples:

udp_open?
# => true

Using a timeout:

udp_open?(timeout: 5)
# => nil

Parameters:

  • host (String) (defaults to: params[:host])

    The host to connect to.

  • port (Integer) (defaults to: params[:port])

    The port to connect to.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for #udp_connect.

Options Hash (**kwargs):

  • :bind_host (String, nil)

    The local host to bind to.

  • :bind_port (Integer, nil)

    The local port to bind to.

  • :timeout (Integer) — default: 5

    The maximum time to attempt connecting.

Returns:

  • (Boolean, nil)

    Specifies whether the remote UDP port is open. If no data or ICMP error were received, nil will be returned.

Since:

  • 1.0.0



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/ronin/exploits/mixins/remote_udp.rb', line 93

def udp_open?(host=params[:host],port=params[:port],
              bind_host: params[:bind_host],
              bind_port: params[:bind_port],
              **kwargs)
  if debug?
    print_debug "Testing if #{host}:#{port} is open ..."
  end

  super(host,port, bind_host: bind_host,
                   bind_port: bind_port,
                   **kwargs)
end

#udp_send(data, host = params[:host], port = params[:port], bind_host: params[:bind_host], bind_port: params[:bind_port]) ⇒ true

Connects to a specified host and port, sends the given data and then closes the connection.

Examples:

buffer = "GET /" + ('A' * 4096) + "\n\r"
udp_send(buffer)
# => true

Parameters:

  • data (String)

    The data to send through the connection.

  • host (String) (defaults to: params[:host])

    The host to connect to.

  • port (Integer) (defaults to: params[:port])

    The port to connect to.

  • bind_host (String, nil) (defaults to: params[:bind_host])

    The local host to bind to.

  • bind_port (Integer, nil) (defaults to: params[:bind_port])

    The local port to bind to.

Returns:

  • (true)

    The data was successfully sent.

Since:

  • 1.0.0



257
258
259
260
261
262
263
# File 'lib/ronin/exploits/mixins/remote_udp.rb', line 257

def udp_send(data,host=params[:host],port=params[:port], bind_host: params[:bind_host], bind_port: params[:bind_port])
  if debug?
    print_debug "Sending #{data.inspect} to #{host}:#{port} ..."
  end

  super(data,host,port, bind_host: bind_host, bind_port: bind_port)
end