ronin-db 0.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) 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 +12 -0
  10. data/Gemfile +39 -0
  11. data/README.md +272 -0
  12. data/Rakefile +76 -0
  13. data/bin/ronin-db +35 -0
  14. data/gemspec.yml +46 -0
  15. data/lib/ronin/db/cli/command.rb +37 -0
  16. data/lib/ronin/db/cli/commands/add.rb +206 -0
  17. data/lib/ronin/db/cli/commands/asn.rb +218 -0
  18. data/lib/ronin/db/cli/commands/creds.rb +80 -0
  19. data/lib/ronin/db/cli/commands/edit.rb +58 -0
  20. data/lib/ronin/db/cli/commands/emails.rb +90 -0
  21. data/lib/ronin/db/cli/commands/hosts.rb +100 -0
  22. data/lib/ronin/db/cli/commands/ips.rb +100 -0
  23. data/lib/ronin/db/cli/commands/irb.rb +81 -0
  24. data/lib/ronin/db/cli/commands/list.rb +124 -0
  25. data/lib/ronin/db/cli/commands/migrate.rb +75 -0
  26. data/lib/ronin/db/cli/commands/remove.rb +69 -0
  27. data/lib/ronin/db/cli/commands/urls.rb +170 -0
  28. data/lib/ronin/db/cli/database_command.rb +71 -0
  29. data/lib/ronin/db/cli/model_command.rb +202 -0
  30. data/lib/ronin/db/cli/modifiable.rb +141 -0
  31. data/lib/ronin/db/cli/resources_command.rb +120 -0
  32. data/lib/ronin/db/cli/ruby_shell.rb +51 -0
  33. data/lib/ronin/db/cli/uri_methods.rb +97 -0
  34. data/lib/ronin/db/cli.rb +38 -0
  35. data/lib/ronin/db/config_file.rb +132 -0
  36. data/lib/ronin/db/exceptions.rb +26 -0
  37. data/lib/ronin/db/home.rb +36 -0
  38. data/lib/ronin/db/root.rb +28 -0
  39. data/lib/ronin/db/version.rb +26 -0
  40. data/lib/ronin/db.rb +123 -0
  41. data/man/ronin-db-add.1 +99 -0
  42. data/man/ronin-db-add.1.md +75 -0
  43. data/man/ronin-db-asn.1 +79 -0
  44. data/man/ronin-db-asn.1.md +59 -0
  45. data/man/ronin-db-creds.1 +78 -0
  46. data/man/ronin-db-creds.1.md +58 -0
  47. data/man/ronin-db-edit.1 +48 -0
  48. data/man/ronin-db-edit.1.md +36 -0
  49. data/man/ronin-db-emails.1 +82 -0
  50. data/man/ronin-db-emails.1.md +61 -0
  51. data/man/ronin-db-hosts.1 +86 -0
  52. data/man/ronin-db-hosts.1.md +64 -0
  53. data/man/ronin-db-ips.1 +90 -0
  54. data/man/ronin-db-ips.1.md +67 -0
  55. data/man/ronin-db-irb.1 +61 -0
  56. data/man/ronin-db-irb.1.md +46 -0
  57. data/man/ronin-db-list.1 +58 -0
  58. data/man/ronin-db-list.1.md +44 -0
  59. data/man/ronin-db-migrate.1 +44 -0
  60. data/man/ronin-db-migrate.1.md +32 -0
  61. data/man/ronin-db-remove.1 +55 -0
  62. data/man/ronin-db-remove.1.md +42 -0
  63. data/man/ronin-db-urls.1 +98 -0
  64. data/man/ronin-db-urls.1.md +73 -0
  65. data/ronin-db.gemspec +78 -0
  66. data/spec/cli/commands/add_spec.rb +220 -0
  67. data/spec/cli/commands/edit_spec.rb +12 -0
  68. data/spec/cli/commands/irb_spec.rb +26 -0
  69. data/spec/cli/database_command_spec.rb +53 -0
  70. data/spec/cli/model_command_spec.rb +237 -0
  71. data/spec/cli/ruby_shell_spec.rb +14 -0
  72. data/spec/cli/uri_methods_spec.rb +190 -0
  73. data/spec/spec_helper.rb +15 -0
  74. metadata +200 -0
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ require 'ronin/db/cli/ruby_shell'
3
+
4
+ describe Ronin::DB::CLI::RubyShell do
5
+ describe "#initialize" do
6
+ it "must default #name to 'ronin-db'" do
7
+ expect(subject.name).to eq('ronin-db')
8
+ end
9
+
10
+ it "must default #context to Ronin::DB" do
11
+ expect(subject.context).to be(Ronin::DB)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,190 @@
1
+ require 'spec_helper'
2
+ require 'ronin/db/cli/uri_methods'
3
+
4
+ describe Ronin::DB::CLI::URIMethods do
5
+ subject do
6
+ obj = Object.new
7
+ obj.extend described_class
8
+ obj
9
+ end
10
+
11
+ describe "#normalize_adapter" do
12
+ context "when given 'sqlite'" do
13
+ it "must return 'sqlite3'" do
14
+ expect(subject.normalize_adapter('sqlite')).to eq('sqlite3')
15
+ end
16
+ end
17
+
18
+ context "when given 'sqlite3'" do
19
+ it "must return 'sqlite3'" do
20
+ expect(subject.normalize_adapter('sqlite3')).to eq('sqlite3')
21
+ end
22
+ end
23
+
24
+ context "when given 'mysql'" do
25
+ it "must return 'mysql2'" do
26
+ expect(subject.normalize_adapter('mysql')).to eq('mysql2')
27
+ end
28
+ end
29
+
30
+ context "when given 'mysql2'" do
31
+ it "must return 'mysql2'" do
32
+ expect(subject.normalize_adapter('mysql2')).to eq('mysql2')
33
+ end
34
+ end
35
+
36
+ context "when given 'postgresql'" do
37
+ it "must return 'postgresql'" do
38
+ expect(subject.normalize_adapter('postgresql')).to eq('postgresql')
39
+ end
40
+ end
41
+
42
+ context "when given 'postgres'" do
43
+ it "must return 'postgresql'" do
44
+ expect(subject.normalize_adapter('postgres')).to eq('postgresql')
45
+ end
46
+ end
47
+
48
+ context "when given 'psql'" do
49
+ it "must return 'postgresql'" do
50
+ expect(subject.normalize_adapter('psql')).to eq('postgresql')
51
+ end
52
+ end
53
+
54
+ context "when given 'pg'" do
55
+ it "must return 'postgresql'" do
56
+ expect(subject.normalize_adapter('pg')).to eq('postgresql')
57
+ end
58
+ end
59
+ end
60
+
61
+ describe "#normalize_sqlite3_path" do
62
+ context "when given a relative path" do
63
+ let(:path) { 'file.sqlite3' }
64
+
65
+ it "must return an absolute path" do
66
+ expect(subject.normalize_sqlite3_path(path)).to eq(
67
+ File.expand_path(path)
68
+ )
69
+ end
70
+ end
71
+
72
+ context "when given an absolute path" do
73
+ let(:path) { '/path/to/file.sqlite3' }
74
+
75
+ it "must return the absolute path" do
76
+ expect(subject.normalize_sqlite3_path(path)).to eq(path)
77
+ end
78
+ end
79
+
80
+ context "when given ':memory:'" do
81
+ let(:path) { ':memory:' }
82
+
83
+ it "must return ':memory:'" do
84
+ expect(subject.normalize_sqlite3_path(path)).to eq(path)
85
+ end
86
+ end
87
+ end
88
+
89
+ describe "#parse_uri" do
90
+ [:sqlite3, :sqlite].each do |adapter|
91
+ let(:adapter) { adapter }
92
+
93
+ context "when given '#{adapter}:path'" do
94
+ let(:path) { "db.sqlite3" }
95
+ let(:uri) { "#{adapter}:#{path}" }
96
+
97
+ it "must return {adapter: 'sqlite3', database: absolute_path}" do
98
+ expect(subject.parse_uri(uri)).to eq(
99
+ {
100
+ adapter: 'sqlite3',
101
+ database: File.expand_path(path)
102
+ }
103
+ )
104
+ end
105
+ end
106
+
107
+ context "when given '#{adapter}:/path'" do
108
+ let(:path) { "/db.sqlite3" }
109
+ let(:uri) { "#{adapter}:#{path}" }
110
+
111
+ it "must return {adapter: 'sqlite3', database: '/path'}" do
112
+ expect(subject.parse_uri(uri)).to eq(
113
+ {
114
+ adapter: 'sqlite3',
115
+ database: path
116
+ }
117
+ )
118
+ end
119
+ end
120
+
121
+ context "when given '#{adapter}::memory:'" do
122
+ let(:path) { ":memory:" }
123
+ let(:uri) { "#{adapter}:#{path}" }
124
+
125
+ it "must return {adapter: 'sqlite3', database: ':memory:'}" do
126
+ expect(subject.parse_uri(uri)).to eq(
127
+ {
128
+ adapter: 'sqlite3',
129
+ database: path
130
+ }
131
+ )
132
+ end
133
+ end
134
+ end
135
+
136
+ [:mysql2, :mysql].each do |adapter|
137
+ context "when given '#{adapter}://user:password@host:port/database'" do
138
+ let(:adapter) { adapter }
139
+ let(:user) { 'foo' }
140
+ let(:password) { 'secret' }
141
+ let(:host) { 'example.com' }
142
+ let(:port) { 1234 }
143
+ let(:database) { 'test' }
144
+ let(:uri) do
145
+ "#{adapter}://#{user}:#{password}@#{host}:#{port}/#{database}"
146
+ end
147
+
148
+ it "must return {adapter: 'mysql2', username: '...', password: '...', host: '...', port: ..., database: 'database'}" do
149
+ expect(subject.parse_uri(uri)).to eq(
150
+ {
151
+ adapter: 'mysql2',
152
+ username: user,
153
+ password: password,
154
+ host: host,
155
+ port: port,
156
+ database: database
157
+ }
158
+ )
159
+ end
160
+ end
161
+ end
162
+
163
+ [:postgresql, :postgres, :psql, :pg].each do |adapter|
164
+ context "when given '#{adapter}://user:password@host:port/database'" do
165
+ let(:adapter) { adapter }
166
+ let(:user) { 'foo' }
167
+ let(:password) { 'secret' }
168
+ let(:host) { 'example.com' }
169
+ let(:port) { 1234 }
170
+ let(:database) { 'test' }
171
+ let(:uri) do
172
+ "#{adapter}://#{user}:#{password}@#{host}:#{port}/#{database}"
173
+ end
174
+
175
+ it "must return {adapter: 'postgresql', username: '...', password: '...', host: '...', port: ..., database: 'database'}" do
176
+ expect(subject.parse_uri(uri)).to eq(
177
+ {
178
+ adapter: 'postgresql',
179
+ username: user,
180
+ password: password,
181
+ host: host,
182
+ port: port,
183
+ database: database
184
+ }
185
+ )
186
+ end
187
+ end
188
+ end
189
+ end
190
+ end
@@ -0,0 +1,15 @@
1
+ require 'rspec'
2
+ require 'simplecov'
3
+ SimpleCov.start
4
+
5
+ require 'active_record'
6
+ ActiveRecord::Base.establish_connection(
7
+ adapter: 'sqlite3', database: ':memory:'
8
+ )
9
+
10
+ RSpec.configure do |specs|
11
+ specs.before(:suite) do
12
+ require 'ronin/db/migrations'
13
+ Ronin::DB::Migrations.migrate
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,200 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ronin-db
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.beta1
5
+ platform: ruby
6
+ authors:
7
+ - Postmodern
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-01-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sqlite
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ronin-db-activerecord
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.0.beta1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.0.beta1
41
+ - !ruby/object:Gem::Dependency
42
+ name: ronin-support
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.0.beta1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0.beta1
55
+ - !ruby/object:Gem::Dependency
56
+ name: ronin-core
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.0.beta1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.0.beta1
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ description: |
84
+ ronin-db is a database library for managing and querying security data.
85
+ ronin-db provides common ORM models for interacting with the database's SQL
86
+ tables and querying/storing security data, such as URLs, email addresses,
87
+ host names, IPs, ports, etc. ronin-db also provides CLI commands for managing
88
+ the database(s).
89
+ email: postmodern.mod3@gmail.com
90
+ executables:
91
+ - ronin-db
92
+ extensions: []
93
+ extra_rdoc_files:
94
+ - COPYING.txt
95
+ - ChangeLog.md
96
+ - README.md
97
+ files:
98
+ - ".document"
99
+ - ".github/workflows/ruby.yml"
100
+ - ".gitignore"
101
+ - ".rspec"
102
+ - ".ruby-version"
103
+ - ".yardopts"
104
+ - COPYING.txt
105
+ - ChangeLog.md
106
+ - Gemfile
107
+ - README.md
108
+ - Rakefile
109
+ - bin/ronin-db
110
+ - gemspec.yml
111
+ - lib/ronin/db.rb
112
+ - lib/ronin/db/cli.rb
113
+ - lib/ronin/db/cli/command.rb
114
+ - lib/ronin/db/cli/commands/add.rb
115
+ - lib/ronin/db/cli/commands/asn.rb
116
+ - lib/ronin/db/cli/commands/creds.rb
117
+ - lib/ronin/db/cli/commands/edit.rb
118
+ - lib/ronin/db/cli/commands/emails.rb
119
+ - lib/ronin/db/cli/commands/hosts.rb
120
+ - lib/ronin/db/cli/commands/ips.rb
121
+ - lib/ronin/db/cli/commands/irb.rb
122
+ - lib/ronin/db/cli/commands/list.rb
123
+ - lib/ronin/db/cli/commands/migrate.rb
124
+ - lib/ronin/db/cli/commands/remove.rb
125
+ - lib/ronin/db/cli/commands/urls.rb
126
+ - lib/ronin/db/cli/database_command.rb
127
+ - lib/ronin/db/cli/model_command.rb
128
+ - lib/ronin/db/cli/modifiable.rb
129
+ - lib/ronin/db/cli/resources_command.rb
130
+ - lib/ronin/db/cli/ruby_shell.rb
131
+ - lib/ronin/db/cli/uri_methods.rb
132
+ - lib/ronin/db/config_file.rb
133
+ - lib/ronin/db/exceptions.rb
134
+ - lib/ronin/db/home.rb
135
+ - lib/ronin/db/root.rb
136
+ - lib/ronin/db/version.rb
137
+ - man/ronin-db-add.1
138
+ - man/ronin-db-add.1.md
139
+ - man/ronin-db-asn.1
140
+ - man/ronin-db-asn.1.md
141
+ - man/ronin-db-creds.1
142
+ - man/ronin-db-creds.1.md
143
+ - man/ronin-db-edit.1
144
+ - man/ronin-db-edit.1.md
145
+ - man/ronin-db-emails.1
146
+ - man/ronin-db-emails.1.md
147
+ - man/ronin-db-hosts.1
148
+ - man/ronin-db-hosts.1.md
149
+ - man/ronin-db-ips.1
150
+ - man/ronin-db-ips.1.md
151
+ - man/ronin-db-irb.1
152
+ - man/ronin-db-irb.1.md
153
+ - man/ronin-db-list.1
154
+ - man/ronin-db-list.1.md
155
+ - man/ronin-db-migrate.1
156
+ - man/ronin-db-migrate.1.md
157
+ - man/ronin-db-remove.1
158
+ - man/ronin-db-remove.1.md
159
+ - man/ronin-db-urls.1
160
+ - man/ronin-db-urls.1.md
161
+ - ronin-db.gemspec
162
+ - spec/cli/commands/add_spec.rb
163
+ - spec/cli/commands/edit_spec.rb
164
+ - spec/cli/commands/irb_spec.rb
165
+ - spec/cli/database_command_spec.rb
166
+ - spec/cli/model_command_spec.rb
167
+ - spec/cli/ruby_shell_spec.rb
168
+ - spec/cli/uri_methods_spec.rb
169
+ - spec/spec_helper.rb
170
+ homepage: https://ronin-rb.dev
171
+ licenses:
172
+ - LGPL-3.0
173
+ metadata: {}
174
+ post_install_message:
175
+ rdoc_options: []
176
+ require_paths:
177
+ - lib
178
+ required_ruby_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: 3.0.0
183
+ required_rubygems_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ requirements: []
189
+ rubygems_version: 3.3.26
190
+ signing_key:
191
+ specification_version: 4
192
+ summary: A common database library for managing and querying security data
193
+ test_files:
194
+ - spec/cli/commands/add_spec.rb
195
+ - spec/cli/commands/edit_spec.rb
196
+ - spec/cli/commands/irb_spec.rb
197
+ - spec/cli/database_command_spec.rb
198
+ - spec/cli/model_command_spec.rb
199
+ - spec/cli/ruby_shell_spec.rb
200
+ - spec/cli/uri_methods_spec.rb