ronin-db-activerecord 0.1.0.beta1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -0
  3. data/.yardopts +1 -1
  4. data/README.md +69 -34
  5. data/db/migrate/0001_create_ronin_ip_address_mac_addresses_table.rb +1 -1
  6. data/db/migrate/0002_create_ronin_vulnerabilities_table.rb +1 -1
  7. data/db/migrate/0003_create_ronin_url_schemes_table.rb +1 -1
  8. data/db/migrate/0004_create_ronin_url_query_param_names_table.rb +1 -1
  9. data/db/migrate/0005_create_ronin_user_names_table.rb +1 -1
  10. data/db/migrate/0006_create_ronin_software_vendors_table.rb +1 -1
  11. data/db/migrate/0007_create_ronin_advisories_table.rb +1 -1
  12. data/db/migrate/0008_create_ronin_host_name_ip_addresses_table.rb +1 -1
  13. data/db/migrate/0009_create_ronin_host_names_table.rb +1 -1
  14. data/db/migrate/0010_create_ronin_arches_table.rb +1 -1
  15. data/db/migrate/0011_create_ronin_email_addresses_table.rb +1 -1
  16. data/db/migrate/0012_create_ronin_oses_table.rb +1 -1
  17. data/db/migrate/0013_create_ronin_organizations_table.rb +1 -1
  18. data/db/migrate/0014_create_ronin_ip_addresses_table.rb +1 -1
  19. data/db/migrate/0015_create_ronin_os_guesses_table.rb +1 -1
  20. data/db/migrate/0016_create_ronin_url_query_params_table.rb +1 -1
  21. data/db/migrate/0017_create_ronin_passwords_table.rb +1 -1
  22. data/db/migrate/0018_create_ronin_open_ports_table.rb +1 -1
  23. data/db/migrate/0019_create_ronin_urls_table.rb +1 -1
  24. data/db/migrate/0020_create_ronin_softwares_table.rb +1 -1
  25. data/db/migrate/0021_create_ronin_mac_addresses_table.rb +1 -1
  26. data/db/migrate/0022_create_ronin_countries_table.rb +1 -1
  27. data/db/migrate/0023_create_ronin_services_table.rb +1 -1
  28. data/db/migrate/0024_create_ronin_credentials_table.rb +1 -1
  29. data/db/migrate/0025_create_ronin_ports_table.rb +1 -1
  30. data/db/migrate/0026_create_ronin_asns_table.rb +1 -1
  31. data/db/migrate/0027_create_ronin_http_query_param_names_table.rb +1 -1
  32. data/db/migrate/0028_create_ronin_http_query_params_table.rb +1 -1
  33. data/db/migrate/0029_create_ronin_http_header_names_table.rb +1 -1
  34. data/db/migrate/0030_create_ronin_http_request_headers_table.rb +1 -1
  35. data/db/migrate/0031_create_ronin_http_response_headers_table.rb +1 -1
  36. data/db/migrate/0032_create_ronin_http_requests_table.rb +1 -1
  37. data/db/migrate/0033_create_ronin_http_responses_table.rb +1 -1
  38. data/db/migrate/0034_create_ronin_service_credentials_table.rb +1 -1
  39. data/db/migrate/0035_create_ronin_web_credentials_table.rb +1 -1
  40. data/gemspec.yml +3 -3
  41. data/lib/ronin/db/address.rb +1 -1
  42. data/lib/ronin/db/advisory.rb +2 -2
  43. data/lib/ronin/db/arch.rb +1 -1
  44. data/lib/ronin/db/asn.rb +1 -1
  45. data/lib/ronin/db/credential.rb +1 -1
  46. data/lib/ronin/db/email_address.rb +1 -1
  47. data/lib/ronin/db/host_name.rb +2 -2
  48. data/lib/ronin/db/host_name_ip_address.rb +1 -1
  49. data/lib/ronin/db/http_header_name.rb +1 -1
  50. data/lib/ronin/db/http_query_param.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_request_header.rb +1 -1
  54. data/lib/ronin/db/http_response.rb +2 -2
  55. data/lib/ronin/db/http_response_header.rb +1 -1
  56. data/lib/ronin/db/ip_address.rb +1 -1
  57. data/lib/ronin/db/ip_address_mac_address.rb +1 -1
  58. data/lib/ronin/db/mac_address.rb +1 -1
  59. data/lib/ronin/db/migrations.rb +1 -1
  60. data/lib/ronin/db/model/has_name.rb +1 -1
  61. data/lib/ronin/db/model/has_unique_name.rb +2 -2
  62. data/lib/ronin/db/model/importable.rb +1 -1
  63. data/lib/ronin/db/model/last_scanned_at.rb +1 -1
  64. data/lib/ronin/db/model.rb +1 -1
  65. data/lib/ronin/db/models.rb +1 -1
  66. data/lib/ronin/db/open_port.rb +1 -1
  67. data/lib/ronin/db/organization.rb +1 -1
  68. data/lib/ronin/db/os.rb +1 -1
  69. data/lib/ronin/db/os_guess.rb +1 -1
  70. data/lib/ronin/db/password.rb +1 -1
  71. data/lib/ronin/db/port.rb +1 -1
  72. data/lib/ronin/db/schema_migration.rb +1 -1
  73. data/lib/ronin/db/service.rb +1 -1
  74. data/lib/ronin/db/service_credential.rb +1 -1
  75. data/lib/ronin/db/software.rb +1 -1
  76. data/lib/ronin/db/software_vendor.rb +1 -1
  77. data/lib/ronin/db/url.rb +1 -1
  78. data/lib/ronin/db/url_query_param.rb +1 -1
  79. data/lib/ronin/db/url_query_param_name.rb +1 -1
  80. data/lib/ronin/db/url_scheme.rb +1 -1
  81. data/lib/ronin/db/user_name.rb +1 -1
  82. data/lib/ronin/db/vulnerability.rb +1 -1
  83. data/lib/ronin/db/web_credential.rb +1 -1
  84. data/ronin-db-activerecord.gemspec +2 -1
  85. metadata +5 -87
  86. data/lib/ronin/db/root.rb +0 -28
  87. data/spec/advisory_spec.rb +0 -277
  88. data/spec/arch_spec.rb +0 -228
  89. data/spec/asn_spec.rb +0 -504
  90. data/spec/credential_spec.rb +0 -362
  91. data/spec/email_address_spec.rb +0 -372
  92. data/spec/host_name_ip_address_spec.rb +0 -8
  93. data/spec/host_name_spec.rb +0 -207
  94. data/spec/http_header_name_spec.rb +0 -25
  95. data/spec/http_query_param_name_spec.rb +0 -25
  96. data/spec/http_query_param_spec.rb +0 -104
  97. data/spec/http_request_header_spec.rb +0 -72
  98. data/spec/http_request_spec.rb +0 -168
  99. data/spec/http_response_header_spec.rb +0 -74
  100. data/spec/http_response_spec.rb +0 -103
  101. data/spec/ip_address_mac_addresses_spec.rb +0 -8
  102. data/spec/ip_address_spec.rb +0 -386
  103. data/spec/mac_address_spec.rb +0 -67
  104. data/spec/migrations_spec.rb +0 -122
  105. data/spec/model/has_name_spec.rb +0 -65
  106. data/spec/model/has_unique_name_spec.rb +0 -61
  107. data/spec/model/importable_spec.rb +0 -105
  108. data/spec/models_spec.rb +0 -60
  109. data/spec/open_port_spec.rb +0 -87
  110. data/spec/organization_spec.rb +0 -10
  111. data/spec/os_guess_spec.rb +0 -43
  112. data/spec/os_spec.rb +0 -114
  113. data/spec/password_spec.rb +0 -81
  114. data/spec/port_spec.rb +0 -102
  115. data/spec/schema_migration_spec.rb +0 -8
  116. data/spec/service_credential_spec.rb +0 -43
  117. data/spec/service_spec.rb +0 -39
  118. data/spec/software_spec.rb +0 -76
  119. data/spec/software_vendor_spec.rb +0 -33
  120. data/spec/spec_helper.rb +0 -13
  121. data/spec/url_query_param_name_spec.rb +0 -25
  122. data/spec/url_query_param_spec.rb +0 -110
  123. data/spec/url_scheme_spec.rb +0 -39
  124. data/spec/url_spec.rb +0 -951
  125. data/spec/user_name_spec.rb +0 -54
  126. data/spec/vulnerability_spec.rb +0 -8
  127. data/spec/web_credential_spec.rb +0 -72
