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
@@ -0,0 +1,65 @@
1
+ #
2
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
3
+ #
4
+ # This file is part of Ronin.
5
+ #
6
+ # Ronin is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Ronin 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 General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+
20
+ require 'ronin/ui/cli/command'
21
+ require 'ronin/repository'
22
+ require 'ronin/database'
23
+
24
+ module Ronin
25
+ module UI
26
+ module CLI
27
+ module Commands
28
+ #
29
+ # The `ronin-uninstall` command.
30
+ #
31
+ class Uninstall < Command
32
+
33
+ summary 'Uninstalls Ronin Repositories'
34
+
35
+ argument :repo, :type => String,
36
+ :description => 'Repository to uninstall'
37
+
38
+ #
39
+ # Sets up the install command.
40
+ #
41
+ def setup
42
+ super
43
+
44
+ Database.setup
45
+ end
46
+
47
+ #
48
+ # Executes the command.
49
+ #
50
+ def execute
51
+ unless repo?
52
+ print_error "Must specify the REPO argument"
53
+ exit -1
54
+ end
55
+
56
+ repository = Repository.uninstall(@repo)
57
+
58
+ print_info "Repository #{repository} uninstalled."
59
+ end
60
+
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,100 @@
1
+ #
2
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
3
+ #
4
+ # This file is part of Ronin.
5
+ #
6
+ # Ronin is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Ronin 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 General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+
20
+ require 'ronin/ui/cli/command'
21
+ require 'ronin/repository'
22
+ require 'ronin/database'
23
+
24
+ module Ronin
25
+ module UI
26
+ module CLI
27
+ module Commands
28
+ #
29
+ # The `ronin-update` command.
30
+ #
31
+ class Update < Command
32
+
33
+ summary 'Updates Ronin Repositories'
34
+
35
+ argument :repo, :type => String,
36
+ :description => 'Repository to update'
37
+
38
+ #
39
+ # Sets up the install command.
40
+ #
41
+ def setup
42
+ super
43
+
44
+ Database.setup
45
+ end
46
+
47
+ #
48
+ # Executes the command.
49
+ #
50
+ def execute
51
+ if repo?
52
+ repository = begin
53
+ Repository.find(@repo)
54
+ rescue RepositoryNotFound => e
55
+ print_error e.message
56
+ exit -1
57
+ end
58
+
59
+ print_info "Updating #{repository} ..."
60
+
61
+ repository.update!
62
+
63
+ print_info "Repository #{repository} updated."
64
+ else
65
+ print_info "Updating Repositories ..."
66
+
67
+ Repository.update!
68
+
69
+ print_info "Repositories updated."
70
+ end
71
+ end
72
+
73
+ protected
74
+
75
+ #
76
+ # Print out any exceptions or validation errors encountered
77
+ # when caching the files of the repository.
78
+ #
79
+ # @param [Repository] repository
80
+ # The repository that was updated.
81
+ #
82
+ def print_cache_errors(repo)
83
+ repository.script_paths.each do |script_path|
84
+ if script_path.cache_exception
85
+ print_exception script_path.cache_exception
86
+ end
87
+
88
+ if script_path.cache_errors
89
+ script_path.cache_errors.each do |error|
90
+ print_error error
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -31,36 +31,36 @@ module Ronin
31
31
 
32
32
  model URL
33
33
 
34
- query_option :http, :type => :boolean
35
- query_option :https, :type => :boolean
34
+ query_option :http, :type => true
35
+ query_option :https, :type => true
36
36
 
37
- query_option :hosts, :type => :array,
38
- :aliases => '-H',
39
- :banner => 'HOST [...]'
37
+ query_option :hosts, :type => Array,
38
+ :flag => '-H',
39
+ :usage => 'HOST [...]'
40
40
 
41
- query_option :ports, :type => :array,
42
- :aliases => '-P',
43
- :banner => 'PORT [...]'
41
+ query_option :ports, :type => Array[Integer],
42
+ :flag => '-P',
43
+ :usage => 'PORT [...]'
44
44
 
45
- query_option :directory, :type => :string,
46
- :aliases => '-d',
47
- :banner => 'SUBDIR'
45
+ query_option :directory, :type => String,
46
+ :flag => '-d',
47
+ :usage => 'SUBDIR'
48
48
 
