ronin-support 0.2.0 → 0.3.0

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.
Files changed (62) hide show
  1. data/.gitignore +11 -0
  2. data/ChangeLog.md +42 -1
  3. data/README.md +4 -1
  4. data/gemspec.yml +2 -1
  5. data/lib/ronin/extensions.rb +2 -0
  6. data/lib/ronin/extensions/enumerable.rb +54 -0
  7. data/lib/ronin/extensions/file.rb +70 -2
  8. data/lib/ronin/extensions/ip_addr.rb +45 -45
  9. data/lib/ronin/extensions/regexp.rb +45 -0
  10. data/lib/ronin/extensions/resolv.rb +80 -0
  11. data/lib/ronin/extensions/string.rb +35 -32
  12. data/lib/ronin/formatting/extensions/binary/integer.rb +12 -5
  13. data/lib/ronin/formatting/extensions/binary/string.rb +44 -16
  14. data/lib/ronin/formatting/extensions/html/integer.rb +51 -31
  15. data/lib/ronin/formatting/extensions/html/string.rb +50 -31
  16. data/lib/ronin/formatting/extensions/http/integer.rb +10 -2
  17. data/lib/ronin/formatting/extensions/sql.rb +20 -0
  18. data/lib/ronin/formatting/extensions/sql/string.rb +98 -0
  19. data/lib/ronin/formatting/extensions/text/array.rb +11 -9
  20. data/lib/ronin/formatting/extensions/text/string.rb +213 -29
  21. data/lib/ronin/formatting/sql.rb +20 -0
  22. data/lib/ronin/network/extensions/http.rb +1 -0
  23. data/lib/ronin/network/extensions/http/net.rb +2 -2
  24. data/lib/ronin/network/extensions/http/uri/http.rb +226 -0
  25. data/lib/ronin/network/extensions/imap/net.rb +1 -1
  26. data/lib/ronin/network/extensions/ssl/net.rb +7 -1
  27. data/lib/ronin/network/http/proxy.rb +20 -21
  28. data/lib/ronin/network/mixins.rb +27 -0
  29. data/lib/ronin/network/mixins/esmtp.rb +165 -0
  30. data/lib/ronin/network/mixins/http.rb +723 -0
  31. data/lib/ronin/network/mixins/imap.rb +151 -0
  32. data/lib/ronin/network/mixins/pop3.rb +141 -0
  33. data/lib/ronin/network/mixins/smtp.rb +159 -0
  34. data/lib/ronin/network/mixins/tcp.rb +331 -0
  35. data/lib/ronin/network/mixins/telnet.rb +199 -0
  36. data/lib/ronin/network/mixins/udp.rb +227 -0
  37. data/lib/ronin/network/ssl.rb +17 -11
  38. data/lib/ronin/path.rb +3 -3
  39. data/lib/ronin/spec/ui/output.rb +28 -0
  40. data/lib/ronin/support.rb +3 -0
  41. data/lib/ronin/support/version.rb +1 -1
  42. data/lib/ronin/ui/output.rb +21 -0
  43. data/lib/ronin/ui/output/helpers.rb +248 -0
  44. data/lib/ronin/ui/output/output.rb +146 -0
  45. data/lib/ronin/ui/output/terminal.rb +21 -0
  46. data/lib/ronin/ui/output/terminal/color.rb +118 -0
  47. data/lib/ronin/ui/output/terminal/raw.rb +103 -0
  48. data/lib/ronin/ui/shell.rb +219 -0
  49. data/ronin-support.gemspec +1 -1
  50. data/spec/extensions/enumerable_spec.rb +24 -0
  51. data/spec/extensions/file_spec.rb +39 -0
  52. data/spec/extensions/ip_addr_spec.rb +6 -0
  53. data/spec/extensions/resolv_spec.rb +18 -0
  54. data/spec/formatting/html/integer_spec.rb +2 -2
  55. data/spec/formatting/html/string_spec.rb +1 -1
  56. data/spec/formatting/sql/string_spec.rb +55 -0
  57. data/spec/formatting/text/string_spec.rb +110 -0
  58. data/spec/network/ssl_spec.rb +10 -4
  59. data/spec/ui/classes/test_shell.rb +22 -0
  60. data/spec/ui/output_spec.rb +32 -0
  61. data/spec/ui/shell_spec.rb +79 -0
  62. metadata +132 -90
