Module: Ronin::Exploits::Mixins::RemoteTCP

Includes:
Support::Network::TCP::Mixin
Defined in:
lib/ronin/exploits/mixins/remote_tcp.rb

Overview

Adds TCP 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::RemoteTCP.

Parameters:

Since:

  • 1.0.0



53
54
55
56
57
58
# File 'lib/ronin/exploits/mixins/remote_tcp.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

#tcp_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.

Examples:

tcp_banner
# => "220 mx.google.com ESMTP c20sm3096959rvf.1"

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) (defaults to: params[:bind_host])

    The local host to bind to.

  • bind_port (Integer) (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



229
230
231
232
233
234
235
# File 'lib/ronin/exploits/mixins/remote_tcp.rb', line 229

def tcp_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

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

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

Examples:

@socket = tcp_connect
# => TCPSocket
tcp_connect do |socket|
  socket.write("GET /\n\n")
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 (TCPsocket)

    The newly created TCPSocket object.

Returns:

  • (TCPSocket, nil)

    The newly created TCPSocket 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_tcp.rb', line 143

def tcp_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

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

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

Examples:

@socket = tcp_connect_and_send(@buffer)

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 (TCPSocket)

    The newly created TCPSocket object.

Returns:

  • (TCPSocket)

    The newly created TCPSocket object.

Since:

  • 1.0.0



187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/ronin/exploits/mixins/remote_tcp.rb', line 187

def tcp_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

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

Tests whether a remote TCP port is open.

Examples:

tcp_open?
# => true

Using a timeout:

tcp_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.

  • 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.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for #tcp_connect.

Options Hash (**kwargs):

  • :timeout (Integer) — default: 5

    The maximum time to attempt connecting.

Returns:

  • (Boolean, nil)

    Specifies whether the remote TCP port is open. If the connection was not accepted, 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_tcp.rb', line 93

def tcp_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

#tcp_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"
# ...
tcp_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) (defaults to: params[:bind_host])

    The local host to bind to.

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

    The local port to bind to.

Returns:

  • (true)

    The data was successfully sent.

Since:

  • 1.0.0



265
266
267
268
269
270
271
# File 'lib/ronin/exploits/mixins/remote_tcp.rb', line 265

def tcp_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