49
- query_option :query_param, :type => :array,
50
- :aliases => '-q',
51
- :banner => 'NAME'
49
+ query_option :with_query_param, :type => Array,
50
+ :flag => '-q',
51
+ :usage => 'NAME [...]'
52
52
 
53
- query_option :query_value, :type => :array,
54
- :aliases => '-Q',
55
- :banner => 'VALUE'
53
+ query_option :with_query_value, :type => Array,
54
+ :flag => '-Q',
55
+ :usage => 'VALUE [...]'
56
56
 
57
- class_option :list, :type => :boolean,
58
- :default => true,
59
- :aliases => '-l'
57
+ option :list, :type => true,
58
+ :default => true,
59
+ :flag => '-l'
60
60
 
61
- class_option :import, :type => :string,
62
- :aliases => '-i',
63
- :banner => 'FILE'
61
+ option :import, :type => String,
62
+ :flag => '-i',
63
+ :usage => 'FILE'
64
64
 
65
65
  protected
66
66
 
@@ -73,7 +73,7 @@ module Ronin
73
73
  # @since 1.0.0
74
74
  #
75
75
  def print_resource(url)
76
- return super(url) unless options.verbose?
76
+ return super(url) unless verbose?
77
77
 
78
78
  print_title url
79
79
 
@@ -28,8 +28,9 @@ module Ronin
28
28
  #
29
29
  class ModelCommand < Command
30
30
 
31
- class_option :database, :type => :string,
32
- :aliases => '-D'
31
+ option :database, :type => URI,
32
+ :flag => '-D',
33
+ :description => 'The Database URI'
33
34
 
34
35
  #
35
36
  # The query options for the command.
@@ -109,7 +110,8 @@ module Ronin
109
110
  #
110
111
  def self.query_option(name,options={})
111
112
  query_options << name
112
- class_option name, options
113
+
114
+ return option(name,options)
113
115
  end
114
116
 
115
117
  #
@@ -122,8 +124,8 @@ module Ronin
122
124
  def setup
123
125
  super
124
126
 
125
- if self.options[:database]
126
- Database.repositories[:default] = options[:database]
127
+ if @database
128
+ Database.repositories[:default] = @database
127
129
  end
128
130
 
129
131
  Database.setup
@@ -151,7 +153,7 @@ module Ronin
151
153
  query = self.class.model.all
152
154
 
153
155
  self.class.each_query_option do |name|
154
- value = options[name]
156
+ value = get_param(name).value
155
157
 
156
158
  # skip unset options
157
159
  next if value.nil?