@@ -0,0 +1,20 @@
1
+ #
2
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
3
+ #
4
+ # This file is part of Ronin Support.
5
+ #
6
+ # Ronin Support is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Lesser General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Ronin Support 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
14
+ # GNU Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public License
17
+ # along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+
20
+ require 'ronin/formatting/extensions/sql'
@@ -18,3 +18,4 @@
18
18
  #
19
19
 
20
20
  require 'ronin/network/extensions/http/net'
21
+ require 'ronin/network/extensions/http/uri/http'
@@ -90,7 +90,7 @@ module Net
90
90
 
91
91
  if options[:ssl]
92
92
  sess.use_ssl = true
93
- sess.verify_mode = Ronin::Network::SSL.verify(options[:ssl][:verify])
93
+ sess.verify_mode = Ronin::Network::SSL::VERIFY[options[:ssl][:verify]]
94
94
  end
95
95
 
96
96
  sess.start()
@@ -253,7 +253,7 @@ module Net
253
253
  # The method to use for the request.
254
254
  #
255
255
  # @return [Boolean]
256
- # Specifies wether the response had an HTTP OK status code or not.
256
+ # Specifies whether the response had an HTTP OK status code or not.
257
257
  #
258
258
  # @see http_status
259
259
  #
@@ -0,0 +1,226 @@
1
+ #
2
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
3
+ #
4
+ # This file is part of Ronin Support.
5
+ #
6
+ # Ronin Support is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Lesser General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Ronin Support 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
14
+ # GNU Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public License
17
+ # along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+
20
+ require 'ronin/network/extensions/http/net'
21
+
22
+ require 'uri/http'
23
+
24
+ module URI
25
+ class HTTP < Generic
26
+
27
+ #
28
+ # @see Net.http_request
29
+ #
30
+ # @since 0.3.0
31
+ #
32
+ def request(options={},&block)
33
+ Net.http_request(options.merge(:url => self),&block)
34
+ end
35
+
36
+ #
37
+ # @see Net.http_status
38
+ #
39
+ # @since 0.3.0
40
+ #
41
+ def status(options={})
42
+ Net.http_status(options.merge(:url => self))
43
+ end
44
+
45
+ #
46
+ # @see Net.http_ok?
47
+ #
48
+ # @since 0.3.0
49
+ #
50
+ def ok?(options={})
51
+ Net.http_ok?(options.merge(:url => self))
52
+ end
53
+
54
+ #
55
+ # @see Net.http_server
56
+ #
57
+ # @since 0.3.0
58
+ #
59
+ def server(options={})
60
+ Net.http_server(options.merge(:url => self))
61
+ end
62
+
63
+ #
64
+ # @see Net.http_powered_by
65
+ #
66
+ # @since 0.3.0
67
+ #
68
+ def powered_by(options={})
69
+ Net.http_powered_by(options.merge(:url => self))
70
+ end
71
+
72
+ #
73
+ # @see Net.http_copy
74
+ #
75
+ # @since 0.3.0
76
+ #
77
+ def copy(options={},&block)
78
+ Net.http_copy(options.merge(:url => self),&block)
79
+ end
80
+
81
+ #
82
+ # @see Net.http_delete
83
+ #
84
+ # @since 0.3.0
85
+ #
86
+ def delete(options={},&block)
87
+ Net.http_delete(options.merge(:url => self),&block)
88
+ end
89
+
90
+ #
91
+ # @see Net.http_get
92
+ #
93
+ # @since 0.3.0
94
+ #
95
+ def get(options={},&block)
96
+ Net.http_get(options.merge(:url => self),&block)
97
+ end
98
+
99
+ #
100
+ # @see Net.http_get_headers
101
+ #
102
+ # @since 0.3.0
103
+ #
104
+ def get_headers(options={},&block)
105
+ Net.http_get_headers(options.merge(:url => self),&block)
106
+ end
107
+
108
+ #
109
+ # @see Net.http_get_body
110
+ #
111
+ # @since 0.3.0
112
+ #
113
+ def get_body(options={},&block)
114
+ Net.http_get_body(options.merge(:url => self),&block)
115
+ end
116
+
117
+ #
118
+ # @see Net.http_head
119
+ #
120
+ # @since 0.3.0
121
+ #
122
+ def head(options={},&block)
123
+ Net.http_head(options.merge(:url => self),&block)
124
+ end
125
+
126
+ #
127
+ # @see Net.http_lock
128
+ #
129
+ # @since 0.3.0
130
+ #
131
+ def lock(options={},&block)
132
+ Net.http_lock(options.merge(:url => self),&block)
133
+ end
134
+
135
+ #
136
+ # @see Net.http_mkcol
137
+ #
138
+ # @since 0.3.0
139
+ #
140
+ def mkcol(options={},&block)
141
+ Net.http_mkcol(options.merge(:url => self),&block)
142
+ end
143
+
144
+ #
145
+ # @see Net.http_move
146
+ #
147
+ # @since 0.3.0
148
+ #
149
+ def move(options={},&block)
150
+ Net.http_move(options.merge(:url => self),&block)
151
+ end
152
+
153
+ #
154
+ # @see Net.http_options
155
+ #
156
+ # @since 0.3.0
157
+ #
158
+ def options(options={},&block)
159
+ Net.http_options(options.merge(:url => self),&block)
160
+ end
161
+
162
+ #
163
+ # @see Net.http_post
164
+ #
165
+ # @since 0.3.0
166
+ #
167
+ def post(options={},&block)
168
+ Net.http_post(options.merge(:url => self),&block)
169
+ end
170
+
171
+ #
172
+ # @see Net.http_post_headers
173
+ #
174
+ # @since 0.3.0
175
+ #
176
+ def post_headers(options={},&block)
177
+ Net.http_post_headers(options.merge(:url => self),&block)
178
+ end
179
+
180
+ #
181
+ # @see Net.http_post_body
182
+ #
183
+ # @since 0.3.0
184
+ #
185
+ def post_body(options={},&block)
186
+ Net.http_post_body(options.merge(:url => self),&block)
187
+ end
188
+
189
+ #
190
+ # @see Net.http_prop_find
191
+ #
192
+ # @since 0.3.0
193
+ #
194
+ def prop_find(options={},&block)
195
+ Net.http_prop_find(options.merge(:url => self),&block)
196
+ end
197
+
198
+ #
199
+ # @see Net.http_prop_match
200
+ #
201
+ # @since 0.3.0
202
+ #
203
+ def prop_match(options={},&block)
204
+ Net.http_prop_match(options.merge(:url => self),&block)
205
+ end
206
+
207
+ #
208
+ # @see Net.http_trace
209
+ #
210
+ # @since 0.3.0
211
+ #
212
+ def trace(options={},&block)
213
+ Net.http_trace(options.merge(:url => self),&block)
214
+ end
215
+
216
+ #
217
+ # @see Net.http_unlock
218
+ #
219
+ # @since 0.3.0
220
+ #
221
+ def unlock(options={},&block)
222
+ Net.http_unlock(options.merge(:url => self),&block)
223
+ end
224
+
225
+ end
226
+ end
@@ -71,7 +71,7 @@ module Net
71
71
  if options[:ssl]
