ronin 1.3.0 → 1.4.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/ChangeLog.md +51 -1
  2. data/Gemfile +1 -1
  3. data/README.md +36 -41
  4. data/bin/ronin-install +25 -0
  5. data/bin/ronin-uninstall +25 -0
  6. data/bin/ronin-update +25 -0
  7. data/gemspec.yml +4 -4
  8. data/lib/bond/completions/ronin.rb +6 -5
  9. data/lib/ronin/address.rb +0 -2
  10. data/lib/ronin/auto_load.rb +4 -5
  11. data/lib/ronin/campaign.rb +1 -0
  12. data/lib/ronin/credential.rb +6 -5
  13. data/lib/ronin/database/database.rb +1 -0
  14. data/lib/ronin/email_address.rb +28 -3
  15. data/lib/ronin/environment.rb +3 -6
  16. data/lib/ronin/host_name.rb +1 -3
  17. data/lib/ronin/host_name_ip_address.rb +0 -2
  18. data/lib/ronin/ip_address.rb +1 -4
  19. data/lib/ronin/ip_address_mac_address.rb +0 -2
  20. data/lib/ronin/mac_address.rb +0 -2
  21. data/lib/ronin/model/has_unique_name.rb +17 -0
  22. data/lib/ronin/open_port.rb +0 -4
  23. data/lib/ronin/organization.rb +0 -1
  24. data/lib/ronin/os.rb +0 -2
  25. data/lib/ronin/os_guess.rb +0 -2
  26. data/lib/ronin/password.rb +17 -1
  27. data/lib/ronin/port.rb +34 -1
  28. data/lib/ronin/repository.rb +31 -25
  29. data/lib/ronin/script/buildable.rb +19 -4
  30. data/lib/ronin/script/deployable.rb +7 -8
  31. data/lib/ronin/script/exceptions.rb +1 -0
  32. data/lib/ronin/script/exceptions/build_failed.rb +27 -0
  33. data/lib/ronin/script/path.rb +28 -11
  34. data/lib/ronin/script/script.rb +17 -14
  35. data/lib/ronin/script/testable.rb +3 -3
  36. data/lib/ronin/service.rb +0 -1
  37. data/lib/ronin/service_credential.rb +0 -1
  38. data/lib/ronin/software.rb +0 -1
  39. data/lib/ronin/target.rb +0 -2
  40. data/lib/ronin/tcp_port.rb +0 -1
  41. data/lib/ronin/ui/cli/class_command.rb +130 -0
  42. data/lib/ronin/ui/cli/command.rb +344 -159
  43. data/lib/ronin/ui/cli/commands/campaigns.rb +39 -29
  44. data/lib/ronin/ui/cli/commands/console.rb +24 -15
  45. data/lib/ronin/ui/cli/commands/creds.rb +14 -12
  46. data/lib/ronin/ui/cli/commands/database.rb +63 -46
  47. data/lib/ronin/ui/cli/commands/emails.rb +15 -15
  48. data/lib/ronin/ui/cli/commands/help.rb +6 -5
  49. data/lib/ronin/ui/cli/commands/hosts.rb +24 -24
  50. data/lib/ronin/ui/cli/commands/install.rb +104 -0
  51. data/lib/ronin/ui/cli/commands/ips.rb +23 -23
  52. data/lib/ronin/ui/cli/commands/repos.rb +69 -182
  53. data/lib/ronin/ui/cli/commands/uninstall.rb +65 -0
  54. data/lib/ronin/ui/cli/commands/update.rb +100 -0
  55. data/lib/ronin/ui/cli/commands/urls.rb +24 -24
  56. data/lib/ronin/ui/cli/model_command.rb +8 -6
  57. data/lib/ronin/ui/cli/printing.rb +167 -0
  58. data/lib/ronin/ui/cli/resources_command.rb +21 -13
  59. data/lib/ronin/ui/cli/script_command.rb +126 -24
  60. data/lib/ronin/ui/console/commands.rb +4 -1
  61. data/lib/ronin/ui/console/console.rb +1 -1
  62. data/lib/ronin/ui/console/context.rb +1 -1
  63. data/lib/ronin/url.rb +24 -5
  64. data/lib/ronin/url_query_param.rb +0 -1
  65. data/lib/ronin/version.rb +1 -1
  66. data/lib/ronin/web_credential.rb +0 -5
  67. data/spec/email_address_spec.rb +17 -0
  68. data/spec/installation_spec.rb +24 -34
  69. data/spec/model/has_authors_spec.rb +1 -1
  70. data/spec/model/has_description_spec.rb +1 -1
  71. data/spec/model/has_license_spec.rb +1 -1
  72. data/spec/model/has_name_spec.rb +1 -1
  73. data/spec/model/has_title_spec.rb +1 -1
  74. data/spec/model/has_version_spec.rb +1 -1
  75. data/spec/model/model_spec.rb +1 -1
  76. data/spec/repository_spec.rb +9 -9
  77. data/spec/script/script_spec.rb +2 -4
  78. data/spec/spec_helper.rb +16 -0
  79. data/spec/ui/cli/classes/test_command.rb +7 -3
  80. data/spec/ui/cli/command_spec.rb +37 -5
  81. metadata +82 -73
  82. data/spec/model/spec_helper.rb +0 -20
