metasploit-credential 1.0.0.pre.rails.pre.4.0c → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +20 -41
  3. data/app/models/metasploit/credential/core.rb +1 -1
  4. data/app/models/metasploit/credential/login.rb +1 -1
  5. data/app/models/metasploit/credential/postgres_md5.rb +4 -0
  6. data/app/models/metasploit/credential/search/operator/type.rb +2 -2
  7. data/lib/metasploit/credential/creation.rb +1 -1
  8. data/lib/metasploit/credential/exporter/core.rb +5 -5
  9. data/lib/metasploit/credential/exporter/pwdump.rb +2 -2
  10. data/lib/metasploit/credential/importer/pwdump.rb +6 -5
  11. data/lib/metasploit/credential/migrator.rb +1 -1
  12. data/lib/metasploit/credential/version.rb +32 -7
  13. data/spec/lib/metasploit/credential/creation_spec.rb +6 -8
  14. data/spec/lib/metasploit/credential/exporter/core_spec.rb +99 -84
  15. data/spec/lib/metasploit/credential/exporter/pwdump_spec.rb +14 -16
  16. data/spec/lib/metasploit/credential/importer/core_spec.rb +10 -12
  17. data/spec/lib/metasploit/credential/importer/multi_spec.rb +4 -6
  18. data/spec/lib/metasploit/credential/importer/pwdump_spec.rb +11 -13
  19. data/spec/lib/metasploit/credential/importer/zip_spec.rb +5 -7
  20. data/spec/lib/metasploit/credential/migrator_spec.rb +8 -9
  21. data/spec/lib/metasploit/credential/version_spec.rb +3 -139
  22. data/spec/lib/metasploit/credential_spec.rb +4 -15
  23. data/spec/models/mdm/service_spec.rb +3 -5
  24. data/spec/models/mdm/session_spec.rb +2 -4
  25. data/spec/models/mdm/task_spec.rb +4 -6
  26. data/spec/models/mdm/user_spec.rb +2 -4
  27. data/spec/models/mdm/workspace_spec.rb +2 -4
  28. data/spec/models/metasploit/credential/blank_username_spec.rb +4 -7
  29. data/spec/models/metasploit/credential/core_spec.rb +43 -45
  30. data/spec/models/metasploit/credential/login/status_spec.rb +19 -21
  31. data/spec/models/metasploit/credential/login_spec.rb +33 -35
  32. data/spec/models/metasploit/credential/nonreplayable_hash_spec.rb +3 -5
  33. data/spec/models/metasploit/credential/ntlm_hash_spec.rb +13 -15
  34. data/spec/models/metasploit/credential/origin/cracked_password_spec.rb +5 -7
  35. data/spec/models/metasploit/credential/origin/import_spec.rb +7 -10
  36. data/spec/models/metasploit/credential/origin/manual_spec.rb +7 -9
  37. data/spec/models/metasploit/credential/origin/service_spec.rb +9 -11
  38. data/spec/models/metasploit/credential/origin/session_spec.rb +10 -12
  39. data/spec/models/metasploit/credential/password_hash_spec.rb +4 -6
  40. data/spec/models/metasploit/credential/password_spec.rb +3 -5
  41. data/spec/models/metasploit/credential/postgres_md5_spec.rb +4 -6
  42. data/spec/models/metasploit/credential/private_spec.rb +7 -9
  43. data/spec/models/metasploit/credential/public_spec.rb +4 -6
  44. data/spec/models/metasploit/credential/realm_spec.rb +12 -14
  45. data/spec/models/metasploit/credential/replayable_hash_spec.rb +3 -5
  46. data/spec/models/metasploit/credential/ssh_key_spec.rb +15 -17
  47. data/spec/models/metasploit/credential/username_spec.rb +5 -9
  48. data/spec/models/metasploit_data_models/search/visitor/relation_spec.rb +1 -3
  49. data/spec/spec_helper.rb +95 -25
  50. data/spec/support/shared/contexts/mdm/workspace.rb +1 -1
  51. data/spec/support/shared/examples/core_validations.rb +117 -42
  52. data/spec/support/shared/examples/single_table_inheritance_database_columns.rb +2 -2
  53. data/spec/support/shared/examples/timestamp_database_column.rb +2 -2
  54. metadata +30 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 11d840c8a6573237be3beafd2d50864f6aafba26
4
- data.tar.gz: db23977d91c96934ada85186052418deda1839ac
3
+ metadata.gz: 2d101098c3d7cc3ab27a13313cb0033a34349272
4
+ data.tar.gz: 357e125b89d9737aef2a6597a173a90e1bd149fc
5
5
  SHA512:
6
- metadata.gz: 9bcf417c1898ba87001552ec9c44eb420f64d0deae78d6a36a0b9713f4f3cac49768f3d1adf2cbfd7e7e92f3fbab86d29226baf2b949a2b98d0c355f34b1ac0d
7
- data.tar.gz: fbed05c95bcc659ce21eafc19b881319364f266c8235f560ad461dfb59412d91e547725c5c82620f434fc24c5945c7c4f4b55ecd1e607aed1035b37435b43db0
6
+ metadata.gz: 9dc70a5df26e28577fd90e7d01e4c739b27e4377e52b5f79ad73ea105b6768c2277ba46df76797b3eb234ef8a19c71b1aedf092e171d307d1564533c5dbda6b5
7
+ data.tar.gz: f454884167aee38773a88c79b73ad07190f60ac75e08d9fd43c3bf30c7d579f5f4fbc1a4d8468740ba0daa42eef43e1667dea4f662a9ecb265ba4a29e4b1ab67
@@ -25,9 +25,9 @@ issue tracking software.
25
25
 
26
26
  ### `PRERELEASE`
27
27
 
28
- 1. Update `PRERELEASE` to match the `SUMMARY` in the branch name. If you branched from `master`, and [version.rb](lib/metasploit/credential/version.rb) does not have `PRERELEASE` defined, then adding the following lines after `PATCH`:
28
+ 1. Update `PRERELEASE` to match the `SUMMARY` in the branch name. If you branched from `master`, and [version.rb](lib/metasploit/credential/version.rb) does not have `PRERELEASE` defined, then adding the following lines after `PATCH`:
29
29
  ```
30
- # The prerelease version, scoped to the {PATCH} version number.
30
+ # The prerelease version, scoped to the {MAJOR}, {MINOR}, and {PATCH} version number.
31
31
  PRERELEASE = '<SUMMARY>'
32
32
  ```