72
72
  ssl = true
73
73
  ssl_certs = options[:ssl][:certs]
74
- ssl_verify = Ronin::Network::SSL.verify(options[:ssl][:verify])
74
+ ssl_verify = Ronin::Network::SSL::VERIFY[options[:ssl][:verify]]
75
75
  else
76
76
  ssl = false
77
77
  ssl_verify = false
@@ -46,6 +46,12 @@ module Net
46
46
  #
47
47
  # @option options [Symbol] :verify
48
48
  # Specifies whether to verify the SSL certificate.
49
+ # May be one of the following:
50
+ #
51
+ # * `:none`
52
+ # * `:peer`
53
+ # * `:client_once`
54
+ # * `:fail_if_no_peer_cert`
49
55
  #
50
56
  # @option options [String] :cert
51
57
  # The path to the SSL certificate.
@@ -74,7 +80,7 @@ module Net
74
80
  socket = Net.tcp_connect(host,port,local_host,local_port)
75
81
 
76
82
  ssl_context = OpenSSL::SSL::SSLContext.new()
77
- ssl_context.verify_mode = Ronin::Network::SSL.verify(options[:verify])
83
+ ssl_context.verify_mode = Ronin::Network::SSL::VERIFY[options[:verify]]
78
84
 
79
85
  if options[:cert]
80
86
  cert_file = File.new(options[:cert])
@@ -93,7 +93,7 @@ module Ronin
93
93
  host, port = proxy.split(':',2)
