ronin-db-activerecord 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.document +0 -1
  3. data/.github/workflows/ruby.yml +14 -0
  4. data/.rubocop.yml +16 -0
  5. data/ChangeLog.md +18 -1
  6. data/Gemfile +4 -0
  7. data/README.md +1 -2
  8. data/Rakefile +3 -3
  9. data/db/migrate/{0014_create_ronin_ip_addresses_table.rb → 0001_create_ronin_ip_addresses_table.rb} +4 -0
  10. data/db/migrate/{0021_create_ronin_mac_addresses_table.rb → 0002_create_ronin_mac_addresses_table.rb} +4 -0
  11. data/db/migrate/{0001_create_ronin_ip_address_mac_addresses_table.rb → 0003_create_ronin_ip_address_mac_addresses_table.rb} +4 -0
  12. data/db/migrate/{0009_create_ronin_host_names_table.rb → 0004_create_ronin_host_names_table.rb} +4 -0
  13. data/db/migrate/{0025_create_ronin_ports_table.rb → 0005_create_ronin_ports_table.rb} +4 -0
  14. data/db/migrate/{0023_create_ronin_services_table.rb → 0006_create_ronin_services_table.rb} +4 -0
  15. data/db/migrate/{0018_create_ronin_open_ports_table.rb → 0007_create_ronin_open_ports_table.rb} +4 -0
  16. data/db/migrate/{0003_create_ronin_url_schemes_table.rb → 0008_create_ronin_url_schemes_table.rb} +4 -0
  17. data/db/migrate/{0019_create_ronin_urls_table.rb → 0009_create_ronin_urls_table.rb} +5 -0
  18. data/db/migrate/0010_create_ronin_advisories_table.rb +45 -0
  19. data/db/migrate/{0002_create_ronin_vulnerabilities_table.rb → 0011_create_ronin_vulnerabilities_table.rb} +14 -11
  20. data/db/migrate/{0004_create_ronin_url_query_param_names_table.rb → 0012_create_ronin_url_query_param_names_table.rb} +4 -0
  21. data/db/migrate/{0005_create_ronin_user_names_table.rb → 0013_create_ronin_user_names_table.rb} +4 -0
  22. data/db/migrate/{0006_create_ronin_software_vendors_table.rb → 0014_create_ronin_software_vendors_table.rb} +4 -0
  23. data/db/migrate/{0008_create_ronin_host_name_ip_addresses_table.rb → 0015_create_ronin_host_name_ip_addresses_table.rb} +4 -0
  24. data/db/migrate/{0010_create_ronin_arches_table.rb → 0016_create_ronin_arches_table.rb} +3 -0
  25. data/db/migrate/{0011_create_ronin_email_addresses_table.rb → 0017_create_ronin_email_addresses_table.rb} +4 -0
  26. data/db/migrate/{0012_create_ronin_oses_table.rb → 0018_create_ronin_oses_table.rb} +4 -0
  27. data/db/migrate/{0013_create_ronin_organizations_table.rb → 0019_create_ronin_organizations_table.rb} +4 -0
  28. data/db/migrate/{0015_create_ronin_os_guesses_table.rb → 0020_create_ronin_os_guesses_table.rb} +4 -0
  29. data/db/migrate/{0016_create_ronin_url_query_params_table.rb → 0021_create_ronin_url_query_params_table.rb} +4 -0
  30. data/db/migrate/{0017_create_ronin_passwords_table.rb → 0022_create_ronin_passwords_table.rb} +4 -0
  31. data/db/migrate/{0020_create_ronin_softwares_table.rb → 0023_create_ronin_softwares_table.rb} +5 -3
  32. data/db/migrate/{0022_create_ronin_countries_table.rb → 0024_create_ronin_countries_table.rb} +4 -0
  33. data/db/migrate/{0024_create_ronin_credentials_table.rb → 0025_create_ronin_credentials_table.rb} +4 -0
  34. data/db/migrate/0026_create_ronin_asns_table.rb +4 -0
  35. data/db/migrate/0027_create_ronin_http_query_param_names_table.rb +4 -0
  36. data/db/migrate/{0033_create_ronin_http_responses_table.rb → 0028_create_ronin_http_responses_table.rb} +5 -3
  37. data/db/migrate/{0032_create_ronin_http_requests_table.rb → 0029_create_ronin_http_requests_table.rb} +5 -3
  38. data/db/migrate/{0028_create_ronin_http_query_params_table.rb → 0030_create_ronin_http_query_params_table.rb} +4 -0
  39. data/db/migrate/{0029_create_ronin_http_header_names_table.rb → 0031_create_ronin_http_header_names_table.rb} +4 -0
  40. data/db/migrate/{0030_create_ronin_http_request_headers_table.rb → 0032_create_ronin_http_request_headers_table.rb} +4 -0
  41. data/db/migrate/{0031_create_ronin_http_response_headers_table.rb → 0033_create_ronin_http_response_headers_table.rb} +4 -0
  42. data/db/migrate/0034_create_ronin_service_credentials_table.rb +4 -0
  43. data/db/migrate/0035_create_ronin_web_credentials_table.rb +4 -0
  44. data/gemspec.yml +1 -1
  45. data/lib/ronin/db/address.rb +4 -2
  46. data/lib/ronin/db/advisory.rb +4 -4
  47. data/lib/ronin/db/asn.rb +5 -5
  48. data/lib/ronin/db/email_address.rb +1 -1
  49. data/lib/ronin/db/host_name.rb +1 -1
  50. data/lib/ronin/db/host_name_ip_address.rb +1 -1
  51. data/lib/ronin/db/http_query_param_name.rb +1 -1
  52. data/lib/ronin/db/http_request.rb +1 -1
  53. data/lib/ronin/db/http_response.rb +1 -1
  54. data/lib/ronin/db/ip_address.rb +1 -1
  55. data/lib/ronin/db/ip_address_mac_address.rb +1 -1
  56. data/lib/ronin/db/mac_address.rb +4 -4
  57. data/lib/ronin/db/migrations.rb +11 -8
  58. data/lib/ronin/db/model/has_unique_name.rb +2 -4
  59. data/lib/ronin/db/model/importable.rb +3 -0
  60. data/lib/ronin/db/model/last_scanned_at.rb +4 -1
  61. data/lib/ronin/db/model.rb +3 -0
  62. data/lib/ronin/db/models.rb +3 -0
  63. data/lib/ronin/db/open_port.rb +1 -1
  64. data/lib/ronin/db/organization.rb +1 -1
  65. data/lib/ronin/db/os.rb +2 -2
  66. data/lib/ronin/db/os_guess.rb +1 -1
  67. data/lib/ronin/db/password.rb +3 -3
  68. data/lib/ronin/db/software.rb +2 -2
  69. data/lib/ronin/db/url.rb +21 -24
  70. data/lib/ronin/db/url_query_param_name.rb +1 -1
  71. data/lib/ronin/db/url_scheme.rb +1 -1
  72. data/lib/ronin/db/user_name.rb +1 -1
  73. data/lib/ronin/db/vulnerability.rb +4 -0
  74. data/ronin-db-activerecord.gemspec +3 -3
  75. metadata +34 -33
  76. data/db/migrate/0007_create_ronin_advisories_table.rb +0 -42
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
3
4
  #
