Class: Ronin::Support::Network::UDP::Proxy
- Defined in:
- lib/ronin/support/network/udp/proxy.rb
Overview
The UDP Proxy allows for inspecting and manipulating UDP protocols.
Example
require 'ronin/support/network/udp/proxy'
require 'hexdump'
Ronin::Support::Network::UDP::Proxy.start(:port => 1337, :server => ['4.2.2.1', 53]) do |proxy|
hex = Hexdump::Hexdump.new
proxy.on_client_data do |(client,(host,port)),server,data|
puts "#{host}:#{port} -> #{proxy}"
hex.dump(data)
end
proxy.on_server_data do |(client,(host,port)),server,data|
puts "#{host}:#{port} <- #{proxy}"
hex.dump(data)
end
end
Constant Summary
Constants inherited from Proxy
Proxy::DEFAULT_BUFFER_SIZE, Proxy::DEFAULT_HOST
Instance Attribute Summary
Attributes inherited from Proxy
#buffer_size, #connections, #host, #port, #server_host, #server_port
Instance Method Summary collapse
-
#close_client_connection(connection) ⇒ Object
protected
Closes a connection from the client to the proxy.
-
#close_proxy ⇒ Object
protected
Closes the UDP proxy socket.
-
#close_server_connection(connection) ⇒ Object
protected
Closes the connection from the proxy to the server.
-
#open ⇒ Object
Opens the UDP Proxy.
-
#open_server_connection ⇒ UDPSocket
protected
Creates a new connection from the proxy to the server.
-
#poll ⇒ Object
Polls the connections for data/errors and the proxy socket for new client connections.
-
#recv(connection) ⇒ String, (String, Array)
Receives data from a connection.
-
#send(connection, data) ⇒ Object
Sends data to a connection.
Methods inherited from Proxy
#callback, #client_connection_for, #client_connections, #client_data, #close, #close!, #close_connection, #close_connections, #ignore!, #initialize, #inspect, #listen, #on_client_data, #on_data, #on_server_data, #reset!, #reset_connection, #server_connection_for, #server_connections, #server_data, start, #start, #stop, #stop!, #to_s
Constructor Details
This class inherits a constructor from Ronin::Support::Network::Proxy
Instance Method Details
#close_client_connection(connection) ⇒ Object (protected)
no-op
Closes a connection from the client to the proxy.
167 168 169 |
# File 'lib/ronin/support/network/udp/proxy.rb', line 167 def close_client_connection(connection) # no-op end |
#close_proxy ⇒ Object (protected)
Closes the UDP proxy socket.
184 185 186 |
# File 'lib/ronin/support/network/udp/proxy.rb', line 184 def close_proxy @socket.close end |
#close_server_connection(connection) ⇒ Object (protected)
Closes the connection from the proxy to the server.
177 178 179 |
# File 'lib/ronin/support/network/udp/proxy.rb', line 177 def close_server_connection(connection) connection.close end |
#open ⇒ Object
Opens the UDP Proxy.
59 60 61 62 |
# File 'lib/ronin/support/network/udp/proxy.rb', line 59 def open @socket = UDPSocket.new @socket.bind(@host,@port) end |
#open_server_connection ⇒ UDPSocket (protected)
Creates a new connection from the proxy to the server.
152 153 154 155 156 157 |
# File 'lib/ronin/support/network/udp/proxy.rb', line 152 def open_server_connection socket = UDPSocket.new socket.connect(@server_host,@server_port) return socket end |
#poll ⇒ Object
Polls the connections for data/errors and the proxy socket for new client connections.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/ronin/support/network/udp/proxy.rb', line 70 def poll sockets = [@socket] + server_connections readable, _writtable, errors = IO.select(sockets,nil,sockets) (errors & server_connections).each do |server_socket| client_socket = client_connection_for(server_socket) close_connection(client_socket,server_socket) end (readable & server_connections).each do |server_socket| client_socket = client_connection_for(server_socket) data, _addrinfo = recv(server_socket) server_data(client_socket,server_socket,data) end if readable.include?(@socket) data, addrinfo = recv(@socket) client_socket = [@socket, [addrinfo[3], addrinfo[1]]] server_socket = (@connections[client_socket] ||= open_server_connection) client_data(client_socket,server_socket,data) end end |
#recv(connection) ⇒ String, (String, Array)
Receives data from a connection.
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/ronin/support/network/udp/proxy.rb', line 133 def recv(connection) case connection when Array socket, _host_and_port = connection socket.recvfrom(@buffer_size) when UDPSocket connection.recvfrom(@buffer_size) end end |
#send(connection, data) ⇒ Object
Sends data to a connection.
110 111 112 113 114 115 116 117 118 119 |
# File 'lib/ronin/support/network/udp/proxy.rb', line 110 def send(connection,data) case connection when Array socket, (host, port) = connection socket.send(data,0,host,port) when UDPSocket connection.send(data,0) end end |