33
33
  2. `rake spec`
@@ -36,21 +36,27 @@ PRERELEASE = '<SUMMARY>'
36
36
 
37
37
  ### Your changes
38
38
 
39
- Make your changes or however many commits you like, commiting each with `git commit`.
39
+ Make your changes or however many commits you like, committing each with `git commit`.
40
40
 
41
41
  ### Pre-Pull Request Testing
42
42
 
43
+ #### Specs
43
44
  1. Run specs one last time before opening the Pull Request: `rake spec`
44
45
  2. Verify there was no failures.
45
46
 
47
+ #### Documentation
48
+ 1. Generate yard documentation to ensure all new code is documented: `rake yard`
49
+ 2. Verify there were no `[warn]`ings.
50
+ 3. Verify there were no undocumented objects.
51
+
46
52
  ### Push
47
53
 
48
- Push your branch to your fork on gitub: `git push push TYPE/ISSUE/SUMMARY`
54
+ Push your branch to your fork on github: `git push TYPE/ISSUE/SUMMARY`
49
55
 
50
56
  ### Pull Request
51
57
 
52
58
  * [Create new Pull Request](https://github.com/rapid7/metasploit-credential/compare/)
53
- * Add a Verification Steps comment
59
+ * Add a Verification Steps to the description comment
54
60
 
55
61
  ```
56
62
  # Verification Steps
@@ -60,7 +66,13 @@ Push your branch to your fork on gitub: `git push push TYPE/ISSUE/SUMMARY`
60
66
  ## `rake spec`
61
67
  - [ ] `rake spec`
62
68
  - [ ] VERIFY no failures
69
+
70
+ ## `rake yard`
71
+ - [ ] `rake yard`
72
+ - [ ] VERIFY no `[warn]`ings
73
+ - [ ] VERIFY no undocumented objects
63
74
  ```
75
+
64
76
  You should also include at least one scenario to manually check the changes outside of specs.
65
77
 
66
78
  * Add a Post-merge Steps comment
@@ -105,7 +117,7 @@ Perform these steps prior to pushing to DESTINATION or the build will be broke o
105
117
  - [ ] Change `PRERELEASE` from `SOURCE_SUMMARY` to `DESTINATION_SUMMARY` to match the branch (DESTINATION) summary (DESTINATION_SUMMARY)
106
118
 
107
119
  ## Gem build
108
- - [ ] gem build *.gemspec
120
+ - [ ] gem build metasploit-credential.gemspec
109
121
  - [ ] VERIFY the prerelease suffix has change on the gem.
110
122
 
111
123
  ## RSpec
@@ -117,38 +129,5 @@ Perform these steps prior to pushing to DESTINATION or the build will be broke o
117
129
  - [ ] `git push origin DESTINATION`
118
130
  ```
119
131
 
120
- * Add a 'Release Steps' comment
121
-
122
- The 'Release Steps' are a reminder to the reviewer of the Pull Request of how to release the gem.
123
-
124
- ```
125
- # Release
126
-
127
- Complete these steps on DESTINATION
128
-
129
- ## `VERSION`
130
-
131
- ### Compatible changes
132
-
133
- If your change are compatible with the previous branch's API, then increment [`PATCH`](lib/metasploit/credential/version.rb).
134
-
135
- ### Incompatible changes
136
-
137
- If your changes are incompatible with the previous branch's API, then increment [`MINOR`](lib/metasploit/credential/version.rb) and reset [`PATCH`](lib/metasploit/credential/version.rb) to `0`.
138
-
139
- - [ ] Following the rules for [semantic versioning 2.0](http://semver.org/spec/v2.0.0.html), update [`MINOR`](lib/metasploit/credential/version.rb) and [`PATCH`](lib/metasploit/credential/version.rb) and commit the changes.
140
-
141
- ## MRI Ruby
142
- - [ ] `rvm use ruby-2.1@metasploit_data_models`
143
- - [ ] `rm Gemfile.lock`
144
- - [ ] `bundle install`
145
- - [ ] `rake release`
146
- ```
147
-
148
- ### Downstream dependencies
149
-
150
- When releasing new versions, the following projects may need to be updated:
151
-
152
- * [metasploit-framework](https://github.com/rapid7/metasploit-framework)
153
- * [metasploit-pro-ui](https://github.com/rapid7/pro/tree/master/ui)
154
- * [metasploit-pro-engine](https://github.com/rapid7/pro/tree/master/engine)
132
+ To update the [CHANGELOG.md](CHANGELOG.md) with the merged changes or release the merged code see
133
+ [RELEASING.md](RELEASING.md)
@@ -12,7 +12,7 @@ class Metasploit::Credential::Core < ActiveRecord::Base
12
12
  #
13
13
 
14
14
  # @!attribute tasks
15
- # The {Mdm::Task tasks} using this to track what tasks interacted with a given core.
15
+ # The `Mdm::Task`s using this to track what tasks interacted with a given core.
16
16
  #
17
17
  # @return [ActiveRecord::Relation<Mdm::Task>]
18
18
  has_and_belongs_to_many :tasks,
@@ -9,7 +9,7 @@ class Metasploit::Credential::Login < ActiveRecord::Base
9
9
  #
10
10
 
11
11
  # @!attribute tasks
12
- # The {Mdm::Task tasks} using this to track what tasks interacted with a given core.
12
+ # The `Mdm::Task`s using this to track what tasks interacted with a given core.
13
13
  #
14
14
  # @return [ActiveRecord::Relation<Mdm::Task>]
15
15
  has_and_belongs_to_many :tasks,
@@ -2,7 +2,11 @@
2
2
  # to authenticate to PostgreSQL servers. It is composed of a hexadecimal string of 32 charachters prepended by the string
3
3
  # 'md5'
4
4
  class Metasploit::Credential::PostgresMD5 < Metasploit::Credential::ReplayableHash
5
+ #
6
+ # CONSTANTS
7
+ #
5
8
 
9
+ # Valid format for {Metasploit::Credential::Private#data}
6
10
  DATA_REGEXP = /md5([a-f0-9]{32})/
7
11
 
8
12
  #
@@ -1,6 +1,6 @@
1
1
  # Operator that searches a polymorphic `#type` attribute. Search terms are restricted to set of `Class#name`s and
2
2
  # `Class#model_name.human` with the `Class#model_name.human` being translated to `Class#name` in the operation returned
3
- # by {#operate_on}.
3
+ # by `#operate_on`.
4
4
  class Metasploit::Credential::Search::Operator::Type < Metasploit::Model::Search::Operator::Attribute
5
5
  #
6
6
  # Attributes
@@ -40,7 +40,7 @@ class Metasploit::Credential::Search::Operator::Type < Metasploit::Model::Search
40
40
  @class_names ||= []
41
41
  end
42
42
 
43
- # Maps `Class.model_name.human` to `Class.name` for all {#classes}.
43
+ # Maps `Class.model_name.human` to `Class.name` for {#class_set}.
44
44
  #
45
45
  # @return [Hash{String => String}] Maps `Class.model_name.name`s to `Class.name`s so `Class.model_names.name` can be
46
46
  # converted to `Class.name` for the in database search.
@@ -1,6 +1,6 @@
1
1
  # Implements a set of "convenience methods" for creating credentials and related portions of the object graph. Creates
2
2
  # {Metasploit::Credential::Core} objects and their attendant relationships as well as {Metasploit::Credential::Login}
3
- # objects and their attendant {Mdm::Host} and {Mdm::Service} objects.
3
+ # objects and their attendant `Mdm::Host` and `Mdm::Service` objects.
4
4
  module Metasploit::Credential::Creation
5
5
 
6
6
  # Returns true if ActiveRecord has an active database connection, false otherwise.
@@ -3,7 +3,7 @@
3
3
  # and `Mdm::Server` information is exported as well. Exported data can be optionally scoped to include only
4
4
  # a certain whitelist of database IDs.
5
5
  #
6
- # The {#export!} method creates a zip file on disk containing a CSV with the data. If the {#workspace} contains
6
+ # The {#export!} method creates a zip file on disk containing a CSV with the data. If the `workspace` contains
7
7
  # {Metasploit::Credential::SSHKey} objects on the exported {Metasploit::Credential::Core} objects, the keys are
8
8
  # exported to files inside a subdirectory of the zip file.
9
9
  # @example Exporting all Cores
@@ -41,7 +41,7 @@ class Metasploit::Credential::Exporter::Core
41
41
  # The downcased and Symbolized name of the default object type to export
42
42
  DEFAULT_MODE = LOGIN_MODE
43
43
 
44
- # An argument to {Dir::mktmpdir}
44
+ # An argument to `Dir::mktmpdir`
45
45
  TEMP_ZIP_PATH_PREFIX = "metasploit-exports"
46
46
 
47
47
 
@@ -49,10 +49,10 @@ class Metasploit::Credential::Exporter::Core
49
49
  # Attributes
50
50
  #
51
51
 
52
- # @!attribute export_data
52
+ # @!attribute [rw] export_data
53
53
  # Holds the raw information from the database before it is formatted into the {#data} attribute
54
54
  # @return [Array]
55
- attr_accessor :export_data
55
+ attr_writer :export_data
56
56
 
57
57
  # @!attribute finalized_zip_file
58
58
  # The final output artifacts, zipped
@@ -109,7 +109,7 @@ class Metasploit::Credential::Exporter::Core
109
109
  end
110
110
 
111
111
  # Returns a platform-agnostic filesystem path where the key data will be saved as a file
112
- # @param line [Hash] the result of {#line_for_login} or #{line_for_core}
112
+ # @param line [Hash] the result of {#line_for_login} or {#line_for_core}
113
113
  # @return [String]
114
114
  def path_for_key(datum)
115
115
  core = datum.is_a?(Metasploit::Credential::Core) ? datum : datum.core
@@ -70,10 +70,10 @@ class Metasploit::Credential::Exporter::Pwdump
70
70
  # Attributes
71
71
  #
72
72
 
73
- # @!attribute logins
73
+ # @!attribute [rw] logins
74
74
  # Holds the raw information from the database before it is formatted into the {#data} attribute
75
75
  # @return [Array<Metasploit::Credential::Login>]
76
- attr_accessor :logins
76
+ attr_writer :logins
77
77
 
78
78
 
79
79
  #
@@ -1,8 +1,8 @@
1
1
  # Implements importation behavior for pwdump files exported by Metasploit as well as files from the John the Ripper
2
2
  # hash cracking suite: http://www.openwall.com/john/
3
3
  #
4
- # Please note that in the case of data exported from Metasploit, the dataset will contain information on the {Mdm::Host}
5
- # and {Mdm::Service} objects that are related to the credential. This means that Metasploit exports will be limited to
4
+ # Please note that in the case of data exported from Metasploit, the dataset will contain information on the `Mdm::Host`
5
+ # and `Mdm::Service` objects that are related to the credential. This means that Metasploit exports will be limited to
6
6
  # containing {Metasploit::Credential::Login} objects, which is the legacy behavior of this export prior to the creation
7
7
  # of this library.
8
8
  class Metasploit::Credential::Importer::Pwdump
@@ -25,9 +25,10 @@ class Metasploit::Credential::Importer::Pwdump
25
25
  # Matches lines that contain usernames and plaintext passwords
26
26
  PLAINTEXT_REGEX = /^[\s]*([\x21-\x7f]+)[\s]+([\x21-\x7f]+)?/n
27
27
 
28
+ # Matches lines taht contain MD5 hashes for PostgreSQL
28
29
  POSTGRES_REGEX = /^[\s]*([\x21-\x7f]+):md5([0-9a-f]{32})$/
29
30
 
30
- # Matches a line that we use to get information for creating {Mdm::Host} and {Mdm::Service} objects
31
+ # Matches a line that we use to get information for creating `Mdm::Host` and `Mdm::Service` objects
31
32
  # TODO: change to use named groups from 1.9+
32
33
  SERVICE_COMMENT_REGEX = /^#[\s]*([0-9.]+):([0-9]+)(\x2f(tcp|udp))?[\s]*(\x28([^\x29]*)\x29)?/n
33
34
 
@@ -70,7 +71,7 @@ class Metasploit::Credential::Importer::Pwdump
70
71
  end
71
72
  end
72
73
 
73
- # Perform the import of the credential data, creating {Mdm::Host} and {Mdm::Service} objects as needed,
74
+ # Perform the import of the credential data, creating `Mdm::Host` and `Mdm::Service` objects as needed,
74
75
  # parsing out data by matching against regex constants that match the various kinds of valid lines found
75
76
  # in the file. Ignore lines which match none of the REGEX constants.
76
77
  # @return [void]
@@ -159,7 +160,7 @@ class Metasploit::Credential::Importer::Pwdump
159
160
  end
160
161
 
161
162
  # Take an msfpwdump comment string and parse it into information necessary for
162
- # creating {Mdm::Host} and {Mdm::Service} objects.
163
+ # creating `Mdm::Host` and `Mdm::Service` objects.
163
164
  # @param comment_string [String] a string starting with a '#' that conforms to {SERVICE_COMMENT_REGEX}
164
165
  # @return [Hash]
165
166
  def service_info_from_comment_string(comment_string)
@@ -104,7 +104,7 @@ class Metasploit::Credential::Migrator
104
104
  # @return [String]
105
105
  def key_data_from_file(path)
106
106
  # Sometimes we will set the :pass attribute to a file path containing the key
107
- if File.exists?(path)
107
+ if File.exist?(path)
108
108
  File.read(path)
109
109
  # In other cases we store the entire SSH key directly in the :pass attribute
110
110
  elsif Metasploit::Credential::SSHKey.new(data: path).private?
@@ -4,20 +4,30 @@ module Metasploit
4
4
  module Credential
5
5
  # Holds components of {VERSION} as defined by {http://semver.org/spec/v2.0.0.html semantic versioning v2.0.0}.
6
6
  module Version
7
+ #
8
+ # CONSTANTS
9
+ #
10
+
7
11
  # The major version number.
8
12
  MAJOR = 1
9
13
  # The minor version number, scoped to the {MAJOR} version number.
10
14
  MINOR = 0
11
- # The patch number, scoped to the {MINOR} version number.
15
+ # The patch version number, scoped to the {MAJOR} and {MINOR} version numbers.
12
16
  PATCH = 0
13
- # the prerelease identifier
14
- PRERELEASE = 'rails-4.0c'
15
17
 
16
- # The full version string, including the {MAJOR}, {MINOR}, {PATCH}, and optionally, the {PRERELEASE} in the
18
+ #
19
+ # Module Methods
20
+ #
21
+
22
+ # The full version string, including the {Metasploit::Credential::Version::MAJOR},
23
+ # {Metasploit::Credential::Version::MINOR}, {Metasploit::Credential::Version::PATCH}, and optionally, the
24
+ # `Metasploit::Credential::Version::PRERELEASE` in the
17
25
  # {http://semver.org/spec/v2.0.0.html semantic versioning v2.0.0} format.
18
26
  #
19
- # @return [String] '{MAJOR}.{MINOR}.{PATCH}' on master. '{MAJOR}.{MINOR}.{PATCH}-{PRERELEASE}' on any branch
20
- # other than master.
27
+ # @return [String] '{Metasploit::Credential::Version::MAJOR}.{Metasploit::Credential::Version::MINOR}.{Metasploit::Credential::Version::PATCH}'
28
+ # on master.
29
+ # '{Metasploit::Credential::Version::MAJOR}.{Metasploit::Credential::Version::MINOR}.{Metasploit::Credential::Version::PATCH}-PRERELEASE'
30
+ # on any branch other than master.
21
31
  def self.full
22
32
  version = "#{MAJOR}.#{MINOR}.#{PATCH}"
23
33
 
@@ -27,9 +37,24 @@ module Metasploit
27
37
 
28
38
  version
29
39
  end
40
+
41
+ # The full gem version string, including the {Metasploit::Credential::Version::MAJOR},
42
+ # {Metasploit::Credential::Version::MINOR}, {Metasploit::Credential::Version::PATCH}, and optionally, the
43
+ # `Metasploit::Credential::Version::PRERELEASE` in the
44
+ # {http://guides.rubygems.org/specification-reference/#version RubyGems versioning} format.
45
+ #
46
+ # @return [String] '{Metasploit::Credential::Version::MAJOR}.{Metasploit::Credential::Version::MINOR}.{Metasploit::Credential::Version::PATCH}'
47
+ # on master. '{Metasploit::Credential::Version::MAJOR}.{Metasploit::Credential::Version::MINOR}.{Metasploit::Credential::Version::PATCH}.PRERELEASE'
48
+ # on any branch other than master.
49
+ def self.gem
50
+ full.gsub('-', '.pre.')
51
+ end
30
52
  end
31
53
 
32
- # @see Version.full
54
+ # (see Version.gem)
55
+ GEM_VERSION = Version.gem
56
+
57
+ # (see Version.full)
33
58
  VERSION = Version.full
34
59
  end
35
60
  end
@@ -1,6 +1,4 @@
1
- require 'spec_helper'
2
-
3
- describe Metasploit::Credential::Creation do
1
+ RSpec.describe Metasploit::Credential::Creation do
4
2
  include_context 'Mdm::Workspace'
5
3
  let(:dummy_class) {
6
4
  Class.new do
@@ -42,7 +40,7 @@ describe Metasploit::Credential::Creation do
42
40
 
43
41
  it 'replicates realm in new credential' do
44
42
  expect {
45
- core = test_object.create_cracked_credential(
43
+ test_object.create_cracked_credential(
46
44
  core_id: old_core.id,
47
45
  workspace_id: workspace.id,
48
46
  username: public.username,
@@ -160,7 +158,7 @@ describe Metasploit::Credential::Creation do
160
158
 
161
159
  it 'should create an Mdm::Service in state "open"' do
162
160
  service = test_object.create_credential_service opts
163
- service.state.should == "open"
161
+ expect(service.state).to eq("open")
164
162
  end
165
163
  end
166
164
 
@@ -483,7 +481,7 @@ describe Metasploit::Credential::Creation do
483
481
  task_id: task.id
484
482
  }
485
483
  core = test_object.create_credential(opts)
486
- core.tasks.should include(task)
484
+ expect(core.tasks).to include(task)
487
485
  end
488
486
 
489
487
  end
@@ -526,7 +524,7 @@ describe Metasploit::Credential::Creation do
526
524
  task_id: task.id
527
525
  }
528
526
  core = test_object.create_credential_core(opts)
529
- core.tasks.should include(task)
527
+ expect(core.tasks).to include(task)
530
528
  end
531
529
 
532
530
  end
@@ -563,7 +561,7 @@ describe Metasploit::Credential::Creation do
563
561
  status: Metasploit::Model::Login::Status::SUCCESSFUL,
564
562
  }
565
563
  login = test_object.create_credential_login(login_data)
566
- login.tasks.should include(task)
564
+ expect(login.tasks).to include(task)
567
565
 
568
566
  end
569
567
 
@@ -1,6 +1,4 @@
1
- require 'spec_helper'
2
-
3
- describe Metasploit::Credential::Exporter::Core do
1
+ RSpec.describe Metasploit::Credential::Exporter::Core do
4
2
  include_context 'Mdm::Workspace'
5
3
  include_context 'export objects'
6
4
 
@@ -24,19 +22,19 @@ describe Metasploit::Credential::Exporter::Core do
24
22
  end
25
23
 
26
24
  it 'should be in LOGIN_MODE by default' do
27
- core_exporter.mode.should == Metasploit::Credential::Exporter::Core::LOGIN_MODE
25
+ expect(core_exporter.mode).to eq(Metasploit::Credential::Exporter::Core::LOGIN_MODE)
28
26
  end
29
27
  end
30
28
 
31
29
  describe "#export!" do
32
30
  it 'should create the zipfile' do
33
31
  core_exporter.export!
34
- File.exists?(core_exporter.output_zipfile_path).should be_true
32
+ expect(File.exists?(core_exporter.output_zipfile_path)).to eq(true)
35
33
  end
36
34
 
37
35
  it 'should output to a directory whose name contains the standardized identifier' do
38
36
  core_exporter.export!
39
- core_exporter.output_final_directory_path.should include(Metasploit::Credential::Exporter::Core::CREDS_DUMP_FILE_IDENTIFIER)
37
+ expect(core_exporter.output_final_directory_path).to include(Metasploit::Credential::Exporter::Core::CREDS_DUMP_FILE_IDENTIFIER)
40
38
  end
41
39
  end
42
40
 
@@ -46,14 +44,14 @@ describe Metasploit::Credential::Exporter::Core do
46
44
  describe "when the argument is a Core" do
47
45
  it 'should be formed from the Public#username and the Private#id' do
48
46
  key_path = core_exporter.path_for_key(core)
49
- Pathname.new(key_path).basename.to_s.should == key_path_basename_string
47
+ expect(Pathname.new(key_path).basename.to_s).to eq(key_path_basename_string)
50
48
  end
51
49
  end
52
50
 
53
51
  describe "when the argument is a Login" do
54
52
  it 'should be formed from the Public#username and the Private#id' do
55
53
  key_path = core_exporter.path_for_key(login)
56
- Pathname.new(key_path).basename.to_s.should == key_path_basename_string
54
+ expect(Pathname.new(key_path).basename.to_s).to eq(key_path_basename_string)
57
55
  end
58
56
  end
59
57
  end
@@ -62,20 +60,27 @@ describe Metasploit::Credential::Exporter::Core do
62
60
  let(:result_hash) { core_exporter.line_for_core(core) }
63
61
 
64
62
  it 'should produce values in the proper order' do
65
- result_hash.values.should == [core.public.username, core.private.type,
66
- core.private.data, core.realm.key, core.realm.value]
63
+ expect(result_hash.values).to eq(
64
+ [
65
+ core.public.username,
66
+ core.private.type,
67
+ core.private.data,
68
+ core.realm.key,
69
+ core.realm.value
70
+ ]
71
+ )
67
72
  end
68
73
 
69
74
  it 'should produce a hash with the public username' do
70
- result_hash[:username].should == core.public.username
75
+ expect(result_hash[:username]).to eq(core.public.username)
71
76
  end
72
77
 
73
78
  it 'should produce a hash with the private data' do
74
- result_hash[:private_data].should == core.private.data
79
+ expect(result_hash[:private_data]).to eq(core.private.data)
75
80
  end
76
81
 
77
82
  it 'should produce a hash with the name of the private type' do
78
- result_hash[:private_type].should == core.private.type
83
+ expect(result_hash[:private_type]).to eq(core.private.type)
79
84
  end
80
85
  end
81
86
 
@@ -84,84 +89,94 @@ describe Metasploit::Credential::Exporter::Core do
84
89
  let(:result_hash) { core_exporter.line_for_login(login) }
85
90
 
86
91
  it 'should produce values in the proper order' do
87
- result_hash.values.should == [core.public.username, core.private.type,
88
- core.private.data, core.realm.key, core.realm.value,
89
- login.service.host.address.to_s, login.service.port,
90
- login.service.name, login.service.proto,
91
- login.status, login.access_level, login.last_attempted_at
92
- ]
92
+ expect(result_hash.values).to eq(
93
+ [
94
+ core.public.username,
95
+ core.private.type,
96
+ core.private.data,
97
+ core.realm.key,
98
+ core.realm.value,
99
+ login.service.host.address,
100
+ login.service.port,
101
+ login.service.name,
102
+ login.service.proto,
103
+ login.status,
104
+ login.access_level,
105
+ login.last_attempted_at
106
+ ]
107
+ )
93
108
  end
94
109
 
95
110
  it 'should produce a hash with the service host address' do
96
- result_hash[:host_address].should == login.service.host.address.to_s
111
+ expect(result_hash[:host_address]).to eq(login.service.host.address.to_s)
97
112
  end
98
113
 
99
114
  it 'should produce a hash with the service port' do
100
- result_hash[:service_port].should == login.service.port
115
+ expect(result_hash[:service_port]).to eq(login.service.port)
101
116
  end
102
117
 
103
118
  it 'should produce a hash with the service name' do
104
- result_hash[:service_name].should == login.service.name
119
+ expect(result_hash[:service_name]).to eq(login.service.name)
105
120
  end
106
121
 
107
122
  it 'should produce a hash with the service protocol' do
108
- result_hash[:service_protocol].should == login.service.proto
123
+ expect(result_hash[:service_protocol]).to eq(login.service.proto)
109
124
  end
110
125
 
111
126
  it 'should produce a hash with the login status' do
112
- result_hash[:status].should == login.status
127
+ expect(result_hash[:status]).to eq(login.status)
113
128
  end
114
129
 
115
130
  it 'should produce a hash with the login access_level' do
116
- result_hash[:access_level].should == login.access_level
131
+ expect(result_hash[:access_level]).to eq(login.access_level)
117
132
  end
118
133
 
119
134
  it 'should produce a hash with the login last_attempted_at' do
120
- result_hash[:last_attempted_at].should == login.last_attempted_at
135
+ expect(result_hash[:last_attempted_at]).to eq(login.last_attempted_at)
121
136
  end
122
137
 
123
138
  it 'should produce a hash with the public information' do
124
- result_hash[:username].should == login.core.public.username
139
+ expect(result_hash[:username]).to eq(login.core.public.username)
125
140
  end
126
141
 
127
142
  it 'should produce a hash with the private data' do
128
- result_hash[:private_data].should == login.core.private.data
143
+ expect(result_hash[:private_data]).to eq(login.core.private.data)
129
144
  end
130
145
 
131
146
  it 'should produce a hash with the demodulized name of the private type' do
132
- result_hash[:private_type].should == login.core.private.type
147
+ expect(result_hash[:private_type]).to eq(login.core.private.type)
133
148
  end
134
149
  end
135
150
 
136
151
  describe "#output" do
137
152
  it 'should be a writable File' do
138
153
  file_stat = core_exporter.output.stat
139
- file_stat.should be_writable
154
+ expect(file_stat).to be_writable
140
155
  end
141
156
 
142
157
  it 'should not be opened in binmode' do
143
- core_exporter.output.should_not be_binmode
158
+ expect(core_exporter.output).not_to be_binmode
144
159
  end
145
160
  end
146
161
 
147
162
  describe "#output_directory_path" do
148
163
  it 'should be in the platform-agnostic temp directory' do
149
- core_exporter.output_final_directory_path.should include(Dir.tmpdir)
164
+ expect(core_exporter.output_final_directory_path).to include(Dir.tmpdir)
150
165
  end
151
166
 
152
167
  it 'should have the set export prefix' do
153
- core_exporter.output_final_directory_path.should include(Metasploit::Credential::Exporter::Core::TEMP_ZIP_PATH_PREFIX)
168
+ expect(core_exporter.output_final_directory_path).to include(Metasploit::Credential::Exporter::Core::TEMP_ZIP_PATH_PREFIX)
154
169
  end
155
170
 
156
171
  describe "uniqueness for export" do
157
172
  let(:path_fragment){ "export-#{Time.now.to_s}" }
158
173
 
159
174
  before(:each) do
160
- core_exporter.stub(:output_final_subdirectory_name).and_return(path_fragment)
175
+ allow(core_exporter).to receive(:output_final_subdirectory_name).and_return(path_fragment)
161
176
  end
162
177
 
163
178
  it 'should include a special time-stamped directory to contain the export data being staged' do
164
- core_exporter.output_final_directory_path.should include(core_exporter.output_final_subdirectory_name)
179
+ expect(core_exporter.output_final_directory_path).to include(core_exporter.output_final_subdirectory_name)
165
180
  end
166
181
  end
167
182
  end
@@ -169,44 +184,44 @@ describe Metasploit::Credential::Exporter::Core do
169
184
  describe "#data" do
170
185
  describe "in LOGIN_MODE" do
171
186
  before(:each) do
172
- core_exporter.stub(:mode).and_return Metasploit::Credential::Exporter::Core::LOGIN_MODE
187
+ allow(core_exporter).to receive(:mode).and_return Metasploit::Credential::Exporter::Core::LOGIN_MODE
173
188
  end
174
189
 
175
190
  describe "when whitelist_ids is present" do
176
191
  before(:each) do
177
- core_exporter.stub(:whitelist_ids).and_return([login1.id])
192
+ allow(core_exporter).to receive(:whitelist_ids).and_return([login1.id])
178
193
  end
179
194
 
180
195
  it 'should contain only those objects whose IDs are in the whitelist' do
181
- core_exporter.data.should_not include(login2)
196
+ expect(core_exporter.data).not_to include(login2)
182
197
  end
183
198
  end
184
199
 
185
200
  describe "when whitelist_ids is blank" do
186
201
  it 'should be the same as #export_data' do
187
- core_exporter.data.should == core_exporter.export_data
202
+ expect(core_exporter.data).to eq(core_exporter.export_data)
188
203
  end
189
204
  end
190
205
  end
191
206
 
192
207
  describe "in CORE_MODE" do
193
208
  before(:each) do
194
- core_exporter.stub(:mode).and_return Metasploit::Credential::Exporter::Core::CORE_MODE
209
+ allow(core_exporter).to receive(:mode).and_return Metasploit::Credential::Exporter::Core::CORE_MODE
195
210
  end
196
211
 
197
212
  describe "when whitelist_ids is present" do
198
213
  before(:each) do
199
- core_exporter.stub(:whitelist_ids).and_return([core1.id])
214
+ allow(core_exporter).to receive(:whitelist_ids).and_return([core1.id])
200
215
  end
201
216
 
202
217
  it 'should contain only those objects whose IDs are in the whitelist' do
203
- core_exporter.data.should_not include(core2)
218
+ expect(core_exporter.data).not_to include(core2)
204
219
  end
205
220
  end
206
221
 
207
222
  describe "when whitelist_ids is blank" do
208
223
  it 'should be the same as #export_data' do
209
- core_exporter.data.should == core_exporter.export_data
224
+ expect(core_exporter.data).to eq(core_exporter.export_data)
210
225
  end
211
226
  end
212
227
  end
@@ -215,22 +230,22 @@ describe Metasploit::Credential::Exporter::Core do
215
230
  describe "#export_data" do
216
231
  describe "in CORE_MODE" do
217
232
  before(:each) do
218
- core_exporter.stub(:mode).and_return Metasploit::Credential::Exporter::Core::CORE_MODE
233
+ allow(core_exporter).to receive(:mode).and_return Metasploit::Credential::Exporter::Core::CORE_MODE
219
234
  end
220
235
 
221
236
  it 'should grab data using the proper scope' do
222
- Metasploit::Credential::Core.should_receive(:workspace_id).with(core_exporter.workspace.id)
237
+ expect(Metasploit::Credential::Core).to receive(:workspace_id).with(core_exporter.workspace.id)
223
238
  core_exporter.export_data
224
239
  end
225
240
  end
226
241
 
227
242
  describe "in LOGIN_MODE" do
228
243
  before(:each) do
229
- core_exporter.stub(:mode).and_return Metasploit::Credential::Exporter::Core::LOGIN_MODE
244
+ allow(core_exporter).to receive(:mode).and_return Metasploit::Credential::Exporter::Core::LOGIN_MODE
230
245
  end
231
246
 
232
247
  it 'should grab data using the proper scope' do
233
- Metasploit::Credential::Login.should_receive(:in_workspace_including_hosts_and_services).with(core_exporter.workspace)
248
+ expect(Metasploit::Credential::Login).to receive(:in_workspace_including_hosts_and_services).with(core_exporter.workspace)
234
249
  core_exporter.export_data
235
250
  end
236
251
  end
@@ -240,7 +255,7 @@ describe Metasploit::Credential::Exporter::Core do
240
255
  describe "#render_manifest_and_output_keys" do
241
256
  describe "in CORE_MODE" do
242
257
  before(:each) do
243
- core_exporter.stub(:mode).and_return Metasploit::Credential::Exporter::Core::CORE_MODE
258
+ allow(core_exporter).to receive(:mode).and_return Metasploit::Credential::Exporter::Core::CORE_MODE
244
259
  core_exporter.render_manifest_output_and_keys
245
260
  path = core_exporter.output_final_directory_path + '/' + Metasploit::Credential::Importer::Zip::MANIFEST_FILE_NAME
246
261
 
@@ -260,34 +275,34 @@ describe Metasploit::Credential::Exporter::Core do
260
275
  end
261
276
 
262
277
  it 'should contain the Public#username for all Core objects' do
263
- @core_publics.should include(core1.public.username)
264
- @core_publics.should include(core2.public.username)
278
+ expect(@core_publics).to include(core1.public.username)
279
+ expect(@core_publics).to include(core2.public.username)
265
280
  end
266
281
 
267
282
  it 'should contain the Private#type for all Core objects' do
268
- @core_private_types.should include(core1.private.type)
269
- @core_private_types.should include(core2.private.type)
283
+ expect(@core_private_types).to include(core1.private.type)
284
+ expect(@core_private_types).to include(core2.private.type)
270
285
  end
271
286
 
272
287
  it 'should contain the Private#data for all Core objects' do
273
- @core_private_data.should include(core1.private.data)
274
- @core_private_data.should include(core2.private.data)
288
+ expect(@core_private_data).to include(core1.private.data)
289
+ expect(@core_private_data).to include(core2.private.data)
275
290
  end
276
291
 
277
292
  it 'should contain the Realm#key for all Core objects' do
278
- @core_realm_keys.should include(core1.realm.key)
279
- @core_realm_keys.should include(core2.realm.key)
293
+ expect(@core_realm_keys).to include(core1.realm.key)
294
+ expect(@core_realm_keys).to include(core2.realm.key)
280
295
  end
281
296
 
282
297
  it 'should contain the Realm#value for all Core objects' do
283
- @core_realm_values.should include(core1.realm.value)
284
- @core_realm_values.should include(core2.realm.value)
298
+ expect(@core_realm_values).to include(core1.realm.value)
299
+ expect(@core_realm_values).to include(core2.realm.value)
285
300
  end
286
301
  end
287
302
 
288
303
  describe "in LOGIN_MODE" do
289
304
  before(:each) do
290
- core_exporter.stub(:mode).and_return Metasploit::Credential::Exporter::Core::LOGIN_MODE
305
+ allow(core_exporter).to receive(:mode).and_return Metasploit::Credential::Exporter::Core::LOGIN_MODE
291
306
  core_exporter.render_manifest_output_and_keys
292
307
  path = core_exporter.output_final_directory_path + '/' + Metasploit::Credential::Importer::Zip::MANIFEST_FILE_NAME
293
308
 
@@ -316,47 +331,47 @@ describe Metasploit::Credential::Exporter::Core do
316
331
 
317
332
 
318
333
  it 'should contain the Public#username for all Login objects' do
319
- @login_publics.should include(login1.core.public.username)
320
- @login_publics.should include(login2.core.public.username)
334
+ expect(@login_publics).to include(login1.core.public.username)
335
+ expect(@login_publics).to include(login2.core.public.username)
321
336
  end
322
337
 
323
338
  it 'should contain the Private#type for all Login objects' do
324
- @login_private_types.should include(login1.core.private.type)
325
- @login_private_types.should include(login2.core.private.type)
339
+ expect(@login_private_types).to include(login1.core.private.type)
340
+ expect(@login_private_types).to include(login2.core.private.type)
326
341
  end
327
342
 
328
343
  it 'should contain the Private#data for all Login objects' do
329
- @login_private_data.should include(login1.core.private.data)
330
- @login_private_data.should include(login2.core.private.data)
344
+ expect(@login_private_data).to include(login1.core.private.data)
345
+ expect(@login_private_data).to include(login2.core.private.data)
331
346
  end
332
347
 
333
348
  it 'should contain the Realm#key for all Login objects' do
334
- @login_realm_keys.should include(login1.core.realm.key)
335
- @login_realm_keys.should include(login2.core.realm.key)
349
+ expect(@login_realm_keys).to include(login1.core.realm.key)
350
+ expect(@login_realm_keys).to include(login2.core.realm.key)
336
351
  end
337
352
 
338
353
  it 'should contain the Realm#value for all Login objects' do
339
- @login_realm_values.should include(login1.core.realm.value)
340
- @login_realm_values.should include(login2.core.realm.value)
354
+ expect(@login_realm_values).to include(login1.core.realm.value)
355
+ expect(@login_realm_values).to include(login2.core.realm.value)
341
356
  end
342
357
 
343
358
  it 'should contain the associated Mdm::Host#address for all Login objects' do
344
- @login_host_addresses.should include(login1.service.host.address.to_s, login2.service.host.address.to_s)
359
+ expect(@login_host_addresses).to include(login1.service.host.address.to_s, login2.service.host.address.to_s)
345
360
  end
346
361
 
347
362
  it 'should contain the associated Mdm::Service#port (stringified) for all Login objects' do
348
- @login_service_ports.should include(login1.service.port.to_s)
349
- @login_service_ports.should include(login2.service.port.to_s)
363
+ expect(@login_service_ports).to include(login1.service.port.to_s)
364
+ expect(@login_service_ports).to include(login2.service.port.to_s)
350
365
  end
351
366
 
352
367
  it 'should contain the associated Mdm::Service#name for all Login objects' do
353
- @login_service_names.should include(login1.service.name)
354
- @login_service_names.should include(login2.service.name)
368
+ expect(@login_service_names).to include(login1.service.name)
369
+ expect(@login_service_names).to include(login2.service.name)
355
370
  end
356
371
 
357
372
  it 'should contain the associated Mdm::Service#proto for all Login objects' do
358
- @login_service_protocols.should include(login1.service.proto)
359
- @login_service_protocols.should include(login2.service.proto)
373
+ expect(@login_service_protocols).to include(login1.service.proto)
374
+ expect(@login_service_protocols).to include(login2.service.proto)
360
375
  end
361
376
  end
362
377
  end
@@ -364,7 +379,7 @@ describe Metasploit::Credential::Exporter::Core do
364
379
  describe "#render_zip" do
365
380
  describe "when there are no SSH keys in the dataset" do
366
381
  before(:each) do
367
- core_exporter.stub(:mode).and_return Metasploit::Credential::Exporter::Core::CORE_MODE
382
+ allow(core_exporter).to receive(:mode).and_return Metasploit::Credential::Exporter::Core::CORE_MODE
368
383
  core_exporter.render_manifest_output_and_keys
369
384
  core_exporter.render_zip
370
385
  end
@@ -374,7 +389,7 @@ describe Metasploit::Credential::Exporter::Core do
374
389
  Zip::File.open(core_exporter.output_zipfile_path) do |zip_file|
375
390
  manifest_entry = zip_file.glob(Metasploit::Credential::Importer::Zip::MANIFEST_FILE_NAME).first
376
391
  end
377
- manifest_entry.should_not be_blank
392
+ expect(manifest_entry).not_to be_blank
378
393
  end
379
394
 
380
395
  it 'should not contain a keys directory' do
@@ -382,7 +397,7 @@ describe Metasploit::Credential::Exporter::Core do
382
397
  Zip::File.open(core_exporter.output_zipfile_path) do |zip_file|
383
398
  keys_entry = zip_file.glob(Metasploit::Credential::Importer::Zip::KEYS_SUBDIRECTORY_NAME).first
384
399
  end
385
- keys_entry.should be_blank
400
+ expect(keys_entry).to be_blank
386
401
  end
387
402
  end
388
403
 
@@ -395,7 +410,7 @@ describe Metasploit::Credential::Exporter::Core do
395
410
  workspace: workspace)}
396
411
 
397
412
  before(:each) do
398
- core_exporter.stub(:mode).and_return Metasploit::Credential::Exporter::Core::CORE_MODE
413
+ allow(core_exporter).to receive(:mode).and_return Metasploit::Credential::Exporter::Core::CORE_MODE
399
414
  core_exporter.render_manifest_output_and_keys
400
415
  core_exporter.render_zip
401
416
  end
@@ -405,7 +420,7 @@ describe Metasploit::Credential::Exporter::Core do
405
420
  Zip::File.open(core_exporter.output_zipfile_path) do |zip_file|
406
421
  manifest_entry = zip_file.glob(Metasploit::Credential::Importer::Zip::MANIFEST_FILE_NAME).first
407
422
  end
408
- manifest_entry.should_not be_blank
423
+ expect(manifest_entry).not_to be_blank
409
424
  end
410
425
 
411
426
  it 'should contain a keys directory' do
@@ -413,7 +428,7 @@ describe Metasploit::Credential::Exporter::Core do
413
428
  Zip::File.open(core_exporter.output_zipfile_path) do |zip_file|
414
429
  keys_entry = zip_file.glob(Metasploit::Credential::Importer::Zip::KEYS_SUBDIRECTORY_NAME).first
415
430
  end
416
- keys_entry.should_not be_blank
431
+ expect(keys_entry).not_to be_blank
417
432
  end
418
433
 
419
434
  describe "the keys directory" do
@@ -425,12 +440,12 @@ describe Metasploit::Credential::Exporter::Core do
425
440
  end
426
441
 
427
442
  it 'should contain a key for each SSH private in the export' do
428
- @key_entries.size.should == core_exporter.data[:core].select{ |d| d.private.type == Metasploit::Credential::SSHKey.name }.size
443
+ expect(@key_entries.size).to eq(core_exporter.data[:core].select{ |d| d.private.type == Metasploit::Credential::SSHKey.name }.size)
429
444
  end
430
445
 
431
446
  it 'should contain key files named with Public#username and Private#id for each Core that uses an SSHKey' do
432
447
  key_names = @key_entries.map{ |e| e.to_s.gsub("#{Metasploit::Credential::Importer::Zip::KEYS_SUBDIRECTORY_NAME}/", '') }
433
- key_names.should include("#{core_with_key.public.username}-#{core_with_key.private.id}")
448
+ expect(key_names).to include("#{core_with_key.public.username}-#{core_with_key.private.id}")
434
449
  end
435
450
 
436
451
  end