@@ -1,277 +0,0 @@
1
- require 'spec_helper'
2
- require 'ronin/db/advisory'
3
-
4
- describe Ronin::DB::Advisory do
5
- describe described_class::ID do
6
- describe ".parse" do
7
- subject { described_class }
8
-
9
- context "when given a CVE ID" do
10
- let(:year) { 2020 }
11
- let(:identifier) { '1234' }
12
- let(:id) { "CVE-#{year}-#{identifier}" }
13
-
14
- it "must return a Hash containing the ID, 'CVE' prefix, the year, and the identifier" do
15
- expect(subject.parse(id)).to eq(
16
- {
17
- id: id,
18
- prefix: 'CVE',
19
- year: year,
20
- identifier: identifier
21
- }
22
- )
23
- end
24
- end
25
-
26
- context "when given a MS ID" do
27
- let(:year) { 2017 }
28
- let(:identifier) { '010' }
29
- let(:id) { "MS#{year - 2000}-#{identifier}" }
30
-
31
- it "must return a Hash containing the ID, 'MS' prefix, the full year, and the identifier" do
32
- expect(subject.parse(id)).to eq(
33
- {
34
- id: id,
35
- prefix: 'MS',
36
- year: year,
37
- identifier: identifier
38
- }
39
- )
40
- end
41
- end
42
-
43
- context "when given a RHSA ID" do
44
- let(:year) { 2022 }
45
- let(:identifier) { '6187' }
46
- let(:id) { "RHSA-#{year}:#{identifier}" }
47
-
48
- it "must return a Hash containing the ID, 'RHSA' prefix, the year, and the identifier" do
49
- expect(subject.parse(id)).to eq(
50
- {
51
- id: id,
52
- prefix: 'RHSA',
53
- year: year,
54
- identifier: identifier
55
- }
56
- )
57
- end
58
- end
59
-
60
- context "when given a GHSA ID" do
61
- let(:identifier) { '3hhc-qp5v-9p2j' }
62
- let(:id) { "GHSA-#{identifier}" }
63
-
64
- it "must return a Hash containing the ID and the identifier" do
65
- expect(subject.parse(id)).to eq(
66
- {
67
- id: id,
68
- prefix: 'GHSA',
69
- identifier: identifier
70
- }
71
- )
72
- end
73
- end
74
- end
75
- end
76
-
77
- describe "validations" do
78
- describe "prefix" do
79
- subject do
80
- end
81
-
82
- it "must require a preifx" do
83
- advisory = described_class.new(
84
- id: 'CVE-2022-1234',
85
- year: 2022,
86
- identifier: '2022-1234'
87
- )
88
- expect(advisory).to_not be_valid
89
- expect(advisory.errors[:prefix]).to eq(["can't be blank"])
90
-
91
- advisory = described_class.new(
92
- id: 'CVE-2022-1234',
93
- prefix: 'CVE',
94
- year: 2022,
95
- identifier: '2022-1234'
96
- )
97
- expect(advisory).to be_valid
98
- end
99
- end
100
-
101
- describe "year" do
102
- it "must accept a nil value" do
103
- advisory = described_class.new(
104
- id: 'GHSA-3hhc-qp5v-9p2j',
105
- prefix: 'GHSA',
106
- year: nil,
107
- identifier: '3hhc-qp5v-9p2j',
108
- )
109
-
110
- advisory.valid?
111
- p advisory.errors
112
- expect(advisory).to be_valid
113
- end
114
-
115
- it "must accept a numberic value" do
116
- advisory = described_class.new(
117
- id: 'CVE-2022-1234',
118
- prefix: 'CVE',
119
- year: 2022,
120
- identifier: '2022-1234'
121
- )
122
-
123
- expect(advisory).to be_valid
124
- end
125
- end
126
-
127
- describe "identifier" do
128
- it "must require a preifx" do
129
- advisory = described_class.new(
130
- id: 'CVE-2022-1234',
131
- prefix: 'CVE',
132
- year: 2022
133
- )
134
- expect(advisory).to_not be_valid
135
- expect(advisory.errors[:identifier]).to eq(["can't be blank"])
136
-
137
- advisory = described_class.new(
138
- id: 'CVE-2022-1234',
139
- prefix: 'CVE',
140
- year: 2022,
141
- identifier: '2022-1234'
142
- )
143
- expect(advisory).to be_valid
144
- end
145
- end
146
- end
147
-
148
- let(:prefix) { 'CVE' }
149
- let(:year) { 2022 }
150
- let(:identifier) { '1234' }
151
- let(:id) { "#{prefix}-#{year}-#{identifier}" }
152
-
153
- describe ".lookup" do
154
- let(:id) { 'CVE-2022-1234' }
155
-
156
- before do
157
- described_class.create(
158
- id: 'CVE-2000-1234',
159
- prefix: 'CVE',
160
- year: 2000,
161
- identifier: '2000-1234'
162
- )
163
- described_class.create(
164
- id: id,
165
- prefix: prefix,
166
- year: year,
167
- identifier: identifier
168
- )
169
- described_class.create(
170
- id: 'CVE-2000-5678',
171
- prefix: 'CVE',
172
- year: 2000,
173
- identifier: '2000-5678'
174
- )
175
- end
176
-
177
- it "must query the #{described_class} with the matching ID" do
178
- advisory = described_class.lookup(id)
179
-
180
- expect(advisory).to be_kind_of(described_class)
181
- expect(advisory.id).to eq(id)
182
- end
183
-
184
- after { described_class.destroy_all }
185
- end
186
-
187
- describe ".import" do
188
- let(:id) { 'CVE-2022-1234' }
189
- let(:parsed_id) { described_class::ID.parse(id) }
190
-
191
- subject { described_class.import(id) }
192
-
193
- it "must parse and import the advisory ID and return a new #{described_class}" do
194
- expect(subject.id).to eq(id)
195
- expect(subject.prefix).to eq(parsed_id[:prefix])
196
- expect(subject.year).to eq(parsed_id[:year])
197
- expect(subject.identifier).to eq(parsed_id[:identifier])
198
- end
199
-
200
- after { described_class.destroy_all }
201
- end
202
-
203
- subject do
204
- described_class.new(
205
- id: id,
206
- prefix: prefix,
207
- year: year,
208
- identifier: identifier
209
- )
210
- end
211
-
212
- describe "#url" do
213
- context "when #prefix is 'CVE'" do
214
- let(:prefix) { 'CVE' }
215
- let(:year) { 2022 }
216
- let(:identifier) { '1234' }
217
- let(:id) { "#{prefix}-#{year}-#{identifier}" }
218
-
219
- subject do
220
- described_class.new(
221
- id: id,
222
- prefix: prefix,
223
- year: year,
224
- identifier: identifier
225
- )
226
- end
227
-
228
- it "must return 'https://nvd.nist.gov/vuln/detail/CVE-YYYY-NNNN'" do
229
- expect(subject.url).to eq("https://nvd.nist.gov/vuln/detail/#{id}")
230
- end
231
- end
232
-
233
- context "when #prefix is 'RHSA'" do
234
- let(:prefix) { 'RHSA' }
235
- let(:year) { 2022 }
236
- let(:identifier) { '6187' }
237
- let(:id) { "#{prefix}-#{year}:#{identifier}" }
238
-
239
- subject do
240
- described_class.new(
241
- id: id,
242
- prefix: prefix,
243
- year: year,
244
- identifier: identifier
245
- )
246
- end
247
-
248
- it "must return 'https://access.redhat.com/errata/RHSA-YYYY-NNNN'" do
249
- expect(subject.url).to eq("https://access.redhat.com/errata/#{id}")
250
- end
251
- end
252
-
253
- context "when #prefix is 'GHSA'" do
254
- let(:prefix) { 'GHSA' }
255
- let(:identifier) { '3hhc-qp5v-9p2j' }
256
- let(:id) { "#{prefix}-#{identifier}" }
257
-
258
- subject do
259
- described_class.new(
260
- id: id,
261
- prefix: prefix,
262
- identifier: identifier
263
- )
264
- end
265
-
266
- it "must return 'https://github.com/advisories/GHSA-...'" do
267
- expect(subject.url).to eq("https://github.com/advisories/#{id}")
268
- end
269
- end
270
- end
271
-
272
- describe "#to_s" do
273
- it "must return the #id" do
274
- expect(subject.to_s).to eq(id)
275
- end
276
- end
277
- end
data/spec/arch_spec.rb DELETED
@@ -1,228 +0,0 @@
1
- require 'spec_helper'
2
- require 'ronin/db/arch'
3
-
4
- describe Ronin::DB::Arch do
5
- it "must use the 'ronin_arches' table" do
6
- expect(described_class.table_name).to eq('ronin_arches')
7
- end
8
-
9
- let(:name) { 'cats' }
10
- let(:endian) { :little }
11
- let(:word_size) { 4 }
12
-
13
- it "must include Ronin::DB::Model" do
14
- expect(described_class).to include(Ronin::DB::Model)
15
- end
16
-
17
- it "must include Ronin::DB::Model::HasUniqueName" do
18
- expect(described_class).to include(Ronin::DB::Model::HasUniqueName)
19
- end
20
-
21
- describe "validations" do
22
- describe "name" do
23
- it "must requier a name" do
24
- arch = described_class.new(endian: endian, word_size: word_size)
25
- expect(arch).to_not be_valid
26
- expect(arch.errors[:name]).to eq(
27
- ["can't be blank"]
28
- )
29
-
30
- arch = described_class.new(
31
- name: name,
32
- endian: endian,
33
- word_size: word_size
34
- )
35
- expect(arch).to be_valid
36
- end
37
- end
38
-
39
- describe "endian" do
40
- subject do
41
- described_class.new(
42
- name: name,
43
- word_size: word_size
44
- )
45
- end
46
-
47
- it "must accept :little" do
48
- arch = described_class.new(
49
- name: name,
50
- endian: :little,
51
- word_size: word_size
52
- )
53
- expect(arch).to be_valid
54
- end
55
-
56
- it "must accept :big" do
57
- arch = described_class.new(
58
- name: name,
59
- endian: :big,
60
- word_size: word_size
61
- )
62
- expect(arch).to be_valid
63
- end
64
-
65
- context "otherwise" do
66
- let(:endian) { :foo }
67
-
68
- it do
69
- expect {
70
- described_class.new(
71
- name: name,
72
- endian: endian,
73
- word_size: word_size
74
- )
75
- }.to raise_error(ArgumentError,"'#{endian}' is not a valid endian")
76
- end
77
- end
78
- end
79
-
80
- describe "word_size" do
81
- it "must require a word_size" do
82
- arch = described_class.new(name: name, endian: endian)
83
- expect(arch).to_not be_valid
84
- expect(arch.errors[:word_size]).to include("can't be blank")
85
-
86
- arch = described_class.new(
87
- name: name,
88
- endian: endian,
89
- word_size: word_size
90
- )
91
- expect(arch).to be_valid
92
- end
93
-
94
- it "must accept a word_size of 4" do
95
- arch = described_class.new(
96
- name: name,
97
- endian: endian,
98
- word_size: 4
99
- )
100
- expect(arch).to be_valid
101
- end
102
-
103
- it "must accept a word_size of 8" do
104
- arch = described_class.new(
105
- name: name,
106
- endian: endian,
107
- word_size: 8
108
- )
109
- expect(arch).to be_valid
110
- end
111
-
112
- context "otherwise" do
113
- let(:word_size) { 3 }
114
-
115
- it do
116
- arch = described_class.new(
117
- name: name,
118
- endian: endian,
119
- word_size: word_size
120
- )
121
- expect(arch).to_not be_valid
122
- expect(arch.errors[:word_size]).to eq(
123
- ['is not included in the list']
124
- )
125
- end
126
- end
127
- end
128
- end
129
-
130
- describe ".x86" do
131
- subject { described_class.x86 }
132
-
133
- it "should return the x86 architecture" do
134
- expect(subject).to be_kind_of(described_class)
135
- expect(subject.name).to eq('x86')
136
- end
137
- end
138
-
139
- describe ".i686" do
140
- subject { described_class.i686 }
141
-
142
- it "should return the i686 architecture" do
143
- expect(subject).to be_kind_of(described_class)
144
- expect(subject.name).to eq('i686')
145
- end
146
- end
147
-
148
- describe ".x86_64" do
149
- subject { described_class.x86_64 }
150
-
151
- it "should return the x86-64 architecture" do
152
- expect(subject).to be_kind_of(described_class)
153
- expect(subject.name).to eq('x86-64')
154
- end
155
- end
156
-
157
- describe ".ppc" do
158
- subject { described_class.ppc }
159
-
160
- it "should return the PPC architecture" do
161
- expect(subject).to be_kind_of(described_class)
162
- expect(subject.name).to eq('PPC')
163
- end
164
- end
165
-
166
- describe ".ppc64" do
167
- subject { described_class.ppc64 }
168
-
169
- it "should return the PPC64 architecture" do
170
- expect(subject).to be_kind_of(described_class)
171
- expect(subject.name).to eq('PPC64')
172
- end
173
- end
174
-
175
- describe ".mips" do
176
- subject { described_class.mips }
177
-
178
- it "should return the MIPS architecture" do
179
- expect(subject).to be_kind_of(described_class)
180
- expect(subject.name).to eq('MIPS')
181
- end
182
- end
183
-
184
- describe ".mips_le" do
185
- subject { described_class.mips_le }
186
-
187
- it "should return the MIPS (Little-Endian) architecture" do
188
- expect(subject).to be_kind_of(described_class)
189
- expect(subject.name).to eq('MIPS (Little-Endian)')
190
- end
191
- end
192
-
193
- describe ".mips_be" do
194
- subject { described_class.mips_be }
195
-
196
- it "should return the MIPS (Big-Endian) architecture" do
197
- expect(subject).to be_kind_of(described_class)
198
- expect(subject.name).to eq('MIPS (Big-Endian)')
199
- end
200
- end
201
-
202
- describe ".arm" do
203
- subject { described_class.arm }
204
-
205
- it "should return the ARM architecture" do
206
- expect(subject).to be_kind_of(described_class)
207
- expect(subject.name).to eq('ARM')
208
- end
209
- end
210
-
211
- describe ".arm_le" do
212
- subject { described_class.arm_le }
213
-
214
- it "should return the ARM (Little-Endian) architecture" do
215
- expect(subject).to be_kind_of(described_class)
216
- expect(subject.name).to eq('ARM (Little-Endian)')
217
- end
218
- end
219
-
220
- describe ".arm_be" do
221
- subject { described_class.arm_be }
222
-
223
- it "should return the ARM (Big-Endian) architecture" do
224
- expect(subject).to be_kind_of(described_class)
225
- expect(subject.name).to eq('ARM (Big-Endian)')
226
- end
227
- end
228
- end