ronin-support 0.3.0 → 0.4.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog.md +77 -7
- data/README.md +19 -3
- data/gemspec.yml +2 -2
- data/lib/ronin/extensions/regexp.rb +50 -2
- data/lib/ronin/extensions/string.rb +1 -0
- data/lib/ronin/formatting.rb +1 -0
- data/lib/ronin/formatting/extensions.rb +1 -0
- data/lib/ronin/formatting/extensions/binary/string.rb +56 -5
- data/lib/ronin/formatting/extensions/html/string.rb +6 -7
- data/lib/ronin/formatting/extensions/sql/string.rb +34 -0
- data/lib/ronin/formatting/extensions/text/string.rb +0 -180
- data/lib/ronin/fuzzing.rb +21 -0
- data/lib/ronin/fuzzing/extensions.rb +20 -0
- data/lib/ronin/fuzzing/extensions/string.rb +380 -0
- data/lib/ronin/fuzzing/fuzzing.rb +191 -0
- data/lib/ronin/network/esmtp.rb +94 -1
- data/lib/ronin/network/extensions/esmtp/net.rb +2 -82
- data/lib/ronin/network/extensions/http/net.rb +1 -736
- data/lib/ronin/network/extensions/imap/net.rb +1 -103
- data/lib/ronin/network/extensions/pop3/net.rb +1 -71
- data/lib/ronin/network/extensions/smtp/net.rb +2 -157
- data/lib/ronin/network/extensions/ssl/net.rb +1 -132
- data/lib/ronin/network/extensions/tcp/net.rb +2 -296
- data/lib/ronin/network/extensions/telnet/net.rb +1 -135
- data/lib/ronin/network/extensions/udp/net.rb +2 -214
- data/lib/ronin/network/http/http.rb +750 -5
- data/lib/ronin/network/imap.rb +105 -2
- data/lib/ronin/network/mixins.rb +1 -1
- data/lib/ronin/network/mixins/esmtp.rb +49 -52
- data/lib/ronin/network/mixins/http.rb +49 -53
- data/lib/ronin/network/mixins/imap.rb +47 -44
- data/lib/ronin/network/mixins/mixin.rb +58 -0
- data/lib/ronin/network/mixins/pop3.rb +44 -38
- data/lib/ronin/network/mixins/smtp.rb +49 -51
- data/lib/ronin/network/mixins/tcp.rb +56 -69
- data/lib/ronin/network/mixins/telnet.rb +57 -50
- data/lib/ronin/network/mixins/udp.rb +48 -52
- data/lib/ronin/network/network.rb +1 -0
- data/lib/ronin/network/pop3.rb +72 -2
- data/lib/ronin/network/smtp/email.rb +1 -0
- data/lib/ronin/network/smtp/smtp.rb +159 -3
- data/lib/ronin/network/ssl.rb +131 -2
- data/lib/ronin/network/tcp.rb +306 -1
- data/lib/ronin/network/telnet.rb +136 -2
- data/lib/ronin/network/udp.rb +229 -1
- data/lib/ronin/support.rb +2 -3
- data/lib/ronin/support/support.rb +38 -0
- data/lib/ronin/support/version.rb +1 -1
- data/lib/ronin/templates/erb.rb +2 -1
- data/lib/ronin/ui/output/helpers.rb +35 -1
- data/lib/ronin/ui/shell.rb +12 -2
- data/lib/ronin/wordlist.rb +157 -0
- data/spec/extensions/regexp_spec.rb +38 -0
- data/spec/formatting/html/string_spec.rb +1 -1
- data/spec/formatting/sql/string_spec.rb +23 -3
- data/spec/formatting/text/string_spec.rb +0 -110
- data/spec/fuzzing/string_spec.rb +158 -0
- data/spec/wordlist_spec.rb +65 -0
- metadata +35 -27
@@ -17,302 +17,8 @@
|
|
17
17
|
# along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#
|
19
19
|
|
20
|
-
require '
|
20
|
+
require 'ronin/network/tcp'
|
21
21
|
|
22
22
|
module Net
|
23
|
-
|
24
|
-
# Creates a new TCPSocket object connected to a given host and port.
|
25
|
-
#
|
26
|
-
# @param [String] host
|
27
|
-
# The host to connect to.
|
28
|
-
#
|
29
|
-
# @param [Integer] port
|
30
|
-
# The port to connect to.
|
31
|
-
#
|
32
|
-
# @param [String] local_host (nil)
|
33
|
-
# The local host to bind to.
|
34
|
-
#
|
35
|
-
# @param [Integer] local_port (nil)
|
36
|
-
# The local port to bind to.
|
37
|
-
#
|
38
|
-
# @yield [socket]
|
39
|
-
# If a block is given, it will be passed the newly created socket.
|
40
|
-
#
|
41
|
-
# @yieldparam [TCPsocket] socket
|
42
|
-
# The newly created TCPSocket object.
|
43
|
-
#
|
44
|
-
# @return [TCPSocket]
|
45
|
-
# The newly created TCPSocket object.
|
46
|
-
#
|
47
|
-
# @example
|
48
|
-
# Net.tcp_connect('www.hackety.org',80) # => TCPSocket
|
49
|
-
#
|
50
|
-
# @example
|
51
|
-
# Net.tcp_connect('www.wired.com',80) do |sock|
|
52
|
-
# sock.write("GET /\n\n")
|
53
|
-
# puts sock.readlines
|
54
|
-
# sock.close
|
55
|
-
# end
|
56
|
-
#
|
57
|
-
# @api public
|
58
|
-
#
|
59
|
-
def Net.tcp_connect(host,port,local_host=nil,local_port=nil)
|
60
|
-
host = host.to_s
|
61
|
-
local_host = if local_host
|
62
|
-
local_host.to_s
|
63
|
-
end
|
64
|
-
|
65
|
-
sock = TCPSocket.new(host,port,local_host,local_port)
|
66
|
-
|
67
|
-
yield sock if block_given?
|
68
|
-
return sock
|
69
|
-
end
|
70
|
-
|
71
|
-
#
|
72
|
-
# Creates a new TCPSocket object, connected to a given host and port.
|
73
|
-
# The given data will then be written to the newly created TCPSocket.
|
74
|
-
#
|
75
|
-
# @param [String] data
|
76
|
-
# The data to send through the connection.
|
77
|
-
#
|
78
|
-
# @param [String] host
|
79
|
-
# The host to connect to.
|
80
|
-
#
|
81
|
-
# @param [Integer] port
|
82
|
-
# The port to connect to.
|
83
|
-
#
|
84
|
-
# @param [String] local_host (nil)
|
85
|
-
# The local host to bind to.
|
86
|
-
#
|
87
|
-
# @param [Integer] local_port (nil)
|
88
|
-
# The local port to bind to.
|
89
|
-
#
|
90
|
-
# @yield [socket]
|
91
|
-
# If a block is given, it will be passed the newly created socket.
|
92
|
-
#
|
93
|
-
# @yieldparam [TCPsocket] socket
|
94
|
-
# The newly created TCPSocket object.
|
95
|
-
#
|
96
|
-
# @api public
|
97
|
-
#
|
98
|
-
def Net.tcp_connect_and_send(data,host,port,local_host=nil,local_port=nil)
|
99
|
-
sock = Net.tcp_connect(host,port,local_host,local_port)
|
100
|
-
sock.write(data)
|
101
|
-
|
102
|
-
yield sock if block_given?
|
103
|
-
return sock
|
104
|
-
end
|
105
|
-
|
106
|
-
#
|
107
|
-
# Creates a new temporary TCPSocket object, connected to the given host
|
108
|
-
# and port.
|
109
|
-
#
|
110
|
-
# @param [String] host
|
111
|
-
# The host to connect to.
|
112
|
-
#
|
113
|
-
# @param [Integer] port
|
114
|
-
# The port to connect to.
|
115
|
-
#
|
116
|
-
# @param [String] local_host (nil)
|
117
|
-
# The local host to bind to.
|
118
|
-
#
|
119
|
-
# @param [Integer] local_port (nil)
|
120
|
-
# The local port to bind to.
|
121
|
-
#
|
122
|
-
# @yield [socket]
|
123
|
-
# If a block is given, it will be passed the newly created socket.
|
124
|
-
# After the block has returned, the socket will then be closed.
|
125
|
-
#
|
126
|
-
# @yieldparam [TCPsocket] socket
|
127
|
-
# The newly created TCPSocket object.
|
128
|
-
#
|
129
|
-
# @return [nil]
|
130
|
-
#
|
131
|
-
# @api public
|
132
|
-
#
|
133
|
-
def Net.tcp_session(host,port,local_host=nil,local_port=nil)
|
134
|
-
sock = Net.tcp_connect(host,port,local_host,local_port)
|
135
|
-
|
136
|
-
yield sock if block_given?
|
137
|
-
|
138
|
-
sock.close
|
139
|
-
return nil
|
140
|
-
end
|
141
|
-
|
142
|
-
#
|
143
|
-
# Reads the banner from the service running on the given host and port.
|
144
|
-
#
|
145
|
-
# @param [String] host
|
146
|
-
# The host to connect to.
|
147
|
-
#
|
148
|
-
# @param [Integer] port
|
149
|
-
# The port to connect to.
|
150
|
-
#
|
151
|
-
# @param [String] local_host (nil)
|
152
|
-
# The local host to bind to.
|
153
|
-
#
|
154
|
-
# @param [Integer] local_port (nil)
|
155
|
-
# The local port to bind to.
|
156
|
-
#
|
157
|
-
# @yield [banner]
|
158
|
-
# If a block is given, it will be passed the grabbed banner.
|
159
|
-
#
|
160
|
-
# @yieldparam [String] banner
|
161
|
-
# The grabbed banner.
|
162
|
-
#
|
163
|
-
# @return [String]
|
164
|
-
# The grabbed banner.
|
165
|
-
#
|
166
|
-
# @example
|
167
|
-
# Net.tcp_banner('pop.gmail.com',25)
|
168
|
-
# # => "220 mx.google.com ESMTP c20sm3096959rvf.1"
|
169
|
-
#
|
170
|
-
# @api public
|
171
|
-
#
|
172
|
-
def Net.tcp_banner(host,port,local_host=nil,local_port=nil)
|
173
|
-
banner = nil
|
174
|
-
|
175
|
-
Net.tcp_session(host,port,local_host,local_port) do |sock|
|
176
|
-
banner = sock.readline.strip
|
177
|
-
end
|
178
|
-
|
179
|
-
yield banner if block_given?
|
180
|
-
return banner
|
181
|
-
end
|
182
|
-
|
183
|
-
#
|
184
|
-
# Connects to a specified host and port, sends the given data and then
|
185
|
-
# closes the connection.
|
186
|
-
#
|
187
|
-
# @param [String] data
|
188
|
-
# The data to send through the connection.
|
189
|
-
#
|
190
|
-
# @param [String] host
|
191
|
-
# The host to connect to.
|
192
|
-
#
|
193
|
-
# @param [Integer] port
|
194
|
-
# The port to connect to.
|
195
|
-
#
|
196
|
-
# @param [String] local_host (nil)
|
197
|
-
# The local host to bind to.
|
198
|
-
#
|
199
|
-
# @param [Integer] local_port (nil)
|
200
|
-
# The local port to bind to.
|
201
|
-
#
|
202
|
-
# @return [true]
|
203
|
-
# The data was successfully sent.
|
204
|
-
#
|
205
|
-
# @example
|
206
|
-
# buffer = "GET /" + ('A' * 4096) + "\n\r"
|
207
|
-
# Net.tcp_send(buffer,'victim.com',80)
|
208
|
-
# # => true
|
209
|
-
#
|
210
|
-
# @api public
|
211
|
-
#
|
212
|
-
def Net.tcp_send(data,host,port,local_host=nil,local_port=nil)
|
213
|
-
Net.tcp_session(host,port,local_host,local_port) do |sock|
|
214
|
-
sock.write(data)
|
215
|
-
end
|
216
|
-
|
217
|
-
return true
|
218
|
-
end
|
219
|
-
|
220
|
-
#
|
221
|
-
# Creates a new TCPServer listening on a given host and port.
|
222
|
-
#
|
223
|
-
# @param [Integer] port
|
224
|
-
# The local port to listen on.
|
225
|
-
#
|
226
|
-
# @param [String] host ('0.0.0.0')
|
227
|
-
# The host to bind to.
|
228
|
-
#
|
229
|
-
# @return [TCPServer]
|
230
|
-
# The new TCP server.
|
231
|
-
#
|
232
|
-
# @example
|
233
|
-
# Net.tcp_server(1337)
|
234
|
-
#
|
235
|
-
# @api public
|
236
|
-
#
|
237
|
-
def Net.tcp_server(port,host='0.0.0.0')
|
238
|
-
host = host.to_s
|
239
|
-
|
240
|
-
server = TCPServer.new(host,port)
|
241
|
-
server.listen(3)
|
242
|
-
|
243
|
-
yield server if block_given?
|
244
|
-
return server
|
245
|
-
end
|
246
|
-
|
247
|
-
#
|
248
|
-
# Creates a new temporary TCPServer listening on a host and port.
|
249
|
-
#
|
250
|
-
# @param [Integer] port
|
251
|
-
# The local port to bind to.
|
252
|
-
#
|
253
|
-
# @param [String] host ('0.0.0.0')
|
254
|
-
# The host to bind to.
|
255
|
-
#
|
256
|
-
# @yield [server]
|
257
|
-
# The block which will be called after the server has been created.
|
258
|
-
# After the block has finished, the server will be closed.
|
259
|
-
#
|
260
|
-
# @yieldparam [TCPServer] server
|
261
|
-
# The newly created TCP server.
|
262
|
-
#
|
263
|
-
# @return [nil]
|
264
|
-
#
|
265
|
-
# @example
|
266
|
-
# Net.tcp_server_session(1337) do |server|
|
267
|
-
# client1 = server.accept
|
268
|
-
# client2 = server.accept
|
269
|
-
#
|
270
|
-
# client2.write(server.read_line)
|
271
|
-
#
|
272
|
-
# client1.close
|
273
|
-
# client2.close
|
274
|
-
# end
|
275
|
-
#
|
276
|
-
# @api public
|
277
|
-
#
|
278
|
-
def Net.tcp_server_session(port,host='0.0.0.0',&block)
|
279
|
-
server = Net.tcp_server(port,host,&block)
|
280
|
-
server.close()
|
281
|
-
return nil
|
282
|
-
end
|
283
|
-
|
284
|
-
#
|
285
|
-
# Creates a new TCPServer listening on a given host and port,
|
286
|
-
# accepts only one client and then stops listening.
|
287
|
-
#
|
288
|
-
# @param [Integer] port
|
289
|
-
# After the block has finished, the client and the server will be
|
290
|
-
# closed.
|
291
|
-
#
|
292
|
-
# @yieldparam [TCPSocket] client
|
293
|
-
# The newly connected client.
|
294
|
-
#
|
295
|
-
# @return [nil]
|
296
|
-
#
|
297
|
-
# @example
|
298
|
-
# Net.tcp_single_server(1337) do |client|
|
299
|
-
# client.puts 'lol'
|
300
|
-
# end
|
301
|
-
#
|
302
|
-
# @api public
|
303
|
-
#
|
304
|
-
def Net.tcp_single_server(port,host='0.0.0.0')
|
305
|
-
host = host.to_s
|
306
|
-
|
307
|
-
server = TCPServer.new(host,port)
|
308
|
-
server.listen(1)
|
309
|
-
|
310
|
-
client = server.accept
|
311
|
-
|
312
|
-
yield client if block_given?
|
313
|
-
|
314
|
-
client.close
|
315
|
-
server.close
|
316
|
-
return nil
|
317
|
-
end
|
23
|
+
extend Ronin::Network::TCP
|
318
24
|
end
|
@@ -19,140 +19,6 @@
|
|
19
19
|
|
20
20
|
require 'ronin/network/telnet'
|
21
21
|
|
22
|
-
require 'net/telnet'
|
23
|
-
|
24
22
|
module Net
|
25
|
-
|
26
|
-
# Creates a new Telnet connection.
|
27
|
-
#
|
28
|
-
# @param [String] host
|
29
|
-
# The host to connect to.
|
30
|
-
#
|
31
|
-
# @param [Hash] options
|
32
|
-
# Additional options.
|
33
|
-
#
|
34
|
-
# @option options [Integer] :port (Ronin::Network::Telnet.default_port)
|
35
|
-
# The port to connect to.
|
36
|
-
#
|
37
|
-
# @option options [Boolean] :binmode
|
38
|
-
# Indicates that newline substitution shall not be performed.
|
39
|
-
#
|
40
|
-
# @option options [String] :output_log
|
41
|
-
# The name of the file to write connection status messages and all
|
42
|
-
# received traffic to.
|
43
|
-
#
|
44
|
-
# @option options [String] :dump_log
|
45
|
-
# Similar to the `:output_log` option, but connection output is also
|
46
|
-
# written in hexdump format.
|
47
|
-
#
|
48
|
-
# @option options [Regexp] :prompt (Ronin::Network::Telnet.default_prompt)
|
49
|
-
# A regular expression matching the host command-line prompt sequence,
|
50
|
-
# used to determine when a command has finished.
|
51
|
-
#
|
52
|
-
# @option options [Boolean] :telnet (true)
|
53
|
-
# Indicates that the connection shall behave as a telnet connection.
|
54
|
-
#
|
55
|
-
# @option options [Boolean] :plain
|
56
|
-
# Indicates that the connection shall behave as a normal TCP
|
57
|
-
# connection.
|
58
|
-
#
|
59
|
-
# @option options [Integer] :timeout (Ronin::Network::Telnet.default_timeout)
|
60
|
-
# The number of seconds to wait before timing out both the initial
|
61
|
-
# attempt to connect to host, and all attempts to read data from the
|
62
|
-
# host.
|
63
|
-
#
|
64
|
-
# @option options [Integer] :wait_time
|
65
|
-
# The amount of time to wait after seeing what looks like a prompt.
|
66
|
-
#
|
67
|
-
# @option options [Net::Telnet, IO] :proxy (Ronin::Network::Telnet.proxy)
|
68
|
-
# A proxy object to used instead of opening a direct connection to the
|
69
|
-
# host.
|
70
|
-
#
|
71
|
-
# @option options [String] :user
|
72
|
-
# The user to login as.
|
73
|
-
#
|
74
|
-
# @option options [String] :password
|
75
|
-
# The password to login with.
|
76
|
-
#
|
77
|
-
# @yield [session]
|
78
|
-
# If a block is given, it will be passed the newly created Telnet
|
79
|
-
# session.
|
80
|
-
#
|
81
|
-
# @yieldparam [Net::Telnet] session
|
82
|
-
# The newly created Telnet session.
|
83
|
-
#
|
84
|
-
# @return [Net::Telnet]
|
85
|
-
# The Telnet session
|
86
|
-
#
|
87
|
-
# @example
|
88
|
-
# Net.telnet_connect('towel.blinkenlights.nl')
|
89
|
-
# # => #<Net::Telnet: ...>
|
90
|
-
#
|
91
|
-
# @api public
|
92
|
-
#
|
93
|
-
def Net.telnet_connect(host,options={})
|
94
|
-
host = host.to_s
|
95
|
-
telnet_options = {}
|
96
|
-
|
97
|
-
telnet_options['Host'] = host
|
98
|
-
telnet_options['Port'] = (options[:port] || Ronin::Network::Telnet.default_port)
|
99
|
-
telnet_options['Binmode'] = options[:binmode]
|
100
|
-
telnet_options['Output_log'] = options[:output_log]
|
101
|
-
telnet_options['Dump_log'] = options[:dump_log]
|
102
|
-
telnet_options['Prompt'] = (options[:prompt] || Ronin::Network::Telnet.default_prompt)
|
103
|
-
|
104
|
-
if (options[:telnet] && !options[:plain])
|
105
|
-
telnet_options['Telnetmode'] = true
|
106
|
-
end
|
107
|
-
|
108
|
-
telnet_options['Timeout'] = (options[:timeout] || Ronin::Network::Telnet.default_timeout)
|
109
|
-
telnet_options['Waittime'] = options[:wait_time]
|
110
|
-
telnet_options['Proxy'] = (options[:proxy] || Ronin::Network::Telnet.proxy)
|
111
|
-
|
112
|
-
user = options[:user]
|
113
|
-
passwd = options[:passwd]
|
114
|
-
|
115
|
-
session = Net::Telnet.new(telnet_options)
|
116
|
-
session.login(user,passwd) if user
|
117
|
-
|
118
|
-
yield session if block_given?
|
119
|
-
return session
|
120
|
-
end
|
121
|
-
|
122
|
-
#
|
123
|
-
# Starts a new Telnet session.
|
124
|
-
#
|
125
|
-
# @param [String] host
|
126
|
-
# The host to connect to.
|
127
|
-
#
|
128
|
-
# @param [Hash] options
|
129
|
-
# Additional options.
|
130
|
-
#
|
131
|
-
# @yield [session]
|
132
|
-
# If a block is given, it will be passed the newly created
|
133
|
-
# Telnet session. After the block has returned, the Telnet session
|
134
|
-
# will be closed.
|
135
|
-
#
|
136
|
-
# @yieldparam [Net::Telnet] session
|
137
|
-
# The newly created Telnet session.
|
138
|
-
#
|
139
|
-
# @return [nil]
|
140
|
-
#
|
141
|
-
# @example
|
142
|
-
# Net.telnet_session('towel.blinkenlights.nl') do |movie|
|
143
|
-
# movie.each_line { |line| puts line }
|
144
|
-
# end
|
145
|
-
#
|
146
|
-
# @see Net.telnet_session
|
147
|
-
#
|
148
|
-
# @api public
|
149
|
-
#
|
150
|
-
def Net.telnet_session(host,options={})
|
151
|
-
session = Net.telnet_connect(host,options)
|
152
|
-
|
153
|
-
yield session if block_given?
|
154
|
-
|
155
|
-
session.close
|
156
|
-
return nil
|
157
|
-
end
|
23
|
+
extend Ronin::Network::Telnet
|
158
24
|
end
|
@@ -17,220 +17,8 @@
|
|
17
17
|
# along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#
|
19
19
|
|
20
|
-
require '
|
20
|
+
require 'ronin/network/udp'
|
21
21
|
|
22
22
|
module Net
|
23
|
-
|
24
|
-
# Creates a new UDPSocket object connected to a given host and port.
|
25
|
-
#
|
26
|
-
# @param [String] host
|
27
|
-
# The host to connect to.
|
28
|
-
#
|
29
|
-
# @param [Integer] port
|
30
|
-
# The port to connect to.
|
31
|
-
#
|
32
|
-
# @param [String] local_host (nil)
|
33
|
-
# The local host to bind to.
|
34
|
-
#
|
35
|
-
# @param [Integer] local_port (nil)
|
36
|
-
# The local port to bind to.
|
37
|
-
#
|
38
|
-
# @yield [socket]
|
39
|
-
# If a block is given, it will be passed the newly created socket.
|
40
|
-
#
|
41
|
-
# @yieldparam [UDPsocket] socket
|
42
|
-
# The newly created UDPSocket object.
|
43
|
-
#
|
44
|
-
# @return [UDPSocket]
|
45
|
-
# The newly created UDPSocket object.
|
46
|
-
#
|
47
|
-
# @example
|
48
|
-
# Net.udp_connect('www.hackety.org',80)
|
49
|
-
# # => UDPSocket
|
50
|
-
#
|
51
|
-
# @example
|
52
|
-
# Net.udp_connect('www.wired.com',80) do |sock|
|
53
|
-
# puts sock.readlines
|
54
|
-
# end
|
55
|
-
#
|
56
|
-
# @api public
|
57
|
-
#
|
58
|
-
def Net.udp_connect(host,port,local_host=nil,local_port=nil)
|
59
|
-
host = host.to_s
|
60
|
-
local_host = if local_host
|
61
|
-
local_host.to_s
|
62
|
-
end
|
63
|
-
|
64
|
-
sock = UDPSocket.new(host,port,local_host,local_port)
|
65
|
-
|
66
|
-
yield sock if block_given?
|
67
|
-
return sock
|
68
|
-
end
|
69
|
-
|
70
|
-
#
|
71
|
-
# Creates a new UDPSocket object, connected to a given host and port.
|
72
|
-
# The given data will then be written to the newly created UDPSocket.
|
73
|
-
#
|
74
|
-
# @param [String] data
|
75
|
-
# The data to send through the connection.
|
76
|
-
#
|
77
|
-
# @param [String] host
|
78
|
-
# The host to connect to.
|
79
|
-
#
|
80
|
-
# @param [Integer] port
|
81
|
-
# The port to connect to.
|
82
|
-
#
|
83
|
-
# @param [String] local_host (nil)
|
84
|
-
# The local host to bind to.
|
85
|
-
#
|
86
|
-
# @param [Integer] local_port (nil)
|
87
|
-
# The local port to bind to.
|
88
|
-
#
|
89
|
-
# @yield [socket]
|
90
|
-
# If a block is given, it will be passed the newly created socket.
|
91
|
-
#
|
92
|
-
# @yieldparam [UDPsocket] socket
|
93
|
-
# The newly created UDPSocket object.
|
94
|
-
#
|
95
|
-
# @return [UDPSocket]
|
96
|
-
# The newly created UDPSocket object.
|
97
|
-
#
|
98
|
-
# @api public
|
99
|
-
#
|
100
|
-
def Net.udp_connect_and_send(data,host,port,local_host=nil,local_port=nil)
|
101
|
-
sock = Net.udp_connect(host,port,local_host,local_port)
|
102
|
-
sock.write(data)
|
103
|
-
|
104
|
-
yield sock if block_given?
|
105
|
-
return sock
|
106
|
-
end
|
107
|
-
|
108
|
-
#
|
109
|
-
# Creates a new temporary UDPSocket object, connected to the given host
|
110
|
-
# and port.
|
111
|
-
#
|
112
|
-
# @param [String] host
|
113
|
-
# The host to connect to.
|
114
|
-
#
|
115
|
-
# @param [Integer] port
|
116
|
-
# The port to connect to.
|
117
|
-
#
|
118
|
-
# @param [String] local_host (nil)
|
119
|
-
# The local host to bind to.
|
120
|
-
#
|
121
|
-
# @param [Integer] local_port (nil)
|
122
|
-
# The local port to bind to.
|
123
|
-
#
|
124
|
-
# @yield [socket]
|
125
|
-
# If a block is given, it will be passed the newly created socket.
|
126
|
-
# After the block has returned, the socket will then be closed.
|
127
|
-
#
|
128
|
-
# @yieldparam [UDPsocket] socket
|
129
|
-
# The newly created UDPSocket object.
|
130
|
-
#
|
131
|
-
# @return [nil]
|
132
|
-
#
|
133
|
-
# @api public
|
134
|
-
#
|
135
|
-
def Net.udp_session(host,port,local_host=nil,local_port=nil)
|
136
|
-
sock = Net.udp_connect(host,port,local_host,local_port)
|
137
|
-
|
138
|
-
yield sock if block_given?
|
139
|
-
|
140
|
-
sock.close
|
141
|
-
return nil
|
142
|
-
end
|
143
|
-
|
144
|
-
#
|
145
|
-
# Reads the banner from the service running on the given host and port.
|
146
|
-
#
|
147
|
-
# @param [String] host
|
148
|
-
# The host to connect to.
|
149
|
-
#
|
150
|
-
# @param [Integer] port
|
151
|
-
# The port to connect to.
|
152
|
-
#
|
153
|
-
# @param [String] local_host (nil)
|
154
|
-
# The local host to bind to.
|
155
|
-
#
|
156
|
-
# @param [Integer] local_port (nil)
|
157
|
-
# The local port to bind to.
|
158
|
-
#
|
159
|
-
# @yield [banner]
|
160
|
-
# If a block is given, it will be passed the grabbed banner.
|
161
|
-
#
|
162
|
-
# @yieldparam [String] banner
|
163
|
-
# The grabbed banner.
|
164
|
-
#
|
165
|
-
# @return [String]
|
166
|
-
# The grabbed banner.
|
167
|
-
#
|
168
|
-
# @api public
|
169
|
-
#
|
170
|
-
def Net.udp_banner(host,port,local_host=nil,local_port=nil)
|
171
|
-
banner = nil
|
172
|
-
|
173
|
-
Net.udp_session(host,port,local_host,local_port) do |sock|
|
174
|
-
banner = sock.readline
|
175
|
-
end
|
176
|
-
|
177
|
-
yield banner if block_given?
|
178
|
-
return banner
|
179
|
-
end
|
180
|
-
|
181
|
-
#
|
182
|
-
# Creates a new UDPServer listening on a given host and port.
|
183
|
-
#
|
184
|
-
# @param [Integer] port
|
185
|
-
# The local port to listen on.
|
186
|
-
#
|
187
|
-
# @param [String] host ('0.0.0.0')
|
188
|
-
# The host to bind to.
|
189
|
-
#
|
190
|
-
# @return [UDPServer]
|
191
|
-
# The new UDP server.
|
192
|
-
#
|
193
|
-
# @example
|
194
|
-
# Net.udp_server(1337)
|
195
|
-
#
|
196
|
-
# @api public
|
197
|
-
#
|
198
|
-
def Net.udp_server(port,host='0.0.0.0')
|
199
|
-
host = host.to_s
|
200
|
-
server = UDPServer.new(host,port)
|
201
|
-
|
202
|
-
yield server if block_given?
|
203
|
-
return server
|
204
|
-
end
|
205
|
-
|
206
|
-
#
|
207
|
-
# Creates a new temporary UDPServer listening on a given host and port.
|
208
|
-
#
|
209
|
-
# @param [Integer] port
|
210
|
-
# The local port to bind to.
|
211
|
-
#
|
212
|
-
# @param [String] host ('0.0.0.0')
|
213
|
-
# The host to bind to.
|
214
|
-
#
|
215
|
-
# @yield [server]
|
216
|
-
# The block which will be called after the server has been created.
|
217
|
-
# After the block has finished, the server will be closed.
|
218
|
-
#
|
219
|
-
# @yieldparam [UDPServer] server
|
220
|
-
# The newly created UDP server.
|
221
|
-
#
|
222
|
-
# @return [nil]
|
223
|
-
#
|
224
|
-
# @example
|
225
|
-
# Net.udp_server_session(1337) do |server|
|
226
|
-
# data, sender = server.recvfrom(1024)
|
227
|
-
# end
|
228
|
-
#
|
229
|
-
# @api public
|
230
|
-
#
|
231
|
-
def Net.udp_server_session(port,host='0.0.0.0',&block)
|
232
|
-
server = Net.udp_server(port,host,&block)
|
233
|
-
server.close()
|
234
|
-
return nil
|
235
|
-
end
|
23
|
+
extend Ronin::Network::UDP
|
236
24
|
end
|