@@ -21,6 +21,8 @@ require 'ronin/ui/cli/model_command'
21
21
  require 'ronin/ui/console'
22
22
  require 'ronin/script'
23
23
 
24
+ require 'parameters/options'
25
+
24
26
  module Ronin
25
27
  module UI
26
28
  module CLI
@@ -29,17 +31,79 @@ module Ronin
29
31
  #
30
32
  class ScriptCommand < ModelCommand
31
33
 
32
- query_option :named, :type => :string, :aliases => '-n'
33
- query_option :describing, :type => :string, :aliases => '-d'
34
- query_option :revision, :type => :string, :aliases => '-V'
35
- query_option :licensed_under, :type => :string, :aliases => '-L'
34
+ usage '[options] --'
35
+
36
+ query_option :named, :type => String,
37
+ :flag => '-n',
38
+ :usage => 'NAME'
39
+
40
+ query_option :describing, :type => String,
41
+ :flag => '-d',
42
+ :usage => 'DESC'
43
+
44
+ query_option :revision, :type => String,
45
+ :flag => '-V',
46
+ :usage => 'REV'
47
+
48
+ query_option :licensed_under, :type => String,
49
+ :flag => '-L',
50
+ :usage => 'LICENSE'
51
+
52
+ option :file, :type => String,
53
+ :flag => '-f',
54
+ :usage => 'FILE'
55
+
56
+ option :console, :type => true
36
57
 
37
- class_option :file, :type => :string, :aliases => '-f'
38
- class_option :params, :type => :hash,
39
- :default => {},
40
- :banner => 'NAME:VALUE ...',
41
- :aliases => '-p'
42
- class_option :console, :type => :boolean, :default => false
58
+ argument :param_options, :type => Array,
59
+ :default => [],
60
+ :description => 'Additional options'
61
+
62
+ #
63
+ # Initializes the Script command.
64
+ #
65
+ # @param [Hash{Symbol => Object}] options
66
+ # Options for the script command.
67
+ #
68
+ # @api semipublic
69
+ #
70
+ def initialize(options={})
71
+ super(options)
72
+
73
+ @script_options = []
74
+ end
75
+
76
+ #
77
+ # Starts the script command.
78
+ #
79
+ # @param [Array<String>] argv
80
+ # Command-line arguments for the script command.
81
+ #
82
+ # @since 1.4.0
83
+ #
84
+ # @api semipublic
85
+ #
86
+ def start(argv=ARGV)
87
+ # collect the script options, upto the -- separator
88
+ @script_options = argv[0,argv.index('--') || argv.length]
89
+
90
+ super(argv)
91
+ end
92
+
93
+ #
94
+ # Sets up the script command, loads the script and parses additional
95
+ # options for the script.
96
+ #
97
+ # @since 1.4.0
98
+ #
99
+ # @api semipublic
100
+ #
101
+ def setup
102
+ super
103
+
104
+ load!
105
+ param_option_parser.parse(@param_options)
106
+ end
43
107
 