@@ -19,6 +20,9 @@
19
20
  # along with ronin-db-activerecord. If not, see <https://www.gnu.org/licenses/>.
20
21
  #
21
22
 
23
+ #
24
+ # Creates the `ronin_http_requests` table.
25
+ #
22
26
  class CreateRoninHttpRequestsTable < ActiveRecord::Migration[7.0]
23
27
 
24
28
  def change
@@ -28,9 +32,7 @@ class CreateRoninHttpRequestsTable < ActiveRecord::Migration[7.0]
28
32
  t.string :path, null: false
29
33
  t.text :body
30
34
 
31
- t.references :response, foreign_key: {
32
- to_table: :ronin_http_responses
33
- }
35
+ t.references :response, foreign_key: {to_table: :ronin_http_responses}
34
36
 
35
37
  t.datetime :created_at, null: false
36
38
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
3
4
  #
@@ -19,6 +20,9 @@
19
20
  # along with ronin-db-activerecord. If not, see <https://www.gnu.org/licenses/>.
20
21
  #
21
22
 
23
+ #
24
+ # Creates the `ronin_http_query_params` table.
25
+ #
22
26
  class CreateRoninHttpQueryParamsTable < ActiveRecord::Migration[7.0]
23
27
 
24
28
  def change
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
3
4
  #
