ronin-support 0.1.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. data/.document +4 -0
  2. data/.rspec +1 -0
  3. data/.yardopts +1 -0
  4. data/COPYING.txt +504 -0
  5. data/ChangeLog.md +4 -0
  6. data/Gemfile +23 -0
  7. data/README.md +98 -0
  8. data/Rakefile +29 -0
  9. data/gemspec.yml +20 -0
  10. data/lib/ronin/extensions.rb +28 -0
  11. data/lib/ronin/extensions/file.rb +63 -0
  12. data/lib/ronin/extensions/ip_addr.rb +220 -0
  13. data/lib/ronin/extensions/kernel.rb +45 -0
  14. data/lib/ronin/extensions/meta.rb +22 -0
  15. data/lib/ronin/extensions/meta/object.rb +24 -0
  16. data/lib/ronin/extensions/string.rb +200 -0
  17. data/lib/ronin/formatting.rb +26 -0
  18. data/lib/ronin/formatting/binary.rb +22 -0
  19. data/lib/ronin/formatting/digest.rb +22 -0
  20. data/lib/ronin/formatting/extensions.rb +25 -0
  21. data/lib/ronin/formatting/extensions/binary.rb +24 -0
  22. data/lib/ronin/formatting/extensions/binary/file.rb +35 -0
  23. data/lib/ronin/formatting/extensions/binary/integer.rb +147 -0
  24. data/lib/ronin/formatting/extensions/binary/string.rb +363 -0
  25. data/lib/ronin/formatting/extensions/digest.rb +23 -0
  26. data/lib/ronin/formatting/extensions/digest/file.rb +117 -0
  27. data/lib/ronin/formatting/extensions/digest/string.rb +80 -0
  28. data/lib/ronin/formatting/extensions/http.rb +23 -0
  29. data/lib/ronin/formatting/extensions/http/integer.rb +57 -0
  30. data/lib/ronin/formatting/extensions/http/string.rb +102 -0
  31. data/lib/ronin/formatting/extensions/text.rb +23 -0
  32. data/lib/ronin/formatting/extensions/text/array.rb +125 -0
  33. data/lib/ronin/formatting/extensions/text/string.rb +206 -0
  34. data/lib/ronin/formatting/http.rb +22 -0
  35. data/lib/ronin/formatting/text.rb +22 -0
  36. data/lib/ronin/network.rb +29 -0
  37. data/lib/ronin/network/esmtp.rb +22 -0
  38. data/lib/ronin/network/extensions.rb +29 -0
  39. data/lib/ronin/network/extensions/esmtp.rb +22 -0
  40. data/lib/ronin/network/extensions/esmtp/net.rb +100 -0
  41. data/lib/ronin/network/extensions/http.rb +22 -0
  42. data/lib/ronin/network/extensions/http/net.rb +661 -0
  43. data/lib/ronin/network/extensions/imap.rb +22 -0
  44. data/lib/ronin/network/extensions/imap/net.rb +124 -0
  45. data/lib/ronin/network/extensions/pop3.rb +22 -0
  46. data/lib/ronin/network/extensions/pop3/net.rb +92 -0
  47. data/lib/ronin/network/extensions/smtp.rb +22 -0
  48. data/lib/ronin/network/extensions/smtp/net.rb +110 -0
  49. data/lib/ronin/network/extensions/ssl.rb +22 -0
  50. data/lib/ronin/network/extensions/ssl/net.rb +147 -0
  51. data/lib/ronin/network/extensions/tcp.rb +22 -0
  52. data/lib/ronin/network/extensions/tcp/net.rb +304 -0
  53. data/lib/ronin/network/extensions/telnet.rb +22 -0
  54. data/lib/ronin/network/extensions/telnet/net.rb +156 -0
  55. data/lib/ronin/network/extensions/udp.rb +22 -0
  56. data/lib/ronin/network/extensions/udp/net.rb +226 -0
  57. data/lib/ronin/network/http.rb +24 -0
  58. data/lib/ronin/network/http/exceptions.rb +22 -0
  59. data/lib/ronin/network/http/exceptions/unknown_request.rb +29 -0
  60. data/lib/ronin/network/http/http.rb +290 -0
  61. data/lib/ronin/network/http/proxy.rb +307 -0
  62. data/lib/ronin/network/imap.rb +49 -0
  63. data/lib/ronin/network/network.rb +41 -0
  64. data/lib/ronin/network/pop3.rb +49 -0
  65. data/lib/ronin/network/smtp.rb +24 -0
  66. data/lib/ronin/network/smtp/email.rb +143 -0
  67. data/lib/ronin/network/smtp/smtp.rb +68 -0
  68. data/lib/ronin/network/ssl.rb +47 -0
  69. data/lib/ronin/network/tcp.rb +22 -0
  70. data/lib/ronin/network/telnet.rb +109 -0
  71. data/lib/ronin/network/udp.rb +22 -0
  72. data/lib/ronin/path.rb +132 -0
  73. data/lib/ronin/support.rb +28 -0
  74. data/lib/ronin/support/inflector.rb +40 -0
  75. data/lib/ronin/support/version.rb +27 -0
  76. data/lib/ronin/templates.rb +23 -0
  77. data/lib/ronin/templates/erb.rb +75 -0
  78. data/lib/ronin/templates/template.rb +161 -0
  79. data/ronin-support.gemspec +10 -0
  80. data/spec/extensions/file_spec.rb +24 -0
  81. data/spec/extensions/ip_addr_spec.rb +171 -0
  82. data/spec/extensions/kernel_spec.rb +30 -0
  83. data/spec/extensions/string_spec.rb +177 -0
  84. data/spec/formatting/binary/helpers/hexdumps.rb +16 -0
  85. data/spec/formatting/binary/helpers/hexdumps/ascii.bin +0 -0
  86. data/spec/formatting/binary/helpers/hexdumps/hexdump_decimal_shorts.txt +17 -0
  87. data/spec/formatting/binary/helpers/hexdumps/hexdump_hex_bytes.txt +17 -0
  88. data/spec/formatting/binary/helpers/hexdumps/hexdump_hex_shorts.txt +17 -0
  89. data/spec/formatting/binary/helpers/hexdumps/hexdump_octal_bytes.txt +17 -0
  90. data/spec/formatting/binary/helpers/hexdumps/hexdump_octal_shorts.txt +17 -0
  91. data/spec/formatting/binary/helpers/hexdumps/hexdump_repeated.txt +6 -0
  92. data/spec/formatting/binary/helpers/hexdumps/od_decimal_bytes.txt +17 -0
  93. data/spec/formatting/binary/helpers/hexdumps/od_decimal_ints.txt +17 -0
  94. data/spec/formatting/binary/helpers/hexdumps/od_decimal_quads.txt +17 -0
  95. data/spec/formatting/binary/helpers/hexdumps/od_decimal_shorts.txt +17 -0
  96. data/spec/formatting/binary/helpers/hexdumps/od_hex_bytes.txt +17 -0
  97. data/spec/formatting/binary/helpers/hexdumps/od_hex_ints.txt +17 -0
  98. data/spec/formatting/binary/helpers/hexdumps/od_hex_quads.txt +17 -0
  99. data/spec/formatting/binary/helpers/hexdumps/od_hex_shorts.txt +17 -0
  100. data/spec/formatting/binary/helpers/hexdumps/od_octal_bytes.txt +17 -0
  101. data/spec/formatting/binary/helpers/hexdumps/od_octal_ints.txt +17 -0
  102. data/spec/formatting/binary/helpers/hexdumps/od_octal_quads.txt +17 -0
  103. data/spec/formatting/binary/helpers/hexdumps/od_octal_shorts.txt +17 -0
  104. data/spec/formatting/binary/helpers/hexdumps/od_repeated.txt +6 -0
  105. data/spec/formatting/binary/helpers/hexdumps/repeated.bin +1 -0
  106. data/spec/formatting/binary/integer_spec.rb +140 -0
  107. data/spec/formatting/binary/string_spec.rb +306 -0
  108. data/spec/formatting/digest/string_spec.rb +82 -0
  109. data/spec/formatting/http/integer_spec.rb +42 -0
  110. data/spec/formatting/http/string_spec.rb +76 -0
  111. data/spec/formatting/text/array_spec.rb +105 -0
  112. data/spec/formatting/text/string_spec.rb +180 -0
  113. data/spec/network/http/http_spec.rb +280 -0
  114. data/spec/network/http/proxy_spec.rb +150 -0
  115. data/spec/network/network_spec.rb +8 -0
  116. data/spec/network/ssl_spec.rb +14 -0
  117. data/spec/path_spec.rb +84 -0
  118. data/spec/spec_helper.rb +4 -0
  119. data/spec/support_spec.rb +8 -0
  120. data/spec/templates/classes/example_erb.rb +11 -0
  121. data/spec/templates/classes/example_template.rb +35 -0
  122. data/spec/templates/erb_spec.rb +21 -0
  123. data/spec/templates/helpers/data.rb +9 -0
  124. data/spec/templates/helpers/data/includes/_relative.erb +1 -0
  125. data/spec/templates/helpers/data/templates/example.erb +1 -0
  126. data/spec/templates/template_spec.rb +54 -0
  127. metadata +286 -0