44
108
  #
45
109
  # Loads the script, sets its parameters and runs the script.
@@ -49,15 +113,12 @@ module Ronin
49
113
  # @api semipublic
50
114
  #
51
115
  def execute
52
- script = load_script
53
- script.params = options[:params]
54
-
55
- if options.console?
116
+ if @console
56
117
  print_info "Starting the console with @script set ..."
57
118
 
58
- UI::Console.start(:script => script)
119
+ UI::Console.start(:script => @script)
59
120
  else
60
- script.run
121
+ @script.run
61
122
  end
62
123
  end
63
124
 
@@ -79,12 +140,12 @@ module Ronin
79
140
  #
80
141
  # @api semipublic
81
142
  #
82
- def self.script_class(script)
83
- unless script.included_modules.include?(Script)
143
+ def self.script_class(script=nil)
144
+ if (script && !script.included_modules.include?(Script))
84
145
  raise(ArgumentError,"#{script} does not include Ronin::Script")
85
146
  end
86
147
 
87
- model(script)
148
+ return model(script)
88
149
  end
89
150
 
90
151
  #
@@ -101,11 +162,52 @@ module Ronin
101
162
  #
102
163
  # @api semipublic
103
164
  #
104
- def load_script
105
- if options[:file]
106
- self.class.model.load_from(options[:file])
107
- else
108
- query.load_first
165
+ def load!
166
+ @script = if @file
167
+ self.class.model.load_from(@file)
168
+ else
169
+ query.load_first
170
+ end
171
+
172
+ unless @script
173
+ print_error "Could not find or load the #{self.class.script_class.short_name}"
174
+ exit -1
175
+ end
176
+ end
177
+
178
+ #
179
+ # Creates an OptionParser based on the parameters of one or more
180
+ # objects.
181
+ #
182
+ # @param [Array<Parameters>] objects
183
+ # The objects that have parameters.
184
+ #
185
+ # @yield [opts]
186
+ # If a block is given, it will be passed the newly created
187
+ # OptionParser.
188
+ #
189
+ # @yieldparam [OptionParser] opts
190
+ # The newly created OptionParser for the parameters.
191
+ #
192
+ # @return [OptionParser]
193
+ # The configured OptionParser for the parameters.
194
+ #
195
+ # @since 1.4.0
196
+ #
197
+ # @api semipublic
198
+ #
199
+ def param_option_parser
200
+ OptionParser.new do |opts|
201
+ opts.banner = "usage: #{self.class.command_name} #{@script_options.join(' ')} -- [script_options]"
202
+
203
+ opts.separator ''
204
+ opts.separator "#{self.class.script_class.short_name} Options:"
205
+
206
+ @script.each_param do |param|
207
+ Parameters::Options.define(opts,param)
208
+ end
209
+
210
+ yield opts if block_given?
109
211
  end
110
212
  end
111
213
 
@@ -41,6 +41,9 @@ module Ronin
41
41
  end
42
42
  end
43
43
 
44
+ # Prefixes that denote a command, instead of Ruby code.
45
+ PREFIXES = Set['!', '.']
46
+
44
47
  # Blacklist of known commands that conflict with Ruby keywords.
