Module: Ronin::Support::Network::UDP
- Defined in:
- lib/ronin/support/network/udp.rb,
lib/ronin/support/network/udp/mixin.rb,
lib/ronin/support/network/udp/proxy.rb
Overview
Defined Under Namespace
Class Method Summary collapse
-
.banner(host, port, **kwargs) {|banner| ... } ⇒ String
Reads the banner from the service running on the given host and port.
-
.connect(host, port, bind_host: nil, bind_port: nil) {|socket| ... } ⇒ UDPSocket?
Creates a new UDPSocket object connected to a given host and port.
-
.connect_and_send(data, host, port, **kwargs) {|socket| ... } ⇒ UDPSocket
Creates a new UDPSocket object, connected to a given host and port.
-
.open?(host, port, timeout: 5, **kwargs) ⇒ Boolean?
Tests whether a remote UDP port is open.
-
.recv(**kwargs) {|server, (client_host, client_port), mesg| ... } ⇒ nil
Creates a new UDPServer listening on a given host and port, accepts only one message from a client.
-
.send(data, host, port, **kwargs) ⇒ true
Connects to a specified host and port, sends the given data and then closes the connection.
-
.server(port: nil, host: nil) {|server| ... } ⇒ UDPServer
Creates a new UDPServer listening on a given host and port.
-
.server_loop(**kwargs) {|server, (client_host, client_port), mesg| ... } ⇒ nil
Creates a new UDPServer listening on a given host and port, accepting messages from clients in a loop.
-
.server_session(**kwargs) {|server| ... } ⇒ nil
Creates a new temporary UDPServer listening on a given host and port.
Class Method Details
.banner(host, port, **kwargs) {|banner| ... } ⇒ String
Reads the banner from the service running on the given host and port.
263 264 265 266 267 268 269 270 271 272 |
# File 'lib/ronin/support/network/udp.rb', line 263 def self.(host,port,**kwargs) = nil connect(host,port,**kwargs) do |socket| = socket.readline end yield if block_given? return end |
.connect(host, port, bind_host: nil, bind_port: nil) {|socket| ... } ⇒ UDPSocket?
Creates a new UDPSocket object connected to a given host and port.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/ronin/support/network/udp.rb', line 127 def self.connect(host,port, bind_host: nil, bind_port: nil) host = DNS::IDN.to_ascii(host) port = port.to_i socket = UDPSocket.new if bind_host || bind_port socket.bind(bind_host.to_s,bind_port.to_i) end socket.connect(host,port) if block_given? begin yield socket ensure socket.close end else return socket end end |
.connect_and_send(data, host, port, **kwargs) {|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.
183 184 185 186 187 188 189 |
# File 'lib/ronin/support/network/udp.rb', line 183 def self.connect_and_send(data,host,port,**kwargs) socket = connect(host,port,**kwargs) socket.write(data) yield socket if block_given? return socket end |
.open?(host, port, timeout: 5, **kwargs) ⇒ Boolean?
Tests whether a remote UDP port is open.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/ronin/support/network/udp.rb', line 69 def self.open?(host,port, timeout: 5, **kwargs) Timeout.timeout(timeout) do connect(host,port,**kwargs) do |socket| # send an empty UDP packet, just like nmap socket.syswrite('') # send an empty UDP packet again, to elicit an # Errno::ECONNREFUSED socket.syswrite('') end end return true rescue Timeout::Error return nil rescue SocketError, SystemCallError return false end |
.recv(**kwargs) {|server, (client_host, client_port), mesg| ... } ⇒ nil
Creates a new UDPServer listening on a given host and port, accepts only one message from a client.
426 427 428 429 430 431 432 |
# File 'lib/ronin/support/network/udp.rb', line 426 def self.recv(**kwargs) server_session(**kwargs) do |server| mesg, addrinfo = server.recvfrom(4096) yield server, [addrinfo[3], addrinfo[1]], mesg if block_given? end end |
.send(data, host, port, **kwargs) ⇒ true
Connects to a specified host and port, sends the given data and then closes the connection.
225 226 227 228 229 230 231 |
# File 'lib/ronin/support/network/udp.rb', line 225 def self.send(data,host,port,**kwargs) connect(host,port,**kwargs) do |socket| socket.write(data) end return true end |
.server(port: nil, host: nil) {|server| ... } ⇒ UDPServer
Creates a new UDPServer listening on a given host and port.
293 294 295 296 297 298 299 |
# File 'lib/ronin/support/network/udp.rb', line 293 def self.server(port: nil, host: nil) server = UDPSocket.new server.bind(host.to_s,port.to_i) yield server if block_given? return server end |
.server_loop(**kwargs) {|server, (client_host, client_port), mesg| ... } ⇒ nil
Creates a new UDPServer listening on a given host and port, accepting messages from clients in a loop.
376 377 378 379 380 381 382 383 384 |
# File 'lib/ronin/support/network/udp.rb', line 376 def self.server_loop(**kwargs) server_session(**kwargs) do |server| loop do mesg, addrinfo = server.recvfrom(4096) yield server, [addrinfo[3], addrinfo[1]], mesg if block_given? end end end |
.server_session(**kwargs) {|server| ... } ⇒ nil
Creates a new temporary UDPServer listening on a given host and port.
330 331 332 333 334 |
# File 'lib/ronin/support/network/udp.rb', line 330 def self.server_session(**kwargs,&block) server = server(**kwargs,&block) server.close return nil end |