@@ -19,6 +20,9 @@
19
20
  # along with ronin-db-activerecord. If not, see <https://www.gnu.org/licenses/>.
20
21
  #
21
22
 
23
+ #
24
+ # Creates the `ronin_http_header_names` table.
25
+ #
22
26
  class CreateRoninHttpHeaderNamesTable < ActiveRecord::Migration[7.0]
23
27
 
24
28
  def change
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
3
4
  #
@@ -19,6 +20,9 @@
19
20
  # along with ronin-db-activerecord. If not, see <https://www.gnu.org/licenses/>.
20
21
  #
21
22
 
23
+ #
24
+ # Creates the `ronin_http_request_headers` table.
25
+ #
22
26
  class CreateRoninHttpRequestHeadersTable < ActiveRecord::Migration[7.0]
23
27
 
24
28
  def change
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
3
4
  #
@@ -19,6 +20,9 @@
19
20
  # along with ronin-db-activerecord. If not, see <https://www.gnu.org/licenses/>.
20
21
  #
21
22
 
23
+ #
24
+ # Creates the `ronin_http_response_headers` table.
25
+ #
22
26
  class CreateRoninHttpResponseHeadersTable < ActiveRecord::Migration[7.0]
23
27
 
24
28
  def change
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
3
4
  #
@@ -19,6 +20,9 @@
19
20
  # along with ronin-db-activerecord. If not, see <https://www.gnu.org/licenses/>.
20
21
  #
21
22
 
23
+ #
24
+ # Creates the `ronin_service_credentials` table.
25
+ #
22
26
  class CreateRoninServiceCredentialsTable < ActiveRecord::Migration[7.0]
23
27
 
24
28
  def change
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
3
4
  #
@@ -19,6 +20,9 @@
19
20
  # along with ronin-db-activerecord. If not, see <https://www.gnu.org/licenses/>.
20
21
  #
21
22
 
23
+ #
24
+ # Creates the `ronin_web_credentials` table.
25
+ #
22
26
  class CreateRoninWebCredentialsTable < ActiveRecord::Migration[7.0]
23
27
 
24
28
  def change
data/gemspec.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  name: ronin-db-activerecord
2
- version: 0.1.0
2
+ version: 0.1.2
3
3
  summary: ActiveRecord backend for the Ronin Database
4
4
  description:
5
5
  ronin-db-activerecord contains ActiveRecord models and migrations for the
@@ -58,7 +58,7 @@ module Ronin
58
58
  # Tracks when the IP Address was first created
59
59
  #
60
60
  # @return [Time]
61
- attribute :created_at, :time
61
+ attribute :created_at, :datetime
62
62
 
63
63
  #
64
64
  # Looks up the address.
@@ -69,6 +69,8 @@ module Ronin
69
69
  # @return [Address, nil]
70
70
  # The found address.
71
71
  #
72
+ # @api public
73
+ #
72
74
  def self.lookup(address)
73
75
  find_by(address: address)
74
76
  end
@@ -80,7 +82,7 @@ module Ronin
80
82
  # The address to parse.
81
83
  #
82
84
  # @return [Address]
83
- # The parsed address.
85
+ # The imported address.
84
86
  #
85
87
  # @api public
86
88
  #
@@ -56,9 +56,9 @@ module Ronin
56
56
  attribute :year, :integer
57
57
  validates :year, allow_nil: true,
58
58
  comparison: {
59
- greater_than: 1990,
60
- less_than_or_equal_to: Date.today.year
61
- }
59
+ greater_than: 1990,
60
+ less_than_or_equal_to: Date.today.year
61
+ }
62
62
 
63
63
  # @!attribute [rw] identifier
64
64
  # The advisory identifier
@@ -84,7 +84,7 @@ module Ronin
84
84
  # The ID does not appear to be a valid security ID.
85
85
  #
86
86
  def self.parse(string)