45
48
  BLACKLIST = Set[
46
49
  '[', 'ap', 'begin', 'case', 'class', 'def', 'fail', 'false',
@@ -56,7 +59,7 @@ module Ronin
56
59
  # The input from the console.
57
60
  #
58
61
  def loop_eval(input)
59
- if input[0,1] == '!'
62
+ if PREFIXES.include?(input[0,1])
60
63
  command = input[1..-1]
61
64
  name, arguments = command.split(' ')
62
65
 
@@ -88,7 +88,7 @@ module Ronin
88
88
  end
89
89
 
90
90
  #
91
- # Enables or disables the printing of one-lin errors.
91
+ # Enables or disables the printing of one-line errors.
92
92
  #
93
93
  # @param [Boolean] mode
94
94
  # The new Console short-errors setting.
@@ -64,7 +64,7 @@ module Ronin
64
64
  #
65
65
  def instance_variables=(variables)
66
66
  variables.each do |name,value|
67
- instance_variable_set("@#{name}".to_sym,value)
67
+ instance_variable_set(:"@#{name}",value)
68
68
  end
69
69
  end
70
70
 
data/lib/ronin/url.rb CHANGED
@@ -23,7 +23,6 @@ require 'ronin/url_scheme'
23
23
  require 'ronin/url_query_param'
24
24
  require 'ronin/host_name'
25
25
  require 'ronin/tcp_port'
26
- require 'ronin/web_credential'
27
26
 
28
27
  require 'dm-timestamps'
29
28
  require 'uri/generic'
@@ -223,11 +222,11 @@ module Ronin
223
222
  # @return [Array<URL>]
224
223
  # The URLs with the given query param.
225
224
  #
226
- # @since 1.0.0
225
+ # @since 1.4.0
227
226
  #
228
227
  # @api public
229
228
  #
230
- def self.query_param(name)
229
+ def self.with_query_param(name)
231
230
  all('query_params.name.name' => name)
232
231
  end
233
232
 
@@ -240,14 +239,34 @@ module Ronin
240
239
  # @return [Array<URL>]
241
240
  # The URLs with the given query param value.
242
241
  #
243
- # @since 1.0.0
242
+ # @since 1.4.0
244
243
  #
245
244
  # @api public
246
245
  #
247
- def self.query_value(value)
246
+ def self.with_query_value(value)
248
247
  all('query_params.value' => value)
249
248
  end
250
249
 
250
+ #
251
+ # @deprecated
252
+ # Deprecated as of 1.4.0 and will be removed in 2.0.0.
253
+ #
254
+ # @see with_query_param
255
+ #
256
+ def self.query_param(name)
257
+ with_query_param(name)
258
+ end
259
+
260
+ #
261
+ # @deprecated
262
+ # Deprecated as of 1.4.0 and will be removed in 2.0.0.
263
+ #
264
+ # @see with_query_value
265
+ #
266
+ def self.query_value(value)
267
+ with_query_value(name)
268
+ end
269
+
251
270
  #
252
271
  # Searches for a URL.
253
272
  #
@@ -17,7 +17,6 @@
17
17
  # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
18
18
  #
19
19
 
20
- require 'ronin/url_query_param_name'
21
20
  require 'ronin/model'
22
21
 
23
22
  require 'uri/query_params'
data/lib/ronin/version.rb CHANGED
@@ -19,5 +19,5 @@
19
19
 
20
20
  module Ronin
21
21
  # Ronin version
22
- VERSION = '1.3.0'
22
+ VERSION = '1.4.0.rc1'
23
23
  end
@@ -18,8 +18,6 @@
18
18
  #
19
19
 
20
20
  require 'ronin/credential'
21
- require 'ronin/email_address'
22
- require 'ronin/url'
23
21
 
24
22
  module Ronin
25
23
  #
@@ -27,9 +25,6 @@ module Ronin
27
25
  #
28
26
  class WebCredential < Credential
29
27
 
30
- # The optional email address the credential is associated with.
31
- belongs_to :email_address, :required => false
32
-
33
28
  # The URL the credential can be used with.
34
29
  belongs_to :url, :required => false,
35
30
  :model => 'URL'
@@ -49,6 +49,23 @@ describe EmailAddress do
49
49
  end
50
50
  end
51
51
 
52
+ describe "from" do
53
+ it "should accept Strings" do
54
+ email_address = described_class.from(email)
55
+
56
+ email_address.user_name.name.should == user
57
+ email_address.host_name.address.should == host
58
+ end
59
+
60
+ it "should accept URI::MailTo objects" do
61
+ uri = URI("mailto:#{email}")
62
+ email_address = described_class.from(uri)
63
+
64
+ email_address.user_name.name.should == user
65
+ email_address.host_name.address.should == host
66
+ end
67
+ end
68
+
52
69
  it "should provide the user-name" do
53
70
  subject.user.should == user
54
71
  end
@@ -10,24 +10,29 @@ describe Installation do
10
10
  subject.libraries.should include('ronin')
11
11
  end
12
12
 
13
+ let(:directory) { 'lib/ronin/ui/cli/commands' }
14
+ let(:files) {
15
+ %w[
16
+ campaigns.rb
17
+ console.rb
18
+ creds.rb
19
+ database.rb
20
+ emails.rb
21
+ exec.rb
22
+ help.rb
23
+ hosts.rb
24
+ install.rb
25
+ ips.rb
26
+ repos.rb
27
+ update.rb
28
+ urls.rb
29
+ uninstall.rb
30
+ ]
31
+ }
32
+
13
33
  describe "each_file" do
14
- let(:directory) { 'lib/ronin/ui/cli/commands' }
15
- let(:pattern) { File.join(directory,'*.rb') }
16
- let(:expected) {
17
- %w[
18
- campaigns.rb
19
- console.rb
20
- creds.rb
21
- database.rb
22
- emails.rb
23
- exec.rb
24
- help.rb
25
- hosts.rb
26
- ips.rb
27
- repos.rb
28
- urls.rb
29
- ].map { |name| File.join(directory,name) }
30
- }
34
+ let(:pattern) { File.join(directory,'*.rb') }
35
+ let(:expected) { files.map { |name| File.join(directory,name) } }
31
36
 
32
37
  it "should enumerate over the files which match a glob pattern" do
33
38
  subject.each_file(pattern).to_a.should =~ expected
@@ -41,23 +46,8 @@ describe Installation do
41
46
  end
42
47
 
43
48
  describe "each_file_in" do
44
- let(:directory) { 'lib/ronin/ui/cli/commands' }
45
- let(:ext) { :rb }
46
- let(:expected) {
47
- %w[
48
- campaigns.rb
49
- console.rb
50
- creds.rb
51
- database.rb
52
- emails.rb
53
- exec.rb
54
- help.rb
55
- hosts.rb
56
- ips.rb
57
- repos.rb
58
- urls.rb
59
- ]
60
- }
49
+ let(:ext) { :rb }
50
+ let(:expected) { files }
61
51
 
62
52
  it "should enumerate over the files which match a glob pattern" do
63
53
  subject.each_file_in(directory,ext).to_a.should =~ expected
@@ -1,4 +1,4 @@
1
- require 'model/spec_helper'
1
+ require 'spec_helper'
2
2
  require 'model/models/authored_model'
3
3
 
4
4
  require 'ronin/model/has_authors'
@@ -1,4 +1,4 @@
1
- require 'model/spec_helper'
1
+ require 'spec_helper'
2
2
  require 'model/models/described_model'
3
3
 
4
4
  require 'ronin/model/has_description'
@@ -1,4 +1,4 @@
1
- require 'model/spec_helper'
1
+ require 'spec_helper'
2
2
  require 'model/models/licensed_model'
3
3
 
4
4
  require 'ronin/model/has_license'
@@ -1,4 +1,4 @@
1
- require 'model/spec_helper'
1
+ require 'spec_helper'
2
2
  require 'model/models/named_model'
3
3
 
4
4
  require 'ronin/model/has_name'