@@ -0,0 +1,22 @@
1
+ #
2
+ # Ronin - A Ruby platform for exploit development and security research.
3
+ #
4
+ # Copyright (c) 2006-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2.1 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
+ # Boston, MA 02110-1301 USA
20
+ #
21
+
22
+ require 'ronin/network/extensions/tcp/net'
@@ -0,0 +1,304 @@
1
+ #
2
+ # Ronin - A Ruby platform for exploit development and security research.
3
+ #
4
+ # Copyright (c) 2006-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2.1 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
+ # Boston, MA 02110-1301 USA
20
+ #
21
+
22
+ require 'socket'
23
+
24
+ module Net
25
+ #
26
+ # Creates a new TCPSocket object connected to a given host and port.
27
+ #
28
+ # @param [String] host
29
+ # The host to connect to.
30
+ #
31
+ # @param [Integer] port
32
+ # The port to connect to.
33
+ #
34
+ # @param [String] local_host (nil)
35
+ # The local host to bind to.
36
+ #
37
+ # @param [Integer] local_port (nil)
38
+ # The local port to bind to.
39
+ #
40
+ # @yield [socket]
41
+ # If a block is given, it will be passed the newly created socket.
42
+ #
43
+ # @yieldparam [TCPsocket] socket
44
+ # The newly created TCPSocket object.
45
+ #
46
+ # @return [TCPSocket]
47
+ # The newly created TCPSocket object.
48
+ #
49
+ # @example
50
+ # Net.tcp_connect('www.hackety.org',80) # => TCPSocket
51
+ #
52
+ # @example
53
+ # Net.tcp_connect('www.wired.com',80) do |sock|
54
+ # sock.write("GET /\n\n")
55
+ # puts sock.readlines
56
+ # sock.close
57
+ # end
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
+ def Net.tcp_connect_and_send(data,host,port,local_host=nil,local_port=nil)
97
+ sock = Net.tcp_connect(host,port,local_host,local_port)
98
+ sock.write(data)
99
+
100
+ yield sock if block_given?
101
+ return sock
102
+ end
103
+
104
+ #
105
+ # Creates a new temporary TCPSocket object, connected to the given host
106
+ # and port.
107
+ #
108
+ # @param [String] host
109
+ # The host to connect to.
110
+ #
111
+ # @param [Integer] port
112
+ # The port to connect to.
113
+ #
114
+ # @param [String] local_host (nil)
115
+ # The local host to bind to.
116
+ #
117
+ # @param [Integer] local_port (nil)
118
+ # The local port to bind to.
119
+ #
120
+ # @yield [socket]
121
+ # If a block is given, it will be passed the newly created socket.
122
+ # After the block has returned, the socket will then be closed.
123
+ #
124
+ # @yieldparam [TCPsocket] socket
125
+ # The newly created TCPSocket object.
126
+ #
127
+ # @return [nil]
128
+ #
129
+ def Net.tcp_session(host,port,local_host=nil,local_port=nil)
130
+ sock = Net.tcp_connect(host,port,local_host,local_port)
131
+
132
+ yield sock if block_given?
133
+
134
+ sock.close
135
+ return nil
136
+ end
137
+
138
+ #
139
+ # Reads the banner from the service running on the given host and port.
140
+ #
141
+ # @param [String] host
142
+ # The host to connect to.
143
+ #
144
+ # @param [Integer] port
145
+ # The port to connect to.
146
+ #
147
+ # @param [String] local_host (nil)
148
+ # The local host to bind to.
149
+ #
150
+ # @param [Integer] local_port (nil)
151
+ # The local port to bind to.
152
+ #
153
+ # @yield [banner]
154
+ # If a block is given, it will be passed the grabbed banner.
155
+ #
156
+ # @yieldparam [String] banner
157
+ # The grabbed banner.
158
+ #
159
+ # @return [String]
160
+ # The grabbed banner.
161
+ #
162
+ # @example
163
+ # Net.tcp_banner('pop.gmail.com',25)
164
+ # # => "220 mx.google.com ESMTP c20sm3096959rvf.1"
165
+ #
166
+ def Net.tcp_banner(host,port,local_host=nil,local_port=nil)
167
+ banner = nil
168
+
169
+ Net.tcp_session(host,port,local_host,local_port) do |sock|
170
+ banner = sock.readline.strip
171
+ end
172
+
173
+ yield banner if block_given?
174
+ return banner
175
+ end
176
+
177
+ #
178
+ # Connects to a specified host and port, sends the given data and then
179
+ # closes the connection.
180
+ #
181
+ # @param [String] data
182
+ # The data to send through the connection.
183
+ #
184
+ # @param [String] host
185
+ # The host to connect to.
186
+ #
187
+ # @param [Integer] port
188
+ # The port to connect to.
189
+ #
190
+ # @param [String] local_host (nil)
191
+ # The local host to bind to.
192
+ #
193
+ # @param [Integer] local_port (nil)
194
+ # The local port to bind to.
195
+ #
196
+ # @return [true]
197
+ # The data was successfully sent.
198
+ #
199
+ # @example
200
+ # buffer = "GET /" + ('A' * 4096) + "\n\r"
201
+ # Net.tcp_send(buffer,'victim.com',80)
202
+ # # => true
203
+ #
204
+ def Net.tcp_send(data,host,port,local_host=nil,local_port=nil)
205
+ Net.tcp_session(host,port,local_host,local_port) do |sock|
206
+ sock.write(data)
207
+ end
208
+
209
+ return true
210
+ end
211
+
212
+ #
213
+ # Creates a new TCPServer listening on a given host and port.
214
+ #
215
+ # @param [Integer] port
216
+ # The local port to listen on.
217
+ #
218
+ # @param [String] host ('0.0.0.0')
219
+ # The host to bind to.
220
+ #
221
+ # @return [TCPServer]
222
+ # The new TCP server.
223
+ #
224
+ # @example
225
+ # Net.tcp_server(1337)
226
+ #
227
+ def Net.tcp_server(port,host='0.0.0.0')
228
+ host = host.to_s
229
+
230
+ server = TCPServer.new(host,port)
231
+ server.listen(3)
232
+
233
+ yield server if block_given?
234
+ return server
235
+ end
236
+
237
+ #
238
+ # Creates a new temporary TCPServer listening on a host and port.
239
+ #
240
+ # @param [Integer] port
241
+ # The local port to bind to.
242
+ #
243
+ # @param [String] host ('0.0.0.0')
244
+ # The host to bind to.
245
+ #
246
+ # @yield [server]
247
+ # The block which will be called after the _server_ has been created.
248
+ # After the block has finished, the _server_ will be closed.
249
+ #
250
+ # @yieldparam [TCPServer] server
251
+ # The newly created TCP server.
252
+ #
253
+ # @return [nil]
254
+ #
255
+ # @example
256
+ # Net.tcp_server_session(1337) do |server|
257
+ # client1 = server.accept
258
+ # client2 = server.accept
259
+ #
260
+ # client2.write(server.read_line)
261
+ #
262
+ # client1.close
263
+ # client2.close
264
+ # end
265
+ #
266
+ def Net.tcp_server_session(port,host='0.0.0.0',&block)
267
+ server = Net.tcp_server(port,host,&block)
268
+ server.close()
269
+ return nil
270
+ end
271
+
272
+ #
273
+ # Creates a new TCPServer listening on a given host and port,
274
+ # accepts only one client and then stops listening.
275
+ #
276
+ # @param [Integer] port
277
+ # After the block has finished, the client and the server will be
278
+ # closed.
279
+ #
280
+ # @yieldparam [TCPSocket] client
281
+ # The newly connected client.
282
+ #
283
+ # @return [nil]
284
+ #
285
+ # @example
286
+ # Net.tcp_single_server(1337) do |client|
287
+ # client.puts 'lol'
288
+ # end
289
+ #
290
+ def Net.tcp_single_server(port,host='0.0.0.0')
291
+ host = host.to_s
292
+
293
+ server = TCPServer.new(host,port)
294
+ server.listen(1)
295
+
296
+ client = server.accept
297
+
298
+ yield client if block_given?
299
+
300
+ client.close
301
+ server.close
302
+ return nil
303
+ end
304
+ end
@@ -0,0 +1,22 @@
1
+ #
2
+ # Ronin - A Ruby platform for exploit development and security research.
3
+ #
4
+ # Copyright (c) 2006-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2.1 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
+ # Boston, MA 02110-1301 USA
20
+ #
21
+
22
+ require 'ronin/network/extensions/telnet/net'
@@ -0,0 +1,156 @@
1
+ #
2
+ # Ronin - A Ruby platform for exploit development and security research.
3
+ #
4
+ # Copyright (c) 2006-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2.1 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
+ # Boston, MA 02110-1301 USA
20
+ #
21
+
22
+ require 'ronin/network/telnet'
23
+
24
+ require 'net/telnet'
25
+
26
+ module Net
27
+ #
28
+ # Creates a new Telnet connection.
29
+ #
30
+ # @param [String] host
31
+ # The host to connect to.
32
+ #
33
+ # @param [Hash] options
34
+ # Additional options.
35
+ #
36
+ # @option options [Integer] :port (Ronin::Network::Telnet.default_port)
37
+ # The port to connect to.
38
+ #
39
+ # @option options [Boolean] :binmode
40
+ # Indicates that newline substitution shall not be performed.
41
+ #
42
+ # @option options [String] :output_log
43
+ # The name of the file to write connection status messages and all
44
+ # received traffic to.
45
+ #
46
+ # @option options [String] :dump_log
47
+ # Similar to the `:output_log` option, but connection output is also
48
+ # written in hexdump format.
49
+ #
50
+ # @option options [Regexp] :prompt (Ronin::Network::Telnet.default_prompt)
51
+ # A regular expression matching the host command-line prompt sequence,
52
+ # used to determine when a command has finished.
53
+ #
54
+ # @option options [Boolean] :telnet (true)
55
+ # Indicates that the connection shall behave as a telnet connection.
56
+ #
57
+ # @option options [Boolean] :plain
58
+ # Indicates that the connection shall behave as a normal TCP
59
+ # connection.
60
+ #
61
+ # @option options [Integer] :timeout (Ronin::Network::Telnet.default_timeout)
62
+ # The number of seconds to wait before timing out both the initial
63
+ # attempt to connect to host, and all attempts to read data from the
64
+ # host.
65
+ #
66
+ # @option options [Integer] :wait_time
67
+ # The amount of time to wait after seeing what looks like a prompt.
68
+ #
69
+ # @option options [Net::Telnet, IO] :proxy (Ronin::Network::Telnet.proxy)
70
+ # A proxy object to used instead of opening a direct connection to the
71
+ # host.
72
+ #
73
+ # @option options [String] :user
74
+ # The user to login as.
75
+ #
76
+ # @option options [String] :password
77
+ # The password to login with.
78
+ #
79
+ # @yield [session]
80
+ # If a block is given, it will be passed the newly created Telnet
81
+ # session.
82
+ #
83
+ # @yieldparam [Net::Telnet] session
84
+ # The newly created Telnet session.
85
+ #
86
+ # @return [Net::Telnet]
87
+ # The Telnet session
88
+ #
89
+ # @example
90
+ # Net.telnet_connect('towel.blinkenlights.nl')
91
+ # # => #<Net::Telnet: ...>
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
+ def Net.telnet_session(host,options={})
149
+ session = Net.telnet_connect(host,options)
150
+
151
+ yield session if block_given?
152
+
153
+ session.close
154
+ return nil
155
+ end
156
+ end