87
- if (match = string.match(/\A([A-Z]+)-(\d{4})[:-]([0-9][0-9-]+)\z/))
87
+ if (match = string.match(/\A([A-Z]+)-(\d{4})[:-]([0-9][0-9-]+)\z/))
88
88
  {
89
89
  id: match[0],
90
90
  prefix: match[1],
data/lib/ronin/db/asn.rb CHANGED
@@ -82,13 +82,13 @@ module Ronin
82
82
  # @!attribute [rw] country_code
83
83
  # The country code of the ASN.
84
84
  #
85
- # @return [String]
85
+ # @return [String, nil]
86
86
  attribute :country_code, :string
87
87
 
88
88
  # @!attribute [rw] name
89
89
  # The organization the ASN is currently assigned to.
90
90
  #
91
- # @return [String]
91
+ # @return [String, nil]
92
92
  attribute :name, :string
93
93
 
94
94
  #
@@ -142,7 +142,7 @@ module Ronin
142
142
  #
143
143
  # Searches for all ASNs with the matching name.
144
144
  #
145
- # @param [String] name
145
+ # @param [String] name
146
146
  # The name to search for.
147
147
  #
148
148
  # @return [Array<ASN>]
@@ -159,11 +159,11 @@ module Ronin
159
159
  # @return [ASN, nil]
160
160
  #
161
161
  def self.containing_ip(ip)
162
- ip = IPAddr.new(ip) unless ip.kind_of?(IPAddr)
162
+ ip = IPAddr.new(ip) unless ip.kind_of?(IPAddr)
163
163
  ip_hton = ip.hton
164
164
 
165
165
  range_start_hton = self.arel_table[:range_start_hton]
166
- range_end_hton = self.arel_table[:range_end_hton]
166
+ range_end_hton = self.arel_table[:range_end_hton]
167
167
 
168
168
  where(range_start_hton.lteq(ip_hton).and(range_end_hton.gteq(ip_hton))).first
169
169
  end
@@ -84,7 +84,7 @@ module Ronin
84
84
  # Tracks when the email address was created at.
85
85
  #
86
86
  # @return [Time]
87
- attribute :created_at, :time
87
+ attribute :created_at, :datetime
88
88
 
89
89
  #
90
90
  # Searches for email addresses associated with the given host name(s).
@@ -60,7 +60,7 @@ module Ronin
60
60
  # When the host name was first created.
61
61
  #
62
62
  # @return [Time]
63
- attribute :created_at, :time
63
+ attribute :created_at, :datetime
64
64
 
65
65
  # @!attribute [rw] host_name_ip_addresses
66
66
  # The IP Address associations.
@@ -58,7 +58,7 @@ module Ronin
58
58
  # Tracks when a IP Address is associated with a host name
59
59
  #
60
60
  # @return [Time]
61
- attribute :created_at, :time
61
+ attribute :created_at, :datetime
62
62
 
63
63
  end
64
64
  end
@@ -57,7 +57,7 @@ module Ronin
57
57
  # When the HTTP query param name was first created.
58
58
  #
59
59
  # @return [Time]
60
- attribute :created_at, :time
60
+ attribute :created_at, :datetime
61
61
 
62
62
  #
63
63
  # Converts the HTTP query param name to a String.
@@ -113,7 +113,7 @@ module Ronin
113
113
  # When the HTTP request was created.
114
114
  #
115
115
  # @return [Time]
116
- attribute :created_at, :time
116
+ attribute :created_at, :datetime
117
117
 
118
118
  end
119
119
  end
@@ -74,7 +74,7 @@ module Ronin
74
74
  # When the HTTP response was created.
75
75
  #
76
76
  # @return [Time]
77
- attribute :created_at, :time
77
+ attribute :created_at, :datetime
78
78
 
79
79
  # @!attribute [rw] request
80
80
  # The associated HTTP request that the response was returned for.
@@ -262,6 +262,7 @@ module Ronin
262
262
  begin
263
263
  IPAddr.new(self.address)
264
264
  rescue IPAddr::InvalidAddressError
265
+ nil
265
266
  end
266
267
  end
267
268
  end
@@ -345,7 +346,6 @@ require 'ronin/db/host_name_ip_address'
345
346
  require 'ronin/db/host_name'
346
347
  require 'ronin/db/open_port'
347
348
  require 'ronin/db/port'
348
- require 'ronin/db/host_name'
349
349
  require 'ronin/db/os_guess'
350
350
  require 'ronin/db/os'
351
351
  require 'ronin/db/asn'
@@ -55,7 +55,7 @@ module Ronin
55
55
  # Tracks when an IP Address becomes associated with a MAC Address.
56
56
  #
57
57
  # @return [Time]
58
- attribute :created_at, :time
58
+ attribute :created_at, :datetime
59
59
 
60
60
  end
61
61
  end
@@ -34,12 +34,12 @@ module Ronin
34
34
  # The MAC address.
35
35
  #
36
36
  # @return [String]
37
- attribute :address, :string # length: 17..17,
37
+ attribute :address, :string
38
38
  validates :address, presence: true,
39
39
  uniqueness: true,
40
40
  length: {maximum: 17},
41
41
  format: {
42
- with: /[0-9a-fA-F]{2}(?::[0-9a-fA-F]{2}){5}/,
42
+ with: /\A[0-9a-fA-F]{2}(?::[0-9a-fA-F]{2}){5}\z/,
43
43
  message: 'Must be a valid MAC address'
44
44
  }
45
45
 
@@ -78,8 +78,8 @@ module Ronin
78
78
  # @api public
79
79
  #
80
80
  def to_i
81
- self.address.split(':').inject(0) do |bits,char|
82
- bits = ((bits << 8) | char.hex)
81
+ self.address.split(':').reduce(0) do |bits,char|
82
+ ((bits << 8) | char.hex)
83
83
  end
84
84
  end
85
85
 
@@ -25,6 +25,9 @@ require 'active_record/migration'
25
25
 
26
26
  module Ronin
27
27
  module DB
28
+ #
29
+ # Handles migrating the database.
30
+ #
28
31
  module Migrations
29
32
  #
30
33
  # The current migration version of the database.
@@ -56,7 +59,7 @@ module Ronin
56
59
  context.migrate(target_version)
57
60
  end
58
61
 
59
- #
62
+ #
60
63
  # Explicitly migrates up the database to the target version.
61
64
  #
62
65
  # @param [Integer, nil] target_version
@@ -68,9 +71,9 @@ module Ronin
68
71
  context.up(target_version,&block)
69
72
  end
70
73
 
71
- #
74
+ #
72
75
  # Explicitly migrates down the database to the target version.
73
- #
76
+ #
74
77
  # @param [Integer, nil] target_version
75
78
  # The desired target version.
76
79
  #
@@ -80,7 +83,7 @@ module Ronin
80
83
  context.down(target_version,&block)
81
84
  end
82
85
 
83
- #
86
+ #
84
87
  # Rollbacks the last number of migrations.
85
88
  #
86
89
  # @param [Integer] steps
@@ -92,7 +95,7 @@ module Ronin
92
95
  context.rollback(steps)
93
96
  end
94
97
 
95
- #
98
+ #
96
99
  # Applies the next number of migrations.
97
100
  #
98
101
  # @param [Integer] steps
@@ -104,8 +107,6 @@ module Ronin
104
107
  context.foreward(steps)
105
108
  end
106
109
 
107
- private
108
-
109
110
  # Path to the `db/migrate/` directory in `ronin-db-activerecord`.
110
111
  DIR = File.expand_path('../../../db/migrate',__dir__)
111
112
 
@@ -129,8 +130,10 @@ module Ronin
129
130
  #
130
131
  # @return [MigrationContext]
131
132
  #
133
+ # @api private
134
+ #
132
135
  def self.context
133
- @migrations ||= MigrationContext.new
136
+ @context ||= MigrationContext.new
134
137
  end
135
138
  end
136
139
  end
@@ -44,11 +44,9 @@ module Ronin
44
44
  # @api semipublic
45
45
  #
46
46
  def self.included(base)
47
- base.send :include, Model,
48
- HasName::InstanceMethods
47
+ base.send :include, Model, HasName::InstanceMethods
49
48
 
50
- base.send :extend, HasName::ClassMethods,
51
- HasUniqueName::ClassMethods
49
+ base.send :extend, HasName::ClassMethods, HasUniqueName::ClassMethods
52
50
 
53
51
  base.module_eval do
54
52
  # The name of the model
@@ -37,6 +37,9 @@ module Ronin
37
37
  model.extend ClassMethods
38
38
  end
39
39
 
40
+ #
41
+ # Class-methods which will be added to the model.
42
+ #
40
43
  module ClassMethods
41
44
  #
42
45
  # Looks up a record with the given value.
@@ -21,6 +21,9 @@
21
21
  module Ronin
22
22
  module DB
23
23
  module Model
24
+ #
25
+ # Mixin which adds a `last_scanned_at` attribute to a model.
26
+ #
24
27
  module LastScannedAt
25
28
  #
26
29
  # @!attribute [rw] last_scanned_at
@@ -39,7 +42,7 @@ module Ronin
39
42
  #
40
43
  def self.included(model)
41
44
  model.class_eval do
42
- attribute :last_scanned_at, :time
45
+ attribute :last_scanned_at, :datetime
43
46
  end
44
47
  end
45
48
  end
@@ -20,6 +20,9 @@
20
20
 
21
21
  module Ronin
22
22
  module DB
23
+ #
24
+ # Mixin for all `ronin-db-activerecord` models.
25
+ #
23
26
  module Model
24
27
  #
25
28
  # Sets the models `table_name_prefix` to `ronin_`.
@@ -56,6 +56,9 @@ require 'ronin/db/vulnerability'
56
56
 
57
57
  module Ronin
58
58
  module DB
59
+ #
60
+ # Manages all models defined in `ronin-db-activerecord`.
61
+ #
59
62
  module Models
60
63
  ALL = [
61
64
  Address,
@@ -74,7 +74,7 @@ module Ronin
74
74
  # Define the created_at timestamp
75
75
  #
76
76
  # @return [Time]
77
- attribute :created_at, :time
77
+ attribute :created_at, :datetime
78
78
 
79
79
  # @!attribute [rw] service_credentials
80
80
  # Credentials used by the service running on the port
@@ -43,7 +43,7 @@ module Ronin
43
43
  # Tracks when the organization was first created
44
44
  #
45
45
  # @return [Time]
46
- attribute :created_at, :time
46
+ attribute :created_at, :datetime
47
47
 
48
48
  end
49
49
  end
data/lib/ronin/db/os.rb CHANGED
@@ -51,14 +51,14 @@ module Ronin
51
51
  #
52
52
  # @return [String]
53
53
  attribute :version, :string
54
- validates :version, presence: true,
54
+ validates :version, presence: true,
55
55
  uniqueness: {scope: :name}
56
56
 
57
57
  # @!attribute [rw] os_guesses
58
58
  # Any OS guesses for the Operating System.
59
59
  #
60
60
  # @return [Array<OSGuess>]
61
- has_many :os_guesses, dependent: :destroy,
61
+ has_many :os_guesses, dependent: :destroy,
62
62
  class_name: 'OSGuess'
63
63
 
64
64
  # @!attribute [rw] ip_addresses
@@ -57,7 +57,7 @@ module Ronin
57
57
  # Tracks when an OS guess is made against an IP Address.
58
58
  #
59
59
  # @return [Time]
60
- attribute :created_at, :time
60
+ attribute :created_at, :datetime
61
61
 
62
62
  end
63
63
  end
@@ -109,13 +109,13 @@ module Ronin
109
109
  #
110
110
  # @example
111
111
  # pass = Password.new(plain_text: 'secret')
112
- #
112
+ #
113
113
  # pass.digest(:sha1)
114
114
  # # => "e5e9fa1ba31ecd1ae84f75caaa474f3a663f05f4"
115
- #
115
+ #
116
116
  # pass.digest(:sha1, prepend_salt: "A\x90\x00")
117
117
  # # => "e2817656a48c49f24839ccf9295b389d8f985904"
118
- #
118
+ #
119
119
  # pass.digest(:sha1, append_salt: "BBBB")
120
120
  # # => "aa6ca21e446d425fc044bbb26e950a788444a5b8"
121
121
  #
@@ -49,14 +49,14 @@ module Ronin
49
49
  #
50
50
  # @return [String]
51
51
  attribute :version, :string
52
- validates :version, presence: true,
52
+ validates :version, presence: true,
53
53
  uniqueness: {scope: :name}
54
54
 
55
55
  # @!attribute [rw] vendor
56
56
  # The vendor of the software
57
57
  #
58
58
  # @return [SoftwareVendor, nil]
59
- belongs_to :vendor, optional: true,
59
+ belongs_to :vendor, optional: true,
60
60
  class_name: 'SoftwareVendor'
61
61
 
62
62
  # @!attribute [rw] open_ports
data/lib/ronin/db/url.rb CHANGED
@@ -87,7 +87,7 @@ module Ronin
87
87
 
88
88
  # @!attribute [rw] fragment
89
89
  # The fragment of the URL.
90
- #
90
+ #
91
91
  # @return [String, nil]
92
92
  attribute :fragment, :string
93
93
 
@@ -95,7 +95,7 @@ module Ronin
95
95
  # Defines the created_at timestamp
96
96
  #
97
97
  # @return [Time]
98
- attribute :created_at, :time
98
+ attribute :created_at, :datetime
99
99
 
100
100
  # @!attribute [rw] query_params
101
101
  # The query params of the URL.
@@ -362,33 +362,30 @@ module Ronin
362
362
  number: uri.port
363
363
  )
364
364
  end
365
+ path = normalized_path(uri)
366
+ query = uri.query
367
+ fragment = uri.fragment
365
368
 
366
- path = normalized_path(uri)
367
- query = uri.query
368
- fragment = uri.fragment
369
-
370
- query_params = []
371
-
372
- if uri.respond_to?(:query_params)
373
- # find or create the URL query params
374
- uri.query_params.each do |name,value|
375
- query_params << URLQueryParam.new(
376
- name: URLQueryParamName.find_or_create_by(name: name),
377
- value: value
378
- )
379
- end
380
- end
381
-
382
- # find or create the URL
369
+ # try to query a pre-existing URI then fallback to creating the URL
370
+ # with query params.
383
371
  return find_or_create_by(
384
372
  scheme: scheme,
385
373
  host_name: host_name,
386
374
  port: port,
387
375
  path: path,
388
376
  query: query,
389
- fragment: fragment,
390
- query_params: query_params
391
- )
377
+ fragment: fragment
378
+ ) do |new_url|
379
+ if uri.respond_to?(:query_params)
380
+ # find or create the URL query params
381
+ uri.query_params.each do |name,value|
382
+ new_url.query_params << URLQueryParam.new(
383
+ name: URLQueryParamName.find_or_create_by(name: name),
384
+ value: value
385
+ )
386
+ end
387
+ end
388
+ end
392
389
  end
