Module: Ronin::Network::Mixins::UNIX

Includes:
Mixin, UNIX
Defined in:
lib/ronin/network/mixins/unix.rb

Overview

Adds UNIX Socket convenience methods and connection parameters to a class.

Defines the following parameters:

  • path (String) - UNIX Socket path.

Since:

  • 0.5.0

Instance Method Summary collapse

Methods included from Mixin

included

Methods included from UNIX

#unix_open?

Instance Method Details

#unix_accept {|client| ... } ⇒ Object (protected)

Opens a UNIX socket specified by the path parameter, accepts a connection, then closes the socket.

Examples:

unix_accept do |client|
  # ...
end

Yields:

  • (client)

    If a block is given, it will be passed the accepted connection.

Yield Parameters:

  • client (UNIXSocket)

    The accepted connection to UNIX socket.

See Also:

Since:

  • 0.5.0


228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/ronin/network/mixins/unix.rb', line 228

def unix_accept
  print_info "Listening on #{self.path} ..."

  super(self.path) do |client|
    print_info "Client connected to #{self.path}"

    yield client if block_given?

    print_info "Client disconnecting from #{self.path} ..."
  end

  print_info "Closed #{self.path}"
  return nil
end

#unix_connect {|socket| ... } ⇒ UNIXSocket (protected)

Connects to a UNIX socket specified by the path parameter.

Examples:

socket = unix_connect

Yields:

  • (socket)

    If a block is given, it will be passed an UNIX socket object.

Yield Parameters:

  • socket (UNIXSocket)

    The UNIX socket.

Returns:

  • (UNIXSocket)

    The UNIX socket.

See Also:

Since:

  • 0.5.0


64
65
66
67
68
# File 'lib/ronin/network/mixins/unix.rb', line 64

def unix_connect(&block)
  print_info "Connecting to #{self.path} ..."

  super(self.path,&block)
end

#unix_connect_and_send(data) {|socket| ... } ⇒ UNIXSocket (protected)

Creates a new UNIXSocket object, connected to the path parameter. The given data will then be written to the newly created UNIXSocket.

Parameters:

  • data (String)

    The data to send to the socket.

Yields:

  • (socket)

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

Yield Parameters:

  • socket (UNIXSocket)

    The newly created UNIXSocket object.

Returns:

  • (UNIXSocket)

    The newly created UNIXSocket object.

See Also:

Since:

  • 0.5.0


90
91
92
93
94
95
# File 'lib/ronin/network/mixins/unix.rb', line 90

def unix_connect_and_send(data,&block)
  print_info "Connecting to #{self.path} ..."
  print_debug "Sending data: #{data.inspect}"

  return super(data,self.path,&block)
end

#unix_send(data) ⇒ true (protected)

Connects to the UNIX socket, specified by the path parameter, sends the given data and then disconnects.

Examples:

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

Parameters:

  • data (String)

    The data to send to the UNIX socket.

Returns:

  • (true)

    The data was successfully sent.

See Also:

Since:

  • 0.4.0


144
145
146
147
148
149
150
151
152
# File 'lib/ronin/network/mixins/unix.rb', line 144

def unix_send(data)
  print_info "Connecting to #{self.path} ..."
  print_debug "Sending data: #{data.inspect}"

  super(data,self.path,&block)

  print_info "Disconnected from #{self.path}"
  return true
end

#unix_server {|server| ... } ⇒ UNIXServer (protected)

Opens a UNIX socket, listening on the path parameter.

Examples:

unix_server

Yields:

  • (server)

    The given block will be passed the newly created server.

Yield Parameters:

  • server (UNIXServer)

    The newly created server.

Returns:

  • (UNIXServer)

    The newly created server.

See Also:

Since:

  • 0.5.0


173
174
175
176
177
# File 'lib/ronin/network/mixins/unix.rb', line 173

def unix_server(&block)
  print_info "Listening on #{self.path} ..."

  return super(self.path,&block)
end

#unix_server_loop {|client| ... } ⇒ Object (protected)

Opens a UNIX socket specified by the path parameter, accepts connections in a loop.

Examples:

unix_server_loop do |client|
  # ...
end

Yields:

  • (client)

    If a block is given, it will be passed each accepted connection.

Yield Parameters:

  • client (UNIXSocket)

    An accepted connection to UNIX socket.

See Also:

Since:

  • 0.5.0


262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/ronin/network/mixins/unix.rb', line 262

def unix_server_loop
  print_info "Listening on #{self.path} ..."

  super(self.path) do |client|
    print_info "Client connected: #{self.path}"

    yield client if block_given?

    print_info "Client disconnecting: #{self.path} ..."
  end

  print_info "Closed #{self.path}"
  return nil
end

#unix_server_session {|server| ... } ⇒ nil (protected)

Opens a UNIX socket temporarily, listening on the path parameter.

Examples:

unix_server_session do |server|
  # ...
end

Yields:

  • (server)

    The given block will be passed the newly created server. When the block has finished, the server will be closed.

Yield Parameters:

  • server (UNIXServer)

    The newly created server.

Returns:

  • (nil)

See Also:

Since:

  • 0.5.0


200
201
202
203
204
205
206
207
# File 'lib/ronin/network/mixins/unix.rb', line 200

def unix_server_session(&block)
  print_info "Listening on #{self.path} ..."

  super(self.path,&block)

  print_info "Closed #{self.path}"
  return nil
end

#unix_session {|socket| ... } ⇒ Object (protected)

Creates a UNIX session to the host and port specified by the host and port parameters. If the local_host and local_port parameters are set, they will be used for the local host and port of the UNIX connection.

Yields:

  • (socket)

    If a block is given, it will be passed the newly created socket. After the block has returned, the socket will then be closed.

Yield Parameters:

  • socket (UNIXsocket)

    The newly created UNIXSocket object.

See Also:

Since:

  • 0.5.0


114
115
116
117
118
119
120
121
# File 'lib/ronin/network/mixins/unix.rb', line 114

def unix_session(&block)
  print_info "Connecting to #{self.path} ..."

  super(self.host,&block)

  print_info "Disconnected from #{self.path}"
  return nil
end