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,104 @@
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-install` command.
30
+ #
31
+ class Install < Command
32
+
33
+ summary 'Installs Ronin Repositories'
34
+
35
+ option :rsync, :type => true
36
+ option :svn, :type => true
37
+ option :hg, :type => true
38
+ option :git, :type => true
39
+
40
+ argument :uri, :type => String,
41
+ :banner => '[URI|PATH]'
42
+
43
+ #
44
+ # Sets up the install command.
45
+ #
46
+ def setup
47
+ super
48
+
49
+ Database.setup
50
+ end
51
+
52
+ #
53
+ # Executes the command.
54
+ #
55
+ def execute
56
+ unless uri?
57
+ print_error "Must specify the URI argument"
58
+ exit -1
59
+ end
60
+
61
+ scm = if rsync?
62
+ :rsync
63
+ elsif svn?
64
+ :sub_version
65
+ elsif hg?
66
+ :mercurial
67
+ elsif git?
68
+ :git
69
+ end
70
+
71
+ repository = begin
72
+ if File.directory?(@uri)
73
+ # add local repositories
74
+ Repository.add(:path => @uri, :scm => scm)
75
+ else
76
+ # install remote repositories
77
+ Repository.install(:uri => @uri, :scm => scm)
78
+ end
79
+ rescue DuplicateRepository => e
80
+ print_error e.message
81
+ exit -1
82
+ end
83
+
84
+ print_info "Repository #{repository} installed."
85
+
86
+ # print any caching exceptions/errors
87
+ repository.script_paths.each do |script_path|
88
+ if script_path.cache_exception
89
+ print_exception script_path.cache_exception
90
+ end
91
+
92
+ if script_path.cache_errors
93
+ script_path.cache_errors.each do |error|
94
+ print_error error
95
+ end
96
+ end
97
+ end
98
+ end
99
+
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
@@ -32,32 +32,32 @@ module Ronin
32
32
 
33
33
  model IPAddress
34
34
 
35
- query_option :v4, :type => :boolean, :aliases => '-4'
36
- query_option :v6, :type => :boolean, :aliases => '-6'
35
+ query_option :v4, :type => true, :flag => '-4'
36
+ query_option :v6, :type => true, :flag => '-6'
37
37
 
38
- query_option :with_ports, :type => :array,
39
- :aliases => '-p',
40
- :banner => 'PORT [...]'
38
+ query_option :with_ports, :type => Array[Integer],
39
+ :flag => '-p',
40
+ :usage => 'PORT [...]'
41
41
 
42
- query_option :with_macs, :type => :array,
43
- :aliases => '-M',
44
- :banner => 'MAC [...]'
42
+ query_option :with_macs, :type => Array,
43
+ :flag => '-M',
44
+ :usage => 'MAC [...]'
45
45
 
46
- query_option :with_hosts, :type => :array,
47
- :aliases => '-H',
48
- :banner => 'HOST [...]'
46
+ query_option :with_hosts, :type => Array,
47
+ :flag => '-H',
48
+ :usage => 'HOST [...]'
49
49
 
50
- class_option :list, :type => :boolean,
51
- :default => true,
52
- :aliases => '-l'
50
+ option :list, :type => true,
51
+ :default => true,
52
+ :aliases => '-l'
53
53
 
54
- class_option :lookup, :type => :string,
55
- :aliases => '-L',
56
- :banner => 'HOST'
54
+ option :lookup, :type => String,
55
+ :flag => '-L',
56
+ :usage => 'HOST'
57
57
 
58
- class_option :import, :type => :string,
59
- :aliases => '-i',
60
- :banner => 'FILE'
58
+ option :import, :type => String,
59
+ :flag => '-i',
60
+ :usage => 'FILE'
61
61
 
62
62
  #
63
63
  # Queries the {IPAddress} model.
@@ -65,8 +65,8 @@ module Ronin
65
65
  # @since 1.0.0
66
66
  #
67
67
  def execute
68
- if options[:lookup]
69
- lookup options[:lookup]
68
+ if lookup?
69
+ lookup(@lookup)
70
70
  else
71
71
  super
72
72
  end
@@ -101,7 +101,7 @@ module Ronin
101
101
  # @since 1.0.0
102
102
  #
103
103
  def print_resource(ip)
104
- return super(ip) unless options.verbose?
104
+ return super(ip) unless verbose?
105
105
 
106
106
  print_title ip.address
107
107
 
@@ -29,226 +29,113 @@ module Ronin
29
29
  #
30
30
  class Repos < ModelCommand
31
31
 
32
- desc 'Manages Ronin repositories'
33
- class_option :add, :type => :string,
34
- :aliases => '-A',
35
- :banner => 'PATH'
36
- class_option :install, :type => :string,
37
- :aliases => '-I',
38
- :banner => 'URI'
39
- class_option :list, :type => :boolean,
40
- :aliases => '-l'
41
- class_option :update, :type => :boolean,
42
- :aliases => '-u'
43
- class_option :uninstall, :type => :string,
44
- :aliases => '-U',
45
- :banner => 'REPO'
46
- class_option :scm, :type => :string, :aliases => '-S'
32
+ summary 'Lists Ronin Repositories'
47
33
 
48
- class_option :rsync, :type => :boolean
49
- class_option :svn, :type => :boolean
50
- class_option :hg, :type => :boolean
51
- class_option :git, :type => :boolean
34
+ model Repository
52
35
 
53
- argument :name, :type => :string, :required => false
36
+ query_option :domain, :type => String,
37
+ :description => 'Domain to filter by'
38
+
39
+ query_option :named, :type => String,
40
+ :flag => '-n',
41
+ :usage => 'NAME',
42
+ :description => 'Name to filter by'
43
+
44
+ query_option :titled, :type => String,
45
+ :flag => '-t',
46
+ :usage => 'TITLE',
47
+ :description => 'Title to filter by'
48
+
49
+ query_option :describing, :type => String,
50
+ :flag => '-d',
51
+ :usage => 'DESC',
52
+ :desc => 'Description to filter by'
53
+
54
+ query_option :licensed_under, :type => String,
55
+ :flag => '-L',
56
+ :usage => 'LICENSE',
57
+ :description => 'License to filter by'
58
+
59
+ argument :repo, :type => String,
60
+ :description => 'Repository to list'
54
61
 
55
62
  #
56
63
  # Executes the command.
57
64
  #
58
65
  def execute
59
- if options[:add]
60
- add options[:add]
61
- elsif options[:install]
62
- install options[:install]
63
- elsif options.update?
64
- update
65
- elsif options[:uninstall]
66
- uninstall options[:uninstall]
66
+ if repo?
67
+ repository = begin
68
+ Repository.find(@repo)
69
+ rescue RepositoryNotFound => e
70
+ print_error e.message
71
+ exit -1
72
+ end
73
+
74
+ print_repository(repository)
67
75
  else
68
- list
76
+ print_array query
69
77
  end
70
78
  end
71
79
 
72
80
  protected
73
81
 
74
82
  #
75
- # The selected SCM.
76
- #
77
- # @return [Symbol]
78
- # The name of the selected SCM.
79
- #
80
- def scm
81
- @scm ||= if options[:scm]
82
- options[:scm].to_sym
83
- elsif options.rsync?
84
- :rsync
85
- elsif options.svn?
86
- :sub_version
87
- elsif options.hg?
88
- :mercurial
89
- elsif options.git?
90
- :git
91
- end
92
- end
93
-
94
- #
95
- # Print out any exceptions or validation errors encountered
96
- # when caching the files of the repository.
83
+ # Prints information about a Repository.
97
84
  #
98
85
  # @param [Repository] repo
99
- # The repository that was updated.
86
+ # The repository to print.
100
87
  #
101
- def print_cache_errors(repo)
102
- repo.cached_files.each do |cached_file|
103
- if cached_file.cache_exception
104
- print_exception cached_file.cache_exception
105
- end
88
+ def print_repository(repo)
89
+ print_title repo.name
106
90
 
107
- if cached_file.cache_errors
108
- cached_file.cache_errors.each do |error|
109
- print_error error
110
- end
91
+ indent do
92
+ if repo.installed?
93
+ puts "Domain: #{repo.domain}"
94
+ else
95
+ puts "Path: #{repo.path}"
111
96
  end
112
- end
113
- end
114
97
 
115
- #
116
- # Lists installed or added Repositories.
117
- #
118
- def list
119
- unless name
120
- print_array Repository.all
121
- else
122
- repo = begin
123
- [Repository.find(name)]
124
- rescue RepositoryNotFound => e
125
- print_error e.message
126
- exit -1
127
- end
128
-
129
- print_title repo.name
130
-
131
- indent do
132
- if repo.installed?
133
- puts "Domain: #{repo.domain}"
134
- else
135
- puts "Path: #{repo.path}"
136
- end
98
+ puts "SCM: #{repo.scm}" if repo.scm
137
99
 
138
- puts "SCM: #{repo.scm}" if repo.scm
100
+ if repo.verbose?
101
+ putc "\n"
139
102
 
140
- if repo.verbose?
141
- putc "\n"
103
+ puts "Title: #{repo.title}" if repo.title
104
+ puts "URI: #{repo.uri}" if repo.uri
105
+ puts "Source URI: #{repo.source}" if repo.source
106
+ puts "Website: #{repo.website}" if repo.website
142
107
 
143
- puts "Title: #{repo.title}" if repo.title
144
- puts "URI: #{repo.uri}" if repo.uri
145
- puts "Source URI: #{repo.source}" if repo.source
146
- puts "Website: #{repo.website}" if repo.website
108
+ executables = repo.executables
147
109
 
148
- executables = repo.executables
110
+ unless executables.empty?
111
+ puts "Executables: #{executables.join(', ')}"
112
+ end
149
113
 
150
- unless executables.empty?
151
- puts "Executables: #{executables.join(', ')}"
152
- end
114
+ putc "\n"
153
115
 
154
- putc "\n"
116
+ unless repo.script_paths.empty?
117
+ print_title 'Cached Files'
155
118
 
156
- unless repo.cached_files.empty?
157
- print_title 'Cached Files'
158
-
159
- indent do
160
- repo.cached_files.each do |cached_file|
161
- puts cached_file.path
162
- end
119
+ indent do
120
+ repo.script_paths.each do |script_path|
121
+ puts script_path.path
163
122
  end
164
123
  end
124
+ end
165
125
 
166
- if repo.description
167
- print_title "Description"
126
+ if repo.description
127
+ print_title "Description"
168
128
 
169
- indent { puts "#{repo.description}\n\n" }
170
- else
171
- putc "\n"
172
- end
129
+ indent { puts "#{repo.description}\n\n" }
173
130
  else
174
131
  putc "\n"
175
132
  end
133
+ else
134
+ putc "\n"
176
135
  end
177
136
  end
178
137
  end
179
138
 
180
- #
181
- # Adds a Repository.
182
- #
183
- # @param [String] path
184
- # The path of the local repository.
185
- #
186
- def add(path)
187
- repo = begin
188
- Repository.add!(:path => path, :scm => @scm)
189
- rescue DuplicateRepository => e
190
- print_error e.message
191
- exit -1
192
- end
193
-
194
- print_info "Repository #{repo} added."
195
- end
196
-
197
- #
198
- # Installs a Repository.
199
- #
200
- # @param [String, URI] uri
201
- # The URI of the remote repository.
202
- #
203
- def install(uri)
204
- repo = begin
205
- Repository.install!(:uri => uri, :scm => scm)
206
- rescue DuplicateRepository => e
207
- print_error e.message
208
- exit -1
209
- end
210
-
211
- print_cache_errors(repo)
212
- print_info "Repository #{repo} has been installed."
213
- end
214
-
215
- #
216
- # Updates installed Repositories.
217
- #
218
- def update
219
- repos = if name
220
- begin
221
- [Repository.find(name)]
222
- rescue RepositoryNotFound => e
223
- print_error e.message
224
- exit -1
225
- end
226
- else
227
- Repository.all
228
- end
229
-
230
- repos.each do |repo|
231
- print_info "Updating repository #{repo} ..."
232
-
233
- repo.update!
234
-
235
- print_cache_errors(repo)
236
- print_info "Repository updated."
237
- end
238
- end
239
-
240
- #
241
- # Uninstalls a Repository.
242
- #
243
- # @param [String] name
244
- # The name of the repository.
245
- #
246
- def uninstall(name)
247
- repo = Repository.uninstall!(name)
248
-
249
- print_info "Uninstalling repository #{repo} ..."
250
- end
251
-
252
139
  end
253
140
  end
254
141
  end