393
390
 
394
391
  #
@@ -430,9 +427,11 @@ module Ronin
430
427
  scheme = if self.scheme
431
428
  self.scheme.name
432
429
  end
430
+
433
431
  host = if self.host_name
434
432
  self.host_name.name
435
433
  end
434
+
436
435
  port = if self.port
437
436
  self.port.number
438
437
  end
@@ -460,8 +459,6 @@ module Ronin
460
459
  self.to_uri.to_s
461
460
  end
462
461
 
463
- protected
464
-
465
462
  #
466
463
  # Normalizes the path of a URI.
467
464
  #
@@ -57,7 +57,7 @@ module Ronin
57
57
  # When the URL query param name was first created.
58
58
  #
59
59
  # @return [Time]
60
- attribute :created_at, :time
60
+ attribute :created_at, :datetime
61
61
 
62
62
  #
63
63
  # Converts the URL query param name to a String.
@@ -34,7 +34,7 @@ module Ronin
34
34
  include Model::HasUniqueName
35
35
 
36
36
  self.table_name = 'ronin_url_schemes'
37
-
37
+
38
38
  # @!attribute [rw] id
39
39
  # The primary key of the URL scheme.
40
40
  #
@@ -48,7 +48,7 @@ module Ronin
48
48
  # Tracks when the user-name was created.
49
49
  #
50
50
  # @return [Time]
51
- attribute :created_at, :time
51
+ attribute :created_at, :datetime
52
52
 
53
53
  # @!attribute [rw] credentials
54
54
  # Any credentials belonging to the user.