@@ -0,0 +1,167 @@
1
+ #
2
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
3
+ #
4
+ # This file is part of Ronin.
5
+ #
6
+ # Ronin is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Ronin 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 General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+
20
+ require 'ronin/ui/output/helpers'
21
+
22
+ module Ronin
23
+ module UI
24
+ module CLI
25
+ #
26
+ # CLI Printing helper methods.
27
+ #
28
+ # @since 1.4.0
29
+ #
30
+ module Printing
31
+ include Output::Helpers
32
+
33
+ #
34
+ # Initializes Printing settings.
35
+ #
36
+ def initialize
37
+ @indent = 0
38
+ end
39
+
40
+ #
41
+ # Increases the indentation out output temporarily.
42
+ #
43
+ # @param [Integer] n
44
+ # The number of spaces to increase the indentation by.
45
+ #
46
+ # @yield []
47
+ # The block will be called after the indentation has been
48
+ # increased. After the block has returned, the indentation will
49
+ # be returned to normal.
50
+ #
51
+ # @return [nil]
52
+ #
53
+ # @api semipublic
54
+ #
55
+ def indent(n=2)
56
+ @indent += n
57
+
58
+ yield
59
+
60
+ @indent -= n
61
+ return nil
62
+ end
63
+
64
+ #
65
+ # Print the given messages with indentation.
66
+ #
67
+ # @param [Array] messages
68
+ # The messages to print, one per-line.
69
+ #
70
+ # @api semipublic
71
+ #
72
+ def puts(*messages)
73
+ super(*(messages.map { |mesg| (' ' * @indent) + mesg.to_s }))
74
+ end
75
+
76
+ #
77
+ # Prints a given title.
78
+ #
79
+ # @param [String] title
80
+ # The title to print.
81
+ #
82
+ # @api semipublic
83
+ #
84
+ def print_title(title)
85
+ puts "[ #{title} ]\n"
86
+ end
87
+
88
+ #
89
+ # Prints a section with a title.
90
+ #
91
+ # @yield []
92
+ # The block will be called after the title has been printed
93
+ # and indentation increased.
94
+ #
95
+ # @since 1.0.0
96
+ #
97
+ # @api semipublic
98
+ #
99
+ def print_section(title,&block)
100
+ print_title(title)
101
+ indent(&block)
102
+ end
103
+
104
+ #
105
+ # Prints a given Array.
106
+ #
107
+ # @param [Array] array
108
+ # The Array to print.
109
+ #
110
+ # @param [Hash] options
111
+ # Additional options.
112
+ #
113
+ # @option options [String] :title
114
+ # The optional title to print before the contents of the Array.
115
+ #
116
+ # @return [nil]
117
+ #
118
+ # @api semipublic
119
+ #
120
+ def print_array(array,options={})
121
+ print_title(options[:title]) if options[:title]
122
+
123
+ indent do
124
+ array.each { |value| puts value }
125
+ end
126
+
127
+ puts if options[:title]
128
+ return nil
129
+ end
130
+
131
+ #
132
+ # Prints a given Hash.
133
+ #
134
+ # @param [Hash] hash
135
+ # The Hash to print.
136
+ #
137
+ # @param [Hash] options
138
+ # Additional options.
139
+ #
140
+ # @option options [String] :title
141
+ # The optional title to print before the contents of the Hash.
142
+ #
143
+ # @return [nil]
144
+ #
145
+ # @api semipublic
146
+ #
147
+ def print_hash(hash,options={})
148
+ align = hash.keys.map { |name|
149
+ name.to_s.length
150
+ }.max
151
+
152
+ print_title(options[:title]) if options[:title]
153
+
154
+ indent do
155
+ hash.each do |name,value|
156
+ name = "#{name}:".ljust(align)
157
+ puts "#{name}\t#{value}"
158
+ end
159
+ end
160
+
161
+ puts if options[:title]
162
+ return nil
163
+ end
164
+ end
165
+ end
166
+ end
167
+ end
@@ -28,10 +28,17 @@ module Ronin
28
28
  #
29
29
  class ResourcesCommand < ModelCommand
30
30
 
31
- class_option :csv, :type => :boolean
32
- class_option :xml, :type => :boolean
33
- class_option :yaml, :type => :boolean
34
- class_option :json, :type => :boolean
31
+ option :csv, :type => true,
32
+ :description => 'CSV output'
33
+
34
+ option :xml, :type => true,
35
+ :description => 'XML output'
36
+
37
+ option :yaml, :type => true,
38
+ :description => 'YAML output'
39
+
40
+ option :json, :type => true,
41
+ :description => 'JSON output'
35
42
 
36
43
  #
37
44
  # Default method performs the query and prints the found resources.
@@ -41,8 +48,8 @@ module Ronin
41
48
  # @api semipublic
42
49
  #
43
50
  def execute
44
- if options[:import]
45
- self.class.model.import(options[:import]) do |resource|
51
+ if @import
52
+ self.class.model.import(@import) do |resource|
46
53
  print_info "Imported #{resource}"
47
54
  end
48
55
  else
@@ -61,9 +68,10 @@ module Ronin
61
68
  #
62
69
  def self.model(model=nil)
63
70
  if (model && model < Model::Importable)
64
- class_option :import, :type => :string,
65
- :aliases => '-i',
66
- :banner => 'FILE'
71
+ option :import, :type => String,
72
+ :flag => '-i',
73
+ :usage => 'FILE',
74
+ :description => 'The file to import'
67
75
  end
68
76
 
69
77
  return super(model)
@@ -94,13 +102,13 @@ module Ronin
94
102
  # @api semipublic
95
103
  #
96
104
  def print_resources(resources)
97
- if options.csv?
105
+ if @csv
98
106
  print resources.to_csv
99
- elsif options.xml?
107
+ elsif @xml
100
108
  print resources.to_xml
101
- elsif options.yaml?
109
+ elsif @yaml
102
110
  print resources.to_yaml
103
- elsif options.json?
111
+ elsif @json
104
112
  print resources.to_json
105
113
  else
106
114
  resources.each { |resource| print_resource(resource) }