ronin-db-activerecord 0.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.github/workflows/ruby.yml +31 -0
  4. data/.gitignore +13 -0
  5. data/.rspec +1 -0
  6. data/.ruby-version +1 -0
  7. data/.yardopts +1 -0
  8. data/COPYING.txt +165 -0
  9. data/ChangeLog.md +39 -0
  10. data/Gemfile +27 -0
  11. data/README.md +143 -0
  12. data/Rakefile +72 -0
  13. data/db/migrate/0001_create_ronin_ip_address_mac_addresses_table.rb +43 -0
  14. data/db/migrate/0002_create_ronin_vulnerabilities_table.rb +61 -0
  15. data/db/migrate/0003_create_ronin_url_schemes_table.rb +32 -0
  16. data/db/migrate/0004_create_ronin_url_query_param_names_table.rb +32 -0
  17. data/db/migrate/0005_create_ronin_user_names_table.rb +33 -0
  18. data/db/migrate/0006_create_ronin_software_vendors_table.rb +32 -0
  19. data/db/migrate/0007_create_ronin_advisories_table.rb +42 -0
  20. data/db/migrate/0008_create_ronin_host_name_ip_addresses_table.rb +43 -0
  21. data/db/migrate/0009_create_ronin_host_names_table.rb +34 -0
  22. data/db/migrate/0010_create_ronin_arches_table.rb +37 -0
  23. data/db/migrate/0011_create_ronin_email_addresses_table.rb +44 -0
  24. data/db/migrate/0012_create_ronin_oses_table.rb +36 -0
  25. data/db/migrate/0013_create_ronin_organizations_table.rb +31 -0
  26. data/db/migrate/0014_create_ronin_ip_addresses_table.rb +35 -0
  27. data/db/migrate/0015_create_ronin_os_guesses_table.rb +40 -0
  28. data/db/migrate/0016_create_ronin_url_query_params_table.rb +42 -0
  29. data/db/migrate/0017_create_ronin_passwords_table.rb +32 -0
  30. data/db/migrate/0018_create_ronin_open_ports_table.rb +46 -0
  31. data/db/migrate/0019_create_ronin_urls_table.rb +50 -0
  32. data/db/migrate/0020_create_ronin_softwares_table.rb +39 -0
  33. data/db/migrate/0021_create_ronin_mac_addresses_table.rb +33 -0
  34. data/db/migrate/0022_create_ronin_countries_table.rb +34 -0
  35. data/db/migrate/0023_create_ronin_services_table.rb +32 -0
  36. data/db/migrate/0024_create_ronin_credentials_table.rb +44 -0
  37. data/db/migrate/0025_create_ronin_ports_table.rb +33 -0
  38. data/db/migrate/0026_create_ronin_asns_table.rb +44 -0
  39. data/db/migrate/0027_create_ronin_http_query_param_names_table.rb +32 -0
  40. data/db/migrate/0028_create_ronin_http_query_params_table.rb +42 -0
  41. data/db/migrate/0029_create_ronin_http_header_names_table.rb +31 -0
  42. data/db/migrate/0030_create_ronin_http_request_headers_table.rb +41 -0
  43. data/db/migrate/0031_create_ronin_http_response_headers_table.rb +41 -0
  44. data/db/migrate/0032_create_ronin_http_requests_table.rb +41 -0
  45. data/db/migrate/0033_create_ronin_http_responses_table.rb +36 -0
  46. data/db/migrate/0034_create_ronin_service_credentials_table.rb +41 -0
  47. data/db/migrate/0035_create_ronin_web_credentials_table.rb +41 -0
  48. data/gemspec.yml +28 -0
  49. data/lib/ronin/db/address.rb +105 -0
  50. data/lib/ronin/db/advisory.rb +169 -0
  51. data/lib/ronin/db/arch.rb +160 -0
  52. data/lib/ronin/db/asn.rb +212 -0
  53. data/lib/ronin/db/credential.rb +248 -0
  54. data/lib/ronin/db/email_address.rb +225 -0
  55. data/lib/ronin/db/host_name.rb +224 -0
  56. data/lib/ronin/db/host_name_ip_address.rb +65 -0
  57. data/lib/ronin/db/http_header_name.rb +75 -0
  58. data/lib/ronin/db/http_query_param.rb +79 -0
  59. data/lib/ronin/db/http_query_param_name.rb +76 -0
  60. data/lib/ronin/db/http_request.rb +120 -0
  61. data/lib/ronin/db/http_request_header.rb +78 -0
  62. data/lib/ronin/db/http_response.rb +91 -0
  63. data/lib/ronin/db/http_response_header.rb +78 -0
  64. data/lib/ronin/db/ip_address.rb +351 -0
  65. data/lib/ronin/db/ip_address_mac_address.rb +62 -0
  66. data/lib/ronin/db/mac_address.rb +91 -0
  67. data/lib/ronin/db/migrations.rb +137 -0
  68. data/lib/ronin/db/model/has_name.rb +102 -0
  69. data/lib/ronin/db/model/has_unique_name.rb +82 -0
  70. data/lib/ronin/db/model/importable.rb +85 -0
  71. data/lib/ronin/db/model/last_scanned_at.rb +48 -0
  72. data/lib/ronin/db/model.rb +37 -0
  73. data/lib/ronin/db/models.rb +108 -0
  74. data/lib/ronin/db/open_port.rb +148 -0
  75. data/lib/ronin/db/organization.rb +50 -0
  76. data/lib/ronin/db/os.rb +183 -0
  77. data/lib/ronin/db/os_guess.rb +67 -0
  78. data/lib/ronin/db/password.rb +167 -0
  79. data/lib/ronin/db/port.rb +123 -0
  80. data/lib/ronin/db/root.rb +28 -0
  81. data/lib/ronin/db/schema_migration.rb +34 -0
  82. data/lib/ronin/db/service.rb +48 -0
  83. data/lib/ronin/db/service_credential.rb +66 -0
  84. data/lib/ronin/db/software.rb +85 -0
  85. data/lib/ronin/db/software_vendor.rb +42 -0
  86. data/lib/ronin/db/url.rb +497 -0
  87. data/lib/ronin/db/url_query_param.rb +79 -0
  88. data/lib/ronin/db/url_query_param_name.rb +76 -0
  89. data/lib/ronin/db/url_scheme.rb +80 -0
  90. data/lib/ronin/db/user_name.rb +96 -0
  91. data/lib/ronin/db/vulnerability.rb +81 -0
  92. data/lib/ronin/db/web_credential.rb +69 -0
  93. data/ronin-db-activerecord.gemspec +61 -0
  94. data/spec/advisory_spec.rb +277 -0
  95. data/spec/arch_spec.rb +228 -0
  96. data/spec/asn_spec.rb +504 -0
  97. data/spec/credential_spec.rb +362 -0
  98. data/spec/email_address_spec.rb +372 -0
  99. data/spec/host_name_ip_address_spec.rb +8 -0
  100. data/spec/host_name_spec.rb +207 -0
  101. data/spec/http_header_name_spec.rb +25 -0
  102. data/spec/http_query_param_name_spec.rb +25 -0
  103. data/spec/http_query_param_spec.rb +104 -0
  104. data/spec/http_request_header_spec.rb +72 -0
  105. data/spec/http_request_spec.rb +168 -0
  106. data/spec/http_response_header_spec.rb +74 -0
  107. data/spec/http_response_spec.rb +103 -0
  108. data/spec/ip_address_mac_addresses_spec.rb +8 -0
  109. data/spec/ip_address_spec.rb +386 -0
  110. data/spec/mac_address_spec.rb +67 -0
  111. data/spec/migrations_spec.rb +122 -0
  112. data/spec/model/has_name_spec.rb +65 -0
  113. data/spec/model/has_unique_name_spec.rb +61 -0
  114. data/spec/model/importable_spec.rb +105 -0
  115. data/spec/models_spec.rb +60 -0
  116. data/spec/open_port_spec.rb +87 -0
  117. data/spec/organization_spec.rb +10 -0
  118. data/spec/os_guess_spec.rb +43 -0
  119. data/spec/os_spec.rb +114 -0
  120. data/spec/password_spec.rb +81 -0
  121. data/spec/port_spec.rb +102 -0
  122. data/spec/schema_migration_spec.rb +8 -0
  123. data/spec/service_credential_spec.rb +43 -0
  124. data/spec/service_spec.rb +39 -0
  125. data/spec/software_spec.rb +76 -0
  126. data/spec/software_vendor_spec.rb +33 -0
  127. data/spec/spec_helper.rb +13 -0
  128. data/spec/url_query_param_name_spec.rb +25 -0
  129. data/spec/url_query_param_spec.rb +110 -0
  130. data/spec/url_scheme_spec.rb +39 -0
  131. data/spec/url_spec.rb +951 -0
  132. data/spec/user_name_spec.rb +54 -0
  133. data/spec/vulnerability_spec.rb +8 -0
  134. data/spec/web_credential_spec.rb +72 -0
  135. metadata +266 -0
