ronin-db-activerecord 0.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.github/workflows/ruby.yml +31 -0
- data/.gitignore +13 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -0
- data/.yardopts +1 -0
- data/COPYING.txt +165 -0
- data/ChangeLog.md +39 -0
- data/Gemfile +27 -0
- data/README.md +143 -0
- data/Rakefile +72 -0
- data/db/migrate/0001_create_ronin_ip_address_mac_addresses_table.rb +43 -0
- data/db/migrate/0002_create_ronin_vulnerabilities_table.rb +61 -0
- data/db/migrate/0003_create_ronin_url_schemes_table.rb +32 -0
- data/db/migrate/0004_create_ronin_url_query_param_names_table.rb +32 -0
- data/db/migrate/0005_create_ronin_user_names_table.rb +33 -0
- data/db/migrate/0006_create_ronin_software_vendors_table.rb +32 -0
- data/db/migrate/0007_create_ronin_advisories_table.rb +42 -0
- data/db/migrate/0008_create_ronin_host_name_ip_addresses_table.rb +43 -0
- data/db/migrate/0009_create_ronin_host_names_table.rb +34 -0
- data/db/migrate/0010_create_ronin_arches_table.rb +37 -0
- data/db/migrate/0011_create_ronin_email_addresses_table.rb +44 -0
- data/db/migrate/0012_create_ronin_oses_table.rb +36 -0
- data/db/migrate/0013_create_ronin_organizations_table.rb +31 -0
- data/db/migrate/0014_create_ronin_ip_addresses_table.rb +35 -0
- data/db/migrate/0015_create_ronin_os_guesses_table.rb +40 -0
- data/db/migrate/0016_create_ronin_url_query_params_table.rb +42 -0
- data/db/migrate/0017_create_ronin_passwords_table.rb +32 -0
- data/db/migrate/0018_create_ronin_open_ports_table.rb +46 -0
- data/db/migrate/0019_create_ronin_urls_table.rb +50 -0
- data/db/migrate/0020_create_ronin_softwares_table.rb +39 -0
- data/db/migrate/0021_create_ronin_mac_addresses_table.rb +33 -0
- data/db/migrate/0022_create_ronin_countries_table.rb +34 -0
- data/db/migrate/0023_create_ronin_services_table.rb +32 -0
- data/db/migrate/0024_create_ronin_credentials_table.rb +44 -0
- data/db/migrate/0025_create_ronin_ports_table.rb +33 -0
- data/db/migrate/0026_create_ronin_asns_table.rb +44 -0
- data/db/migrate/0027_create_ronin_http_query_param_names_table.rb +32 -0
- data/db/migrate/0028_create_ronin_http_query_params_table.rb +42 -0
- data/db/migrate/0029_create_ronin_http_header_names_table.rb +31 -0
- data/db/migrate/0030_create_ronin_http_request_headers_table.rb +41 -0
- data/db/migrate/0031_create_ronin_http_response_headers_table.rb +41 -0
- data/db/migrate/0032_create_ronin_http_requests_table.rb +41 -0
- data/db/migrate/0033_create_ronin_http_responses_table.rb +36 -0
- data/db/migrate/0034_create_ronin_service_credentials_table.rb +41 -0
- data/db/migrate/0035_create_ronin_web_credentials_table.rb +41 -0
- data/gemspec.yml +28 -0
- data/lib/ronin/db/address.rb +105 -0
- data/lib/ronin/db/advisory.rb +169 -0
- data/lib/ronin/db/arch.rb +160 -0
- data/lib/ronin/db/asn.rb +212 -0
- data/lib/ronin/db/credential.rb +248 -0
- data/lib/ronin/db/email_address.rb +225 -0
- data/lib/ronin/db/host_name.rb +224 -0
- data/lib/ronin/db/host_name_ip_address.rb +65 -0
- data/lib/ronin/db/http_header_name.rb +75 -0
- data/lib/ronin/db/http_query_param.rb +79 -0
- data/lib/ronin/db/http_query_param_name.rb +76 -0
- data/lib/ronin/db/http_request.rb +120 -0
- data/lib/ronin/db/http_request_header.rb +78 -0
- data/lib/ronin/db/http_response.rb +91 -0
- data/lib/ronin/db/http_response_header.rb +78 -0
- data/lib/ronin/db/ip_address.rb +351 -0
- data/lib/ronin/db/ip_address_mac_address.rb +62 -0
- data/lib/ronin/db/mac_address.rb +91 -0
- data/lib/ronin/db/migrations.rb +137 -0
- data/lib/ronin/db/model/has_name.rb +102 -0
- data/lib/ronin/db/model/has_unique_name.rb +82 -0
- data/lib/ronin/db/model/importable.rb +85 -0
- data/lib/ronin/db/model/last_scanned_at.rb +48 -0
- data/lib/ronin/db/model.rb +37 -0
- data/lib/ronin/db/models.rb +108 -0
- data/lib/ronin/db/open_port.rb +148 -0
- data/lib/ronin/db/organization.rb +50 -0
- data/lib/ronin/db/os.rb +183 -0
- data/lib/ronin/db/os_guess.rb +67 -0
- data/lib/ronin/db/password.rb +167 -0
- data/lib/ronin/db/port.rb +123 -0
- data/lib/ronin/db/root.rb +28 -0
- data/lib/ronin/db/schema_migration.rb +34 -0
- data/lib/ronin/db/service.rb +48 -0
- data/lib/ronin/db/service_credential.rb +66 -0
- data/lib/ronin/db/software.rb +85 -0
- data/lib/ronin/db/software_vendor.rb +42 -0
- data/lib/ronin/db/url.rb +497 -0
- data/lib/ronin/db/url_query_param.rb +79 -0
- data/lib/ronin/db/url_query_param_name.rb +76 -0
- data/lib/ronin/db/url_scheme.rb +80 -0
- data/lib/ronin/db/user_name.rb +96 -0
- data/lib/ronin/db/vulnerability.rb +81 -0
- data/lib/ronin/db/web_credential.rb +69 -0
- data/ronin-db-activerecord.gemspec +61 -0
- data/spec/advisory_spec.rb +277 -0
- data/spec/arch_spec.rb +228 -0
- data/spec/asn_spec.rb +504 -0
- data/spec/credential_spec.rb +362 -0
- data/spec/email_address_spec.rb +372 -0
- data/spec/host_name_ip_address_spec.rb +8 -0
- data/spec/host_name_spec.rb +207 -0
- data/spec/http_header_name_spec.rb +25 -0
- data/spec/http_query_param_name_spec.rb +25 -0
- data/spec/http_query_param_spec.rb +104 -0
- data/spec/http_request_header_spec.rb +72 -0
- data/spec/http_request_spec.rb +168 -0
- data/spec/http_response_header_spec.rb +74 -0
- data/spec/http_response_spec.rb +103 -0
- data/spec/ip_address_mac_addresses_spec.rb +8 -0
- data/spec/ip_address_spec.rb +386 -0
- data/spec/mac_address_spec.rb +67 -0
- data/spec/migrations_spec.rb +122 -0
- data/spec/model/has_name_spec.rb +65 -0
- data/spec/model/has_unique_name_spec.rb +61 -0
- data/spec/model/importable_spec.rb +105 -0
- data/spec/models_spec.rb +60 -0
- data/spec/open_port_spec.rb +87 -0
- data/spec/organization_spec.rb +10 -0
- data/spec/os_guess_spec.rb +43 -0
- data/spec/os_spec.rb +114 -0
- data/spec/password_spec.rb +81 -0
- data/spec/port_spec.rb +102 -0
- data/spec/schema_migration_spec.rb +8 -0
- data/spec/service_credential_spec.rb +43 -0
- data/spec/service_spec.rb +39 -0
- data/spec/software_spec.rb +76 -0
- data/spec/software_vendor_spec.rb +33 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/url_query_param_name_spec.rb +25 -0
- data/spec/url_query_param_spec.rb +110 -0
- data/spec/url_scheme_spec.rb +39 -0
- data/spec/url_spec.rb +951 -0
- data/spec/user_name_spec.rb +54 -0
- data/spec/vulnerability_spec.rb +8 -0
- data/spec/web_credential_spec.rb +72 -0
- metadata +266 -0
@@ -0,0 +1,102 @@
|
|
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
|
+
module Ronin
|
24
|
+
module DB
|
25
|
+
module Model
|
26
|
+
#
|
27
|
+
# Adds a `name` property to a model.
|
28
|
+
#
|
29
|
+
module HasName
|
30
|
+
#
|
31
|
+
# @!attribute [rw] name
|
32
|
+
# The name attribute of the model.
|
33
|
+
#
|
34
|
+
# @return [String]
|
35
|
+
#
|
36
|
+
|
37
|
+
#
|
38
|
+
# Adds the `name` property and {ClassMethods} to the model.
|
39
|
+
#
|
40
|
+
# @param [Class] base
|
41
|
+
# The model.
|
42
|
+
#
|
43
|
+
# @api private
|
44
|
+
#
|
45
|
+
def self.included(base)
|
46
|
+
base.send :include, Model, InstanceMethods
|
47
|
+
base.send :extend, ClassMethods
|
48
|
+
|
49
|
+
base.module_eval do
|
50
|
+
# The name attribute of the model
|
51
|
+
attribute :name, :string
|
52
|
+
validates :name, presence: true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# Class methods that are added when {HasName} is included into a
|
58
|
+
# model.
|
59
|
+
#
|
60
|
+
module ClassMethods
|
61
|
+
#
|
62
|
+
# Finds models with names containing a given fragment of text.
|
63
|
+
#
|
64
|
+
# @param [String] fragment
|
65
|
+
# The fragment of text to search for within the names of models.
|
66
|
+
#
|
67
|
+
# @return [Array<Model>]
|
68
|
+
# The found models.
|
69
|
+
#
|
70
|
+
# @example
|
71
|
+
# Exploit.named 'ProFTP'
|
72
|
+
#
|
73
|
+
# @api public
|
74
|
+
#
|
75
|
+
def named(fragment)
|
76
|
+
name_column = self.arel_table[:name]
|
77
|
+
|
78
|
+
where(name_column.matches("%#{sanitize_sql_like(fragment)}%"))
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
#
|
83
|
+
# Instance methods that are added when {HasName} is included into a
|
84
|
+
# model.
|
85
|
+
#
|
86
|
+
module InstanceMethods
|
87
|
+
#
|
88
|
+
# Converts the named resource into a String.
|
89
|
+
#
|
90
|
+
# @return [String]
|
91
|
+
# The name of the resource.
|
92
|
+
#
|
93
|
+
# @api public
|
94
|
+
#
|
95
|
+
def to_s
|
96
|
+
self.name.to_s
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,82 @@
|
|
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/has_name'
|
22
|
+
|
23
|
+
module Ronin
|
24
|
+
module DB
|
25
|
+
module Model
|
26
|
+
#
|
27
|
+
# Adds a unique `name` property to a model.
|
28
|
+
#
|
29
|
+
module HasUniqueName
|
30
|
+
#
|
31
|
+
# @!attribute [rw] name
|
32
|
+
# The unqiue name of the model.
|
33
|
+
#
|
34
|
+
# @return [String]
|
35
|
+
#
|
36
|
+
|
37
|
+
#
|
38
|
+
# Adds the unique `name` property and {HasName::ClassMethods} to the
|
39
|
+
# model.
|
40
|
+
#
|
41
|
+
# @param [Class] base
|
42
|
+
# The model.
|
43
|
+
#
|
44
|
+
# @api semipublic
|
45
|
+
#
|
46
|
+
def self.included(base)
|
47
|
+
base.send :include, Model,
|
48
|
+
HasName::InstanceMethods
|
49
|
+
|
50
|
+
base.send :extend, HasName::ClassMethods,
|
51
|
+
HasUniqueName::ClassMethods
|
52
|
+
|
53
|
+
base.module_eval do
|
54
|
+
# The name of the model
|
55
|
+
attribute :name, :string
|
56
|
+
validates :name, presence: true, uniqueness: true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
#
|
61
|
+
# Class methods that will be added when {HasUniqueName} is included.
|
62
|
+
#
|
63
|
+
module ClassMethods
|
64
|
+
#
|
65
|
+
# Parses a unique name.
|
66
|
+
#
|
67
|
+
# @param [String] name
|
68
|
+
# The name to parse.
|
69
|
+
#
|
70
|
+
# @return [Model]
|
71
|
+
# A new or previously saved resource.
|
72
|
+
#
|
73
|
+
# @api public
|
74
|
+
#
|
75
|
+
def parse(name)
|
76
|
+
find_or_initialize_by(name: name.strip)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,85 @@
|
|
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
|
+
module Model
|
24
|
+
#
|
25
|
+
# Allows a model to import records from raw values.
|
26
|
+
#
|
27
|
+
module Importable
|
28
|
+
#
|
29
|
+
# Adds {ClassMethods} to the model including {Importable}.
|
30
|
+
#
|
31
|
+
# @param [Class] model
|
32
|
+
# The model including {Importable}.
|
33
|
+
#
|
34
|
+
# @api private
|
35
|
+
#
|
36
|
+
def self.included(model)
|
37
|
+
model.extend ClassMethods
|
38
|
+
end
|
39
|
+
|
40
|
+
module ClassMethods
|
41
|
+
#
|
42
|
+
# Looks up a record with the given value.
|
43
|
+
#
|
44
|
+
# @param [Object] value
|
45
|
+
# The raw value to use for the query.
|
46
|
+
#
|
47
|
+
# @return [ActiveRecord::Base, nil]
|
48
|
+
# The found record.
|
49
|
+
#
|
50
|
+
def lookup(value)
|
51
|
+
raise(NotImplementedError,"#{self} did not define a self.lookup method")
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# Imports a record from the given value.
|
56
|
+
#
|
57
|
+
# @param [Object] value
|
58
|
+
# The raw value that represents the record.
|
59
|
+
#
|
60
|
+
# @return [ActiveRecord::Base]
|
61
|
+
# The imported record.
|
62
|
+
#
|
63
|
+
# @abstract
|
64
|
+
#
|
65
|
+
def import(value)
|
66
|
+
raise(NotImplementedError,"#{self} did not define a self.import method")
|
67
|
+
end
|
68
|
+
|
69
|
+
#
|
70
|
+
# Finds or imports a new record.
|
71
|
+
#
|
72
|
+
# @param [Object] value
|
73
|
+
# The raw value that represents the record.
|
74
|
+
#
|
75
|
+
# @return [ActiveRecord::Base]
|
76
|
+
# The found or created record.
|
77
|
+
#
|
78
|
+
def find_or_import(value)
|
79
|
+
lookup(value) || import(value)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
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
|
+
module Ronin
|
22
|
+
module DB
|
23
|
+
module Model
|
24
|
+
module LastScannedAt
|
25
|
+
#
|
26
|
+
# @!attribute [rw] last_scanned_at
|
27
|
+
# Whenever the model was last scanned.
|
28
|
+
#
|
29
|
+
# @return [Time, nil]
|
30
|
+
#
|
31
|
+
|
32
|
+
#
|
33
|
+
# Adds the `last_scanned_at` attribute to the model.
|
34
|
+
#
|
35
|
+
# @param [Class<ActiveRecord::Base>] model
|
36
|
+
# The ActiveRecord model which is including {LastScannedAt}.
|
37
|
+
#
|
38
|
+
# @api private
|
39
|
+
#
|
40
|
+
def self.included(model)
|
41
|
+
model.class_eval do
|
42
|
+
attribute :last_scanned_at, :time
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,37 @@
|
|
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
|
+
module Model
|
24
|
+
#
|
25
|
+
# Sets the models `table_name_prefix` to `ronin_`.
|
26
|
+
#
|
27
|
+
# @param [Class<ActiveRecord::Base>] model
|
28
|
+
# The ActiveRecord model class which is including {Model}.
|
29
|
+
#
|
30
|
+
# @api private
|
31
|
+
#
|
32
|
+
def self.included(model)
|
33
|
+
model.table_name_prefix = 'ronin_'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,108 @@
|
|
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/address'
|
22
|
+
require 'ronin/db/arch'
|
23
|
+
require 'ronin/db/credential'
|
24
|
+
require 'ronin/db/email_address'
|
25
|
+
require 'ronin/db/host_name'
|
26
|
+
require 'ronin/db/host_name_ip_address'
|
27
|
+
require 'ronin/db/ip_address'
|
28
|
+
require 'ronin/db/ip_address_mac_address'
|
29
|
+
require 'ronin/db/mac_address'
|
30
|
+
require 'ronin/db/open_port'
|
31
|
+
require 'ronin/db/organization'
|
32
|
+
require 'ronin/db/os'
|
33
|
+
require 'ronin/db/os_guess'
|
34
|
+
require 'ronin/db/password'
|
35
|
+
require 'ronin/db/port'
|
36
|
+
require 'ronin/db/service'
|
37
|
+
require 'ronin/db/service_credential'
|
38
|
+
require 'ronin/db/software'
|
39
|
+
require 'ronin/db/url_query_param_name'
|
40
|
+
require 'ronin/db/url_query_param'
|
41
|
+
require 'ronin/db/url_scheme'
|
42
|
+
require 'ronin/db/url'
|
43
|
+
require 'ronin/db/user_name'
|
44
|
+
require 'ronin/db/software_vendor'
|
45
|
+
require 'ronin/db/web_credential'
|
46
|
+
require 'ronin/db/asn'
|
47
|
+
require 'ronin/db/http_query_param_name'
|
48
|
+
require 'ronin/db/http_query_param'
|
49
|
+
require 'ronin/db/http_header_name'
|
50
|
+
require 'ronin/db/http_request_header'
|
51
|
+
require 'ronin/db/http_response_header'
|
52
|
+
require 'ronin/db/http_request'
|
53
|
+
require 'ronin/db/http_response'
|
54
|
+
require 'ronin/db/advisory'
|
55
|
+
require 'ronin/db/vulnerability'
|
56
|
+
|
57
|
+
module Ronin
|
58
|
+
module DB
|
59
|
+
module Models
|
60
|
+
ALL = [
|
61
|
+
Address,
|
62
|
+
Arch,
|
63
|
+
Credential,
|
64
|
+
EmailAddress,
|
65
|
+
HostName,
|
66
|
+
HostNameIPAddress,
|
67
|
+
IPAddress,
|
68
|
+
IPAddressMACAddress,
|
69
|
+
MACAddress,
|
70
|
+
OS,
|
71
|
+
OSGuess,
|
72
|
+
OpenPort,
|
73
|
+
Organization,
|
74
|
+
Password,
|
75
|
+
Port,
|
76
|
+
Service,
|
77
|
+
ServiceCredential,
|
78
|
+
Software,
|
79
|
+
URLQueryParamName,
|
80
|
+
URLQueryParam,
|
81
|
+
URLScheme,
|
82
|
+
URL,
|
83
|
+
UserName,
|
84
|
+
SoftwareVendor,
|
85
|
+
WebCredential,
|
86
|
+
ASN,
|
87
|
+
HTTPQueryParamName,
|
88
|
+
HTTPQueryParam,
|
89
|
+
HTTPHeaderName,
|
90
|
+
HTTPRequestHeader,
|
91
|
+
HTTPResponseHeader,
|
92
|
+
HTTPRequest,
|
93
|
+
HTTPResponse,
|
94
|
+
Advisory,
|
95
|
+
Vulnerability
|
96
|
+
]
|
97
|
+
|
98
|
+
#
|
99
|
+
# Calls `.connect` on all {Ronin::DB} models.
|
100
|
+
#
|
101
|
+
# @api semipublic
|
102
|
+
#
|
103
|
+
def self.connect
|
104
|
+
ALL.each(&:connection)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,148 @@
|
|
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/last_scanned_at'
|
23
|
+
|
24
|
+
require 'active_record'
|
25
|
+
|
26
|
+
module Ronin
|
27
|
+
module DB
|
28
|
+
#
|
29
|
+
# Represents a open port at a specified IP address.
|
30
|
+
#
|
31
|
+
class OpenPort < ActiveRecord::Base
|
32
|
+
|
33
|
+
include Model
|
34
|
+
include Model::LastScannedAt
|
35
|
+
|
36
|
+
# @!attribute [rw] id
|
37
|
+
# The primary key of the open port.
|
38
|
+
#
|
39
|
+
# @return [Integer]
|
40
|
+
attribute :id, :integer
|
41
|
+
|
42
|
+
# @!attribute [rw] ip_address
|
43
|
+
# The IP Address that was scanned.
|
44
|
+
#
|
45
|
+
# @return [IPAddress]
|
46
|
+
belongs_to :ip_address, required: true,
|
47
|
+
class_name: 'IPAddress'
|
48
|
+
|
49
|
+
# @!attribute [rw] port
|
50
|
+
# The port.
|
51
|
+
#
|
52
|
+
# @return [Port]
|
53
|
+
belongs_to :port, required: true
|
54
|
+
|
55
|
+
# @!attribute [rw] service
|
56
|
+
# The service detected on the port
|
57
|
+
#
|
58
|
+
# @return [Service, nil]
|
59
|
+
belongs_to :service, optional: true
|
60
|
+
|
61
|
+
# @!attribute [rw] software
|
62
|
+
# The software running on the open port
|
63
|
+
#
|
64
|
+
# @return [Software]
|
65
|
+
belongs_to :software, optional: true
|
66
|
+
|
67
|
+
# @!attribute [rw] ssl
|
68
|
+
# Specifies whether the service requires SSL.
|
69
|
+
#
|
70
|
+
# @return [Boolean]
|
71
|
+
attribute :ssl, :boolean
|
72
|
+
|
73
|
+
# @!attribute [r] created_at
|
74
|
+
# Define the created_at timestamp
|
75
|
+
#
|
76
|
+
# @return [Time]
|
77
|
+
attribute :created_at, :time
|
78
|
+
|
79
|
+
# @!attribute [rw] service_credentials
|
80
|
+
# Credentials used by the service running on the port
|
81
|
+
#
|
82
|
+
# @return [Array<ServiceCredential>]
|
83
|
+
has_many :service_credentials, dependent: :destroy
|
84
|
+
|
85
|
+
# @!attribute [rw] credentials
|
86
|
+
# The credentials that will work with this open port.
|
87
|
+
#
|
88
|
+
# @return [Array<Credential>]
|
89
|
+
has_many :credentials, through: :service_credentials
|
90
|
+
|
91
|
+
#
|
92
|
+
# The IP Address of the open port.
|
93
|
+
#
|
94
|
+
# @return [String]
|
95
|
+
# The IP Address.
|
96
|
+
#
|
97
|
+
# @api public
|
98
|
+
#
|
99
|
+
def address
|
100
|
+
self.ip_address.address
|
101
|
+
end
|
102
|
+
|
103
|
+
#
|
104
|
+
# The port number.
|
105
|
+
#
|
106
|
+
# @return [Integer]
|
107
|
+
# The port number.
|
108
|
+
#
|
109
|
+
# @api public
|
110
|
+
#
|
111
|
+
def number
|
112
|
+
self.port.number
|
113
|
+
end
|
114
|
+
|
115
|
+
#
|
116
|
+
# Converts the open port to an integer.
|
117
|
+
#
|
118
|
+
# @return [Integer]
|
119
|
+
# The port number.
|
120
|
+
#
|
121
|
+
# @api public
|
122
|
+
#
|
123
|
+
def to_i
|
124
|
+
self.port.to_i
|
125
|
+
end
|
126
|
+
|
127
|
+
#
|
128
|
+
# Converts the open port to a string.
|
129
|
+
#
|
130
|
+
# @return [String]
|
131
|
+
# The information of the open port.
|
132
|
+
#
|
133
|
+
# @api public
|
134
|
+
#
|
135
|
+
def to_s
|
136
|
+
if self.service then "#{self.port} (#{self.service})"
|
137
|
+
else "#{self.port}"
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
require 'ronin/db/ip_address'
|
146
|
+
require 'ronin/db/port'
|
147
|
+
require 'ronin/db/service'
|
148
|
+
require 'ronin/db/service_credential'
|
@@ -0,0 +1,50 @@
|
|
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
|
+
require 'active_record'
|
25
|
+
|
26
|
+
module Ronin
|
27
|
+
module DB
|
28
|
+
#
|
29
|
+
# Represents an Company.
|
30
|
+
#
|
31
|
+
class Organization < ActiveRecord::Base
|
32
|
+
|
33
|
+
include Model
|
34
|
+
include Model::HasUniqueName
|
35
|
+
|
36
|
+
# @!attribute [rw] id
|
37
|
+
# Primary key of the organization
|
38
|
+
#
|
39
|
+
# @return [Integer]
|
40
|
+
attribute :id, :integer
|
41
|
+
|
42
|
+
# @!attribute [r] created_at
|
43
|
+
# Tracks when the organization was first created
|
44
|
+
#
|
45
|
+
# @return [Time]
|
46
|
+
attribute :created_at, :time
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|