94
94
  port = port.to_i if port
95
95
 
96
- return self.new(
96
+ return new(
97
97
  :host => host,
98
98
  :port => port,
99
99
  :user => user,
@@ -121,18 +121,18 @@ module Ronin
121
121
  when Proxy
122
122
  proxy
123
123
  when URI::HTTP
124
- self.new(
124
+ new(
125
125
  :host => proxy.host,
126
126
  :port => proxy.port,
127
127
  :user => proxy.user,
128
128
  :password => proxy.password
129
129
  )
130
130
  when Hash
131
- self.new(proxy)
131
+ new(proxy)
132
132
  when String
133
- self.parse(proxy)
133
+ parse(proxy)
134
134
  when nil
135
- self.new
135
+ new
136
136
  else
137
137
  raise(ArgumentError,"argument must be either a #{self}, URI::HTTP, Hash or String")
138
138
  end
@@ -250,7 +250,7 @@ module Ronin
250
250
  # @api public
251
251
  #
252
252
  def enabled?
253
- !(self.host.nil?)
253
+ !(host.nil?)
254
254
  end
255
255
 
256
256
  #
@@ -265,18 +265,18 @@ module Ronin
265
265
  def url
266
266
  return nil unless enabled?
267
267
 
268
- userinfo = if self.user
269
- if self.password
270
- "#{self.user}:#{self.password}"
268
+ userinfo = if user
269
+ if password
270
+ "#{user}:#{password}"
271
271
  else
272
- self.user
272
+ user
273
273
  end
274
274
  end
275
275
 
276
276
  return URI::HTTP.build(
277
277
  :userinfo => userinfo,
278
- :host => self.host,
279
- :port => self.port
278
+ :host => host,
279
+ :port => port
280
280
  )
281
281
  end
282
282
 
@@ -289,7 +289,7 @@ module Ronin
289
289
  # @api public
290
290
  #
291
291
  def to_s
292
- self.host.to_s
292
+ host.to_s
293
293
  end
294
294
 
295
295
  #
@@ -301,21 +301,20 @@ module Ronin
301
301
  # @api public
302
302
  #
303
303
  def inspect
304
- unless self.host
304
+ unless host
305
305
  str = 'disabled'
306
306
  else
307
307
  str = ''
308
308
 
309
- str << self.host.to_s
310
- str << ":#{self.port}" if self.port
309
+ str << host.to_s
310
+ str << ":#{port}" if port
311
311
 
312
- if self.user
312
+ if user
313
313
  auth_str = ''
314
+ auth_str << user.to_s
314
315
 
315
- auth_str << self.user.to_s
316
-
317
- if self.password
318
- auth_str << ":#{self.password}"
316
+ if password
317
+ auth_str << ":#{password}"
319
318
  end
320
319
 
321
320
  str = "#{auth_str}@#{str}"
@@ -0,0 +1,27 @@
1
+ #
2
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
3
+ #
4
+ # This file is part of Ronin Support.
5
+ #
6
+ # Ronin Support is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Lesser General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Ronin Support 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
14
+ # GNU Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public License
17
+ # along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+
20
+ require 'ronin/network/mixins/tcp'
21
+ require 'ronin/network/mixins/udp'
22
+ require 'ronin/network/mixins/smtp'
23
+ require 'ronin/network/mixins/esmtp'
24
+ require 'ronin/network/mixins/pop3'
25
+ require 'ronin/network/mixins/imap'
26
+ require 'ronin/network/mixins/telnet'
27
+ require 'ronin/network/mixins/web'
@@ -0,0 +1,165 @@
1
+ #
2
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
3
+ #
4
+ # This file is part of Ronin Support.
5
+ #
6
+ # Ronin Support is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Lesser General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Ronin Support 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
14
+ # GNU Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public License
17
+ # along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+
20
+ require 'ronin/network/esmtp'
21
+ require 'ronin/ui/output/helpers'
22
+ require 'ronin/mixin'
23
+
24
+ require 'parameters'
25
+
26
+ module Ronin
27
+ module Network
28
+ module Mixins
29
+ #
30
+ # Adds ESMTP convenience methods and connection parameters to a class.
31
+ #
32
+ # Defines the following parameters:
33
+ #
34
+ # * `host` (`String`) - ESMTP host.
35
+ # * `port` (`Integer`) - ESMTP port.
36
+ # * `esmtp_login` (`String`) - ESMTP authentication method to use.
37
+ # * `esmtp_user` (`String`) - ESMTP user to login as.
38
+ # * `esmtp_password` (`String`) - ESMTP password to login with.
39
+ #
40
+ module ESMTP
41
+ include Mixin
42
+
43
+ mixin UI::Output::Helpers, Parameters
44
+
45
+ mixin do
46
+ # ESMTP host
47
+ parameter :host, :type => String,
48
+ :description => 'ESMTP host'
49
+
50
+ # ESMTP port
51
+ parameter :port, :type => Integer,
52
+ :description => 'ESMTP port'
53
+
54
+ # ESMTP authentication method to use
55
+ parameter :esmtp_login, :type => String,
56
+ :description => 'ESMTP authentication method to use'
57
+
58
+ # ESMTP user to login as
59
+ parameter :esmtp_user, :type => String,
60
+ :description => 'ESMTP user to login as'
61
+
62
+ # ESMTP password to login with
63
+ parameter :esmtp_password, :type => String,
64
+ :description => 'ESMTP password to login with'
65
+ end
66
+
67
+ protected
68
+
69
+ #
70
+ # @see Ronin::Network::SMTP.message.
71
+ #
72
+ # @api public
73
+ #
74
+ def esmtp_message(options={},&block)
75
+ Network::SMTP.message(options,&block)
76
+ end
77
+
78
+ #
79
+ # Creates a connection to the ESMTP server. The `host`, `port`,
80
+ # `esmtp_login`, `esmtp_user` and `esmtp_password` parameters
81
+ # will also be used to connect to the ESMTP server.
82
+ #
83
+ # @param [Hash] options
84
+ # Additional options.
85
+ #
86
+ # @option options [Integer] :port (Ronin::Network::SMTP.default_port)
87
+ # The port to connect to.
88
+ #
89
+ # @option options [String] :helo
90
+ # The HELO domain.
91
+ #
92
+ # @option options [Symbol] :auth
93
+ # The type of authentication to use.
94
+ # Can be either `:login`, `:plain`, or `:cram_md5`.
95
+ #
96
+ # @option options [String] :user
97
+ # The user-name to authenticate with.
98
+ #
99
+ # @option options [String] :password
100
+ # The password to authenticate with.
101
+ #
102
+ # @yield [session]
103
+ # If a block is given, it will be passed an ESMTP enabled
104
+ # session object.
105
+ #
106
+ # @yieldparam [Net::SMTP] session
107
+ # The ESMTP session.
108
+ #
109
+ # @return [Net::SMTP]
110
+ # The ESMTP enabled session.
111
+ #
112
+ # @api public
113
+ #
114
+ def esmtp_connect(options={},&block)
115
+ options[:port] ||= self.port
116
+ options[:login] ||= self.esmtp_login
117
+ options[:user] ||= self.esmtp_user
118
+ options[:password] ||= self.esmtp_password
119
+
120
+ if self.port
121
+ print_info "Connecting to #{self.host}:#{self.port} ..."
122
+ else
123
+ print_info "Connecting to #{self.host} ..."
124
+ end
125
+
126
+ return ::Net.esmtp_connect(self.host,options,&block)
127
+ end
128
+
129
+ #
130
+ # Starts a session with the ESMTP server. The `host`, `port`,
131
+ # `esmtp_login`, `esmtp_user` and `esmtp_password` parameters
132
+ # will also be used to connect to the ESMTP server.
133
+ #
134
+ # @param [Hash] options
135
+ # Additional options.
136
+ #
137
+ # @yield [session]
138
+ # If a block is given, it will be passed an ESMTP enabled
139
+ # session object. After the block has returned, the session
140
+ # will be closed.
141
+ #
142
+ # @yieldparam [Net::SMTP] session
143
+ # The ESMTP session.
144
+ #
145
+ # @see esmtp_connect
146
+ #
147
+ # @api public
148
+ #
149
+ def esmtp_session(options={})
150
+ esmtp_connect(options) do |sess|
151
+ yield sess if block_given?
152
+
153
+ sess.close
154
+
155
+ if self.port
156
+ print_info "Disconnecting from #{self.host}:#{self.port}"
157
+ else
158
+ print_info "Disconnecting from #{self.host}"
159
+ end
160
+ end
161
+ end
162
+ end
163
+ end
164
+ end
165
+ end