@@ -0,0 +1,183 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
4
+ #
5
+ # Copyright (c) 2022 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # ronin-db-activerecord is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-db-activerecord is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-db-activerecord. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/db/model'
22
+ require 'ronin/db/model/has_name'
23
+
24
+ module Ronin
25
+ module DB
26
+ #
27
+ # Represents an Operating System and pre-defines other common ones
28
+ # ({linux}, {freebsd}, {openbsd}, {netbsd}, {macos}, and {windows}.
29
+ #
30
+ class OS < ActiveRecord::Base
31
+
32
+ include Model
33
+ include Model::HasName
34
+
35
+ self.table_name = 'ronin_oses'
36
+
37
+ # @!attribute [rw] id
38
+ # The primary key of the OS.
39
+ #
40
+ # @return [Integer]
41
+ attribute :id, :integer
42
+
43
+ # @!attribute [rw] flavor
44
+ # The flavor of the OS (Linux, BSD).
45
+ #
46
+ # @return [:linux, :bsd]
47
+ enum :flavor, {linux: 'Linux', bsd: 'BSD'}
48
+
49
+ # @!attribute [rw] version
50
+ # The version of the Operating System.
51
+ #
52
+ # @return [String]
53
+ attribute :version, :string
54
+ validates :version, presence: true,
55
+ uniqueness: {scope: :name}
56
+
57
+ # @!attribute [rw] os_guesses
58
+ # Any OS guesses for the Operating System.
59
+ #
60
+ # @return [Array<OSGuess>]
61
+ has_many :os_guesses, dependent: :destroy,
62
+ class_name: 'OSGuess'
63
+
64
+ # @!attribute [rw] ip_addresses
65
+ # Any IP Addresses that might be running the Operating System
66
+ #
67
+ # @return [Array<IPAddress>]
68
+ has_many :ip_addresses, through: :os_guesses,
69
+ class_name: 'IPAddress'
70
+
71
+ #
72
+ # The Linux OS
73
+ #
74
+ # @param [String] version
75
+ # Optional version of the OS.
76
+ #
77
+ # @return [OS]
78
+ #
79
+ def self.linux(version)
80
+ find_or_create_by(name: 'Linux', flavor: :linux, version: version)
81
+ end
82
+
83
+ #
84
+ # The FreeBSD OS
85
+ #
86
+ # @param [String] version
87
+ # Optional version of the OS.
88
+ #
89
+ # @return [OS]
90
+ #
91
+ def self.freebsd(version)
92
+ find_or_create_by(name: 'FreeBSD', flavor: :bsd, version: version)
93
+ end
94
+
95
+ #
96
+ # The OpenBSD OS
97
+ #
98
+ # @param [String] version
99
+ # Optional version of the OS.
100
+ #
101
+ # @return [OS]
102
+ #
103
+ def self.openbsd(version)
104
+ find_or_create_by(name: 'OpenBSD', flavor: :bsd, version: version)
105
+ end
106
+
107
+ #
108
+ # The NetBSD OS
109
+ #
110
+ # @param [String] version
111
+ # Optional version of the OS.
112
+ #
113
+ # @return [OS]
114
+ #
115
+ def self.netbsd(version)
116
+ find_or_create_by(name: 'NetBSD', flavor: :bsd, version: version)
117
+ end
118
+
119
+ #
120
+ # The macOS OS.
121
+ #
122
+ # @param [String] version
123
+ # Optional version of the OS.
124
+ #
125
+ # @return [OS]
126
+ #
127
+ def self.macos(version)
128
+ find_or_create_by(name: 'macOS', flavor: :bsd, version: version)
129
+ end
130
+
131
+ #
132
+ # The Windows OS
133
+ #
134
+ # @param [String] version
135
+ # Optional version of the OS.
136
+ #
137
+ # @return [OS]
138
+ #
139
+ def self.windows(version)
140
+ find_or_create_by(name: 'Windows', version: version)
141
+ end
142
+
143
+ #
144
+ # The IP Address that was most recently guessed to be using the
145
+ # Operating System.
146
+ #
147
+ # @return [IPAddress]
148
+ # The IP Address most recently guessed to be using the
149
+ # Operating System.
150
+ #
151
+ # @api public
152
+ #
153
+ def recent_ip_address
154
+ relation = self.os_guesses.order('created_at DESC').first
155
+
156
+ if relation
157
+ return relation.ip_address
158
+ end
159
+ end
160
+
161
+ #
162
+ # Converts the Operating System to a String.
163
+ #
164
+ # @return [String]
165
+ # The OS name and version.
166
+ #
167
+ # @example
168
+ # os = OS.new(name: 'Linux', version: '2.6.11')
169
+ # os.to_s
170
+ # # => "Linux 2.6.11"
171
+ #
172
+ # @api public
173
+ #
174
+ def to_s
175
+ "#{self.name} #{self.version}"
176
+ end
177
+
178
+ end
179
+ end
180
+ end
181
+
182
+ require 'ronin/db/os_guess'
183
+ require 'ronin/db/ip_address'
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
4
+ #
5
+ # Copyright (c) 2022 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # ronin-db-activerecord is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-db-activerecord is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-db-activerecord. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/db/model'
22
+
23
+ require 'active_record'
24
+
25
+ module Ronin
26
+ module DB
27
+ #
28
+ # Represents a guess about what {OS} an {IPAddress} might be running.
29
+ #
30
+ class OSGuess < ActiveRecord::Base
31
+
32
+ include Model
33
+
34
+ self.table_name = 'ronin_os_guesses'
35
+
36
+ # @!attribute [rw] id
37
+ # The primary-key of the OS guess.
38
+ #
39
+ # @return [Integer]
40
+ attribute :id, :integer
41
+
42
+ # @!attribute [rw] ip_address
43
+ # The IP Address the OS guess was made against.
44
+ #
45
+ # @return [IPAddress]
46
+ belongs_to :ip_address, required: true,
47
+ class_name: 'IPAddress'
48
+
49
+ # @!attribute [rw] os
50
+ # The guessed OS.
51
+ #
52
+ # @return [OS]
53
+ belongs_to :os, required: true,
54
+ class_name: 'OS'
55
+
56
+ # @!attribute [r] created_at
57
+ # Tracks when an OS guess is made against an IP Address.
58
+ #
59
+ # @return [Time]
60
+ attribute :created_at, :time
61
+
62
+ end
63
+ end
64
+ end
65
+
66
+ require 'ronin/db/ip_address'
67
+ require 'ronin/db/os'
@@ -0,0 +1,167 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
4
+ #
5
+ # Copyright (c) 2022 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # ronin-db-activerecord is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-db-activerecord is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-db-activerecord. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/db/model'
22
+ require 'ronin/db/model/importable'
23
+
24
+ require 'active_record'
25
+ require 'digest'
26
+
27
+ module Ronin
28
+ module DB
29
+ #
30
+ # Represents a password used by {Service services} or {URL websites}.
31
+ #
32
+ class Password < ActiveRecord::Base
33
+
34
+ include Model
35
+ include Model::Importable
36
+
37
+ # @!attribute [rw] id
38
+ # The primary key of the password.
39
+ #
40
+ # @return [Integer]
41
+ attribute :id, :integer
42
+
43
+ # @!attribute [rw] plain_text
44
+ # The clear-text of the password.
45
+ #
46
+ # @return [String]
47
+ attribute :plain_text, :string # length: 256,
48
+ validates :plain_text, presence: true, uniqueness: true
49
+
50
+ # @!attribute [rw] credentials
51
+ # The credentials which use the password.
52
+ #
53
+ # @return [Array<Credential>]
54
+ has_many :credentials, dependent: :destroy
55
+
56
+ # @!attribute [rw] user_names
57
+ # The user names which use the password.
58
+ #
59
+ # @return [Array<UserName>]
60
+ has_many :user_names, through: :credentials
61
+
62
+ #
63
+ # Looks up the password.
64
+ #
65
+ # @param [#to_s] password
66
+ # The password to lookup.
67
+ #
68
+ # @return [Password, nil]
69
+ # The found password.
70
+ #
71
+ # @api public
72
+ #
73
+ def self.lookup(password)
74
+ find_by(plain_text: password.to_s)
75
+ end
76
+
77
+ #
78
+ # Parses a password.
79
+ #
80
+ # @param [#to_s] password
81
+ # The password to import.
82
+ #
83
+ # @return [Password]
84
+ # The imported password.
85
+ #
86
+ # @api public
87
+ #
88
+ def self.import(password)
89
+ create(plain_text: password.to_s)
90
+ end
91
+
92
+ #
93
+ # Hashes the password.
94
+ #
95
+ # @param [Symbol, String] algorithm
96
+ # The digest algorithm to use.
97
+ #
98
+ # @param [String, nil] prepend_salt
99
+ # The salt data to prepend to the password.
100
+ #
101
+ # @param [String, nil] append_salt
102
+ # The salt data to append to the password.
103
+ #
104
+ # @return [String]
105
+ # The hex-digest of the hashed password.
106
+ #
107
+ # @raise [ArgumentError]
108
+ # Unknown Digest algorithm.
109
+ #
110
+ # @example
111
+ # pass = Password.new(plain_text: 'secret')
112
+ #
113
+ # pass.digest(:sha1)
114
+ # # => "e5e9fa1ba31ecd1ae84f75caaa474f3a663f05f4"
115
+ #
116
+ # pass.digest(:sha1, prepend_salt: "A\x90\x00")
117
+ # # => "e2817656a48c49f24839ccf9295b389d8f985904"
118
+ #
119
+ # pass.digest(:sha1, append_salt: "BBBB")
120
+ # # => "aa6ca21e446d425fc044bbb26e950a788444a5b8"
121
+ #
122
+ # @api public
123
+ #
124
+ def digest(algorithm, prepend_salt: nil, append_salt: nil)
125
+ digest_class = begin
126
+ Digest.const_get(algorithm.upcase)
127
+ rescue LoadError
128
+ raise(ArgumentError,"Unknown Digest algorithm #{algorithm}")
129
+ end
130
+
131
+ hash = digest_class.new
132
+ hash << prepend_salt.to_s if prepend_salt
133
+ hash << self.plain_text
134
+ hash << append_salt.to_s if append_salt
135
+
136
+ return hash.hexdigest
137
+ end
138
+
139
+ #
140
+ # The number of credentials which use this password.
141
+ #
142
+ # @return [Integer]
143
+ # The number of credentials that use the password.
144
+ #
145
+ # @api public
146
+ #
147
+ def count
148
+ self.credentials.count
149
+ end
150
+
151
+ #
152
+ # Converts the password into a String.
153
+ #
154
+ # @return [String]
155
+ # The clear-text of the password.
156
+ #
157
+ # @api public
158
+ #
159
+ def to_s
160
+ self.plain_text
161
+ end
162
+
163
+ end
164
+ end
165
+ end
166
+
167
+ require 'ronin/db/credential'
@@ -0,0 +1,123 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
4
+ #
5
+ # Copyright (c) 2022 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # ronin-db-activerecord is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-db-activerecord is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-db-activerecord. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/db/model'
22
+
23
+ require 'active_record'
24
+
25
+ module Ronin
26
+ module DB
27
+ #
28
+ # Represents a TCP or UDP port.
29
+ #
30
+ class Port < ActiveRecord::Base
31
+
32
+ include Model
33
+
34
+ # @!attribute [rw] id
35
+ # The primary key of the port.
36
+ #
37
+ # @return [Integer]
38
+ attribute :id, :integer
39
+
40
+ # @!attribute [rw] protocol
41
+ # The protocol of the port (either `'tcp'` / `'udp'`).
42
+ #
43
+ # @return [:tcp, :udp]
44
+ enum :protocol, {tcp: 'tcp', udp: 'udp'}, default: :tcp
45
+ validates :protocol, presence: true
46
+
47
+ # @!attribute [rw] number
48
+ # The port number.
49
+ #
50
+ # @return [Integer]
51
+ attribute :number, :integer
52
+ validates :number, presence: true,
53
+ numericality: {
54
+ greater_than_or_equal_to: 1,
55
+ less_than_or_equal_to: 65535
56
+ },
57
+ uniqueness: {scope: :protocol}
58
+
59
+ # @!attribute [rw] open_ports
60
+ # The open ports.
61
+ #
62
+ # @return [Array<OpenPort>]
63
+ has_many :open_ports, dependent: :destroy
64
+
65
+ #
66
+ # Looks up a port by it's number.
67
+ #
68
+ # @param [String, Integer] number
69
+ # The port number to query.
70
+ #
71
+ # @return [Port, nil]
72
+ # The found port number.
73
+ #
74
+ # @api public
75
+ #
76
+ def self.lookup(number)
77
+ find_by(number: number)
78
+ end
79
+
80
+ #
81
+ # Creates a new Port.
82
+ #
83
+ # @param [String, Integer] number
84
+ # The port number.
85
+ #
86
+ # @return [Port]
87
+ # The new or previously saved port.
88
+ #
89
+ # @api public
90
+ #
91
+ def self.import(number)
92
+ create(number: number)
93
+ end
94
+
95
+ #
96
+ # Converts the port to an integer.
97
+ #
98
+ # @return [Integer]
99
+ # The port number.
100
+ #
101
+ # @api public
102
+ #
103
+ def to_i
104
+ self.number.to_i
105
+ end
106
+
107
+ #
108
+ # Converts the port to a string.
109
+ #
110
+ # @return [String]
111
+ # The port number and protocol.
112
+ #
113
+ # @api public
114
+ #
115
+ def to_s
116
+ "#{self.number}/#{self.protocol}"
117
+ end
118
+
119
+ end
120
+ end
121
+ end
122
+
123
+ require 'ronin/db/open_port'
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
4
+ #
5
+ # Copyright (c) 2022 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # ronin-db-activerecord is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-db-activerecord is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-db-activerecord. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ module Ronin
22
+ module DB
23
+ # Path to `ronin-db-activerecord` root directory.
24
+ #
25
+ # @api private
26
+ ROOT = File.expand_path(File.join(__dir__,'..','..','..'))
27
+ end
28
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
4
+ #
5
+ # Copyright (c) 2022 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # ronin-db-activerecord is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-db-activerecord is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-db-activerecord. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'active_record'
22
+ require 'active_record/schema_migration'
23
+
24
+ module Ronin
25
+ module DB
26
+ #
27
+ # Represents the `ronin_schema_migrations` table which tracks the applied
28
+ # migrations.
29
+ #
30
+ class SchemaMigration < ActiveRecord::SchemaMigration
31
+ self.table_name_prefix = 'ronin_'
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
4
+ #
5
+ # Copyright (c) 2022 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # ronin-db-activerecord is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-db-activerecord is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-db-activerecord. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/db/model'
22
+ require 'ronin/db/model/has_unique_name'
23
+
24
+ module Ronin
25
+ module DB
26
+ #
27
+ # Represents a TCP/UDP Service that runs on various common ports.
28
+ #
29
+ class Service < ActiveRecord::Base
30
+
31
+ include Model
32
+ include Model::HasUniqueName
33
+
34
+ # @!attribute [rw] id
35
+ # Primary key of the service
36
+ #
37
+ # @return [Integer]
38
+ attribute :id, :integer
39
+
40
+ # @!attribute [rw] open_ports
41
+ # The open ports running the service
42
+ #
43
+ # @return [Array<OpenPort>]
44
+ has_many :open_ports
45
+
46
+ end
47
+ end
48
+ end