ronin-db 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 +12 -0
- data/Gemfile +39 -0
- data/README.md +272 -0
- data/Rakefile +76 -0
- data/bin/ronin-db +35 -0
- data/gemspec.yml +46 -0
- data/lib/ronin/db/cli/command.rb +37 -0
- data/lib/ronin/db/cli/commands/add.rb +206 -0
- data/lib/ronin/db/cli/commands/asn.rb +218 -0
- data/lib/ronin/db/cli/commands/creds.rb +80 -0
- data/lib/ronin/db/cli/commands/edit.rb +58 -0
- data/lib/ronin/db/cli/commands/emails.rb +90 -0
- data/lib/ronin/db/cli/commands/hosts.rb +100 -0
- data/lib/ronin/db/cli/commands/ips.rb +100 -0
- data/lib/ronin/db/cli/commands/irb.rb +81 -0
- data/lib/ronin/db/cli/commands/list.rb +124 -0
- data/lib/ronin/db/cli/commands/migrate.rb +75 -0
- data/lib/ronin/db/cli/commands/remove.rb +69 -0
- data/lib/ronin/db/cli/commands/urls.rb +170 -0
- data/lib/ronin/db/cli/database_command.rb +71 -0
- data/lib/ronin/db/cli/model_command.rb +202 -0
- data/lib/ronin/db/cli/modifiable.rb +141 -0
- data/lib/ronin/db/cli/resources_command.rb +120 -0
- data/lib/ronin/db/cli/ruby_shell.rb +51 -0
- data/lib/ronin/db/cli/uri_methods.rb +97 -0
- data/lib/ronin/db/cli.rb +38 -0
- data/lib/ronin/db/config_file.rb +132 -0
- data/lib/ronin/db/exceptions.rb +26 -0
- data/lib/ronin/db/home.rb +36 -0
- data/lib/ronin/db/root.rb +28 -0
- data/lib/ronin/db/version.rb +26 -0
- data/lib/ronin/db.rb +123 -0
- data/man/ronin-db-add.1 +99 -0
- data/man/ronin-db-add.1.md +75 -0
- data/man/ronin-db-asn.1 +79 -0
- data/man/ronin-db-asn.1.md +59 -0
- data/man/ronin-db-creds.1 +78 -0
- data/man/ronin-db-creds.1.md +58 -0
- data/man/ronin-db-edit.1 +48 -0
- data/man/ronin-db-edit.1.md +36 -0
- data/man/ronin-db-emails.1 +82 -0
- data/man/ronin-db-emails.1.md +61 -0
- data/man/ronin-db-hosts.1 +86 -0
- data/man/ronin-db-hosts.1.md +64 -0
- data/man/ronin-db-ips.1 +90 -0
- data/man/ronin-db-ips.1.md +67 -0
- data/man/ronin-db-irb.1 +61 -0
- data/man/ronin-db-irb.1.md +46 -0
- data/man/ronin-db-list.1 +58 -0
- data/man/ronin-db-list.1.md +44 -0
- data/man/ronin-db-migrate.1 +44 -0
- data/man/ronin-db-migrate.1.md +32 -0
- data/man/ronin-db-remove.1 +55 -0
- data/man/ronin-db-remove.1.md +42 -0
- data/man/ronin-db-urls.1 +98 -0
- data/man/ronin-db-urls.1.md +73 -0
- data/ronin-db.gemspec +78 -0
- data/spec/cli/commands/add_spec.rb +220 -0
- data/spec/cli/commands/edit_spec.rb +12 -0
- data/spec/cli/commands/irb_spec.rb +26 -0
- data/spec/cli/database_command_spec.rb +53 -0
- data/spec/cli/model_command_spec.rb +237 -0
- data/spec/cli/ruby_shell_spec.rb +14 -0
- data/spec/cli/uri_methods_spec.rb +190 -0
- data/spec/spec_helper.rb +15 -0
- metadata +200 -0
data/gemspec.yml
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
name: ronin-db
|
2
|
+
summary: A common database library for managing and querying security data
|
3
|
+
description: |
|
4
|
+
ronin-db is a database library for managing and querying security data.
|
5
|
+
ronin-db provides common ORM models for interacting with the database's SQL
|
6
|
+
tables and querying/storing security data, such as URLs, email addresses,
|
7
|
+
host names, IPs, ports, etc. ronin-db also provides CLI commands for managing
|
8
|
+
the database(s).
|
9
|
+
|
10
|
+
license: LGPL-3.0
|
11
|
+
authors: Postmodern
|
12
|
+
email: postmodern.mod3@gmail.com
|
13
|
+
homepage: https://ronin-rb.dev
|
14
|
+
has_yard: true
|
15
|
+
|
16
|
+
generated_files:
|
17
|
+
- man/ronin-db-add.1
|
18
|
+
- man/ronin-db-asn.1
|
19
|
+
- man/ronin-db-creds.1
|
20
|
+
- man/ronin-db-emails.1
|
21
|
+
- man/ronin-db-hosts.1
|
22
|
+
- man/ronin-db-ips.1
|
23
|
+
- man/ronin-db-irb.1
|
24
|
+
- man/ronin-db-edit.1
|
25
|
+
- man/ronin-db-irb.1
|
26
|
+
- man/ronin-db-list.1
|
27
|
+
- man/ronin-db-migrate.1
|
28
|
+
- man/ronin-db-remove.1
|
29
|
+
- man/ronin-db-urls.1
|
30
|
+
|
31
|
+
required_ruby_version: ">= 3.0.0"
|
32
|
+
|
33
|
+
ruby_dependencies:
|
34
|
+
sqlite: ~> 1.0
|
35
|
+
|
36
|
+
jruby_dependencies:
|
37
|
+
activerecord-jdbcsqlite3-adapter: ~> 70.0.pre
|
38
|
+
|
39
|
+
dependencies:
|
40
|
+
# Ronin dependencies:
|
41
|
+
ronin-db-activerecord: ~> 0.1.0.beta1
|
42
|
+
ronin-support: ~> 1.0.0.beta1
|
43
|
+
ronin-core: ~> 0.1.0.beta1
|
44
|
+
|
45
|
+
development_dependencies:
|
46
|
+
bundler: ~> 2.0
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-db - A common database library for managing and querying security data.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2006-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-db 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 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. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'ronin/db/root'
|
22
|
+
|
23
|
+
require 'ronin/core/cli/command'
|
24
|
+
|
25
|
+
module Ronin
|
26
|
+
module DB
|
27
|
+
class CLI
|
28
|
+
class Command < Core::CLI::Command
|
29
|
+
|
30
|
+
man_dir File.join(ROOT,'man')
|
31
|
+
|
32
|
+
bug_report_url 'https://github.com/ronin-rb/ronin-db/issues/new'
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,206 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-db - A common database library for managing and querying security data.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2006-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-db 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 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. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'ronin/db/cli/command'
|
22
|
+
require 'ronin/db/cli/uri_methods'
|
23
|
+
require 'ronin/db/config_file'
|
24
|
+
|
25
|
+
require 'command_kit/options/verbose'
|
26
|
+
require 'command_kit/printing'
|
27
|
+
require 'command_kit/printing/indent'
|
28
|
+
|
29
|
+
module Ronin
|
30
|
+
module DB
|
31
|
+
class CLI
|
32
|
+
module Commands
|
33
|
+
#
|
34
|
+
# Adds an existing database to the `~/.config/ronin-db/database.yml`
|
35
|
+
# configuration file.
|
36
|
+
#
|
37
|
+
# ## Usage
|
38
|
+
#
|
39
|
+
# ronin-db add [options] NAME [URI]
|
40
|
+
#
|
41
|
+
# ## Options
|
42
|
+
#
|
43
|
+
# -A sqlite3|mysql2|postgresql|...,
|
44
|
+
# --adapter The database adapter
|
45
|
+
# --sqlite3 FILE Alias for --adapter sqlite3 --database FILE
|
46
|
+
# --mysql2 Alias for --adapter mysql2
|
47
|
+
# --postgresql Alias for --adapter postgresql
|
48
|
+
# -H, --host HOST The host of the database to add
|
49
|
+
# -p, --port PORT The port of the database to add
|
50
|
+
# -u, --username USER The user to authenticate with for the database
|
51
|
+
# -P, --password PASSWORD The password to authenticate with for the database
|
52
|
+
# --read-password Reads the database password from stdin
|
53
|
+
# -D, --database NAME|PATH The database name or path (for sqlite3)
|
54
|
+
# -h, --help Print help information
|
55
|
+
#
|
56
|
+
# ## Arguments
|
57
|
+
#
|
58
|
+
# NAME The name of the database to add.
|
59
|
+
# [URI] The optional URI to the database.
|
60
|
+
#
|
61
|
+
class Add < Command
|
62
|
+
|
63
|
+
include URIMethods
|
64
|
+
|
65
|
+
usage '[options] NAME [URI]'
|
66
|
+
|
67
|
+
option :adapter, short: '-A',
|
68
|
+
value: {
|
69
|
+
type: String,
|
70
|
+
usage: 'sqlite3|mysql2|postgresql|...'
|
71
|
+
},
|
72
|
+
desc: 'The database adapter' do |adapter|
|
73
|
+
@config[:adapter] = normalize_adapter(adapter)
|
74
|
+
end
|
75
|
+
|
76
|
+
option :sqlite3, value: {
|
77
|
+
type: String,
|
78
|
+
usage: 'FILE'
|
79
|
+
},
|
80
|
+
desc: 'Alias for --adapter sqlite3 --database FILE' do |file|
|
81
|
+
@config[:adapter] = 'sqlite3'
|
82
|
+
@config[:database] = normalize_sqlite3_path(file)
|
83
|
+
end
|
84
|
+
|
85
|
+
option :mysql2, desc: 'Alias for --adapter mysql2' do
|
86
|
+
@config[:adapter] = 'mysql2'
|
87
|
+
end
|
88
|
+
|
89
|
+
option :postgresql, desc: 'Alias for --adapter postgresql' do
|
90
|
+
@config[:adapter] = 'postgresql'
|
91
|
+
end
|
92
|
+
|
93
|
+
option :host, short: '-H',
|
94
|
+
value: {
|
95
|
+
type: String,
|
96
|
+
usage: 'HOST'
|
97
|
+
},
|
98
|
+
desc: 'The host of the database to add' do |host|
|
99
|
+
@config[:host] = host
|
100
|
+
end
|
101
|
+
|
102
|
+
option :port, short: '-p',
|
103
|
+
value: {
|
104
|
+
type: Integer,
|
105
|
+
usage: 'PORT'
|
106
|
+
},
|
107
|
+
desc: 'The port of the database to add' do |port|
|
108
|
+
@config[:port] = port
|
109
|
+
end
|
110
|
+
|
111
|
+
option :username, short: '-u',
|
112
|
+
value: {
|
113
|
+
type: String,
|
114
|
+
usage: 'USER'
|
115
|
+
},
|
116
|
+
desc: 'The user to authenticate with for the database' do |user|
|
117
|
+
@config[:username] = user
|
118
|
+
end
|
119
|
+
|
120
|
+
option :password, short: '-P',
|
121
|
+
value: {
|
122
|
+
type: String,
|
123
|
+
usage: 'PASSWORD'
|
124
|
+
},
|
125
|
+
desc: 'The password to authenticate with for the database' do |password|
|
126
|
+
@config[:password] = password
|
127
|
+
end
|
128
|
+
|
129
|
+
option :read_password, desc: 'Reads the database password from stdin'
|
130
|
+
|
131
|
+
option :database, short: '-D',
|
132
|
+
value: {
|
133
|
+
type: String,
|
134
|
+
usage: 'NAME|PATH'
|
135
|
+
},
|
136
|
+
desc: 'The database name or path (for sqlite3)' do |database|
|
137
|
+
@config[:database] = database
|
138
|
+
end
|
139
|
+
|
140
|
+
argument :name, desc: 'The name of the database to add'
|
141
|
+
|
142
|
+
argument :uri, required: false,
|
143
|
+
desc: 'The optional URI to the database'
|
144
|
+
|
145
|
+
description 'Adds a pre-existing database to ronin-db'
|
146
|
+
|
147
|
+
man_page 'ronin-db-add.1'
|
148
|
+
|
149
|
+
# The database configuration Hash to add.
|
150
|
+
#
|
151
|
+
# @return [Hash{Symbol => Object}]
|
152
|
+
attr_reader :config
|
153
|
+
|
154
|
+
#
|
155
|
+
# Initializes the command.
|
156
|
+
#
|
157
|
+
# @param [Hash{Symbol => Object}] kwargs
|
158
|
+
# Additional keyword arguments.
|
159
|
+
#
|
160
|
+
def initialize(**kwargs)
|
161
|
+
super(**kwargs)
|
162
|
+
|
163
|
+
@config = {}
|
164
|
+
end
|
165
|
+
|
166
|
+
#
|
167
|
+
# Runs the `ronin-db add` command.
|
168
|
+
#
|
169
|
+
def run(name,uri=nil)
|
170
|
+
@config = parse_uri(uri) if uri
|
171
|
+
|
172
|
+
read_password if options[:read_password]
|
173
|
+
validate_config!
|
174
|
+
|
175
|
+
ConfigFile.edit do |yaml|
|
176
|
+
yaml[name] = @config
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
#
|
181
|
+
# Reads the password from stdin and sets `config[:password]`.
|
182
|
+
#
|
183
|
+
def read_password
|
184
|
+
@config[:password] = ask_secret('Password')
|
185
|
+
end
|
186
|
+
|
187
|
+
#
|
188
|
+
# Validates the {#config} Hash.
|
189
|
+
#
|
190
|
+
def validate_config!
|
191
|
+
unless @config[:adapter]
|
192
|
+
print_error "must specify a URI or the --adapter option"
|
193
|
+
exit(1)
|
194
|
+
end
|
195
|
+
|
196
|
+
unless @config[:database]
|
197
|
+
print_error "must specify a URI or the --database option"
|
198
|
+
exit(1)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
@@ -0,0 +1,218 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-db - A common database library for managing and querying security data.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2006-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-db 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 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. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'ronin/db/cli/model_command'
|
22
|
+
require 'ronin/core/cli/logging'
|
23
|
+
|
24
|
+
require 'ronin/support/network/asn'
|
25
|
+
require 'ronin/support/network/asn/list'
|
26
|
+
|
27
|
+
module Ronin
|
28
|
+
module DB
|
29
|
+
class CLI
|
30
|
+
module Commands
|
31
|
+
#
|
32
|
+
# Queries and updates ASNs.
|
33
|
+
#
|
34
|
+
# ## Usage
|
35
|
+
#
|
36
|
+
# ronin-db asn [options]
|
37
|
+
#
|
38
|
+
# ## Options
|
39
|
+
#
|
40
|
+
# --db NAME The database to connect to (Default: default)
|
41
|
+
# --db-uri URI The database URI to connect to
|
42
|
+
# -v, --verbose Enables verbose output
|
43
|
+
# -n, --number INT Searches for all ASN records with the AS number
|
44
|
+
# -C XX|None|Uknown, Searches for all ASN records with the country code
|
45
|
+
# --country-code
|
46
|
+
# -N, --name NAME Searches for all ASN records with the matching name
|
47
|
+
# -I, --ip IP Queries the ASN record for the IP
|
48
|
+
# -4, --ipv4 Filter ASN records for only IPv4 ranges
|
49
|
+
# -6, --ipv6 Filter ASN records for only IPv6 ranges
|
50
|
+
# -u, --update Updates the ASN records
|
51
|
+
# -U, --url URI Overrides the default ASN list URL (Default: https://iptoasn.com/data/ip2asn-combined.tsv.gz)
|
52
|
+
# -f, --file FILE Overrides the default ASN list file (Default: /home/postmodern/.local/share/ronin/ronin-support/ip2asn-combined.tsv.gz)
|
53
|
+
# -h, --help Print help information
|
54
|
+
#
|
55
|
+
class Asn < ModelCommand
|
56
|
+
|
57
|
+
include Core::CLI::Logging
|
58
|
+
|
59
|
+
model_file 'ronin/db/asn'
|
60
|
+
model_name 'ASN'
|
61
|
+
|
62
|
+
option :number, short: '-n',
|
63
|
+
value: {
|
64
|
+
type: Integer,
|
65
|
+
},
|
66
|
+
desc: 'Searches for all ASN records with the AS number' do |number|
|
67
|
+
@query_method_calls << [:with_number, [number]]
|
68
|
+
end
|
69
|
+
|
70
|
+
option :country_code, short: '-C',
|
71
|
+
value: {
|
72
|
+
type: /[A-Z]{2}|None|Unknown/,
|
73
|
+
usage: 'XX|None|Uknown'
|
74
|
+
},
|
75
|
+
desc: 'Searches for all ASN records with the country code' do |cc|
|
76
|
+
@query_method_calls << [:with_country_code, [cc]]
|
77
|
+
end
|
78
|
+
|
79
|
+
option :name, short: '-N',
|
80
|
+
value: {
|
81
|
+
type: String,
|
82
|
+
usage: 'NAME'
|
83
|
+
},
|
84
|
+
desc: 'Searches for all ASN records with the matching name' do |name|
|
85
|
+
@query_method_calls << [:with_name, [name]]
|
86
|
+
end
|
87
|
+
|
88
|
+
option :ip, short: '-I',
|
89
|
+
value: {
|
90
|
+
type: String,
|
91
|
+
usage: 'IP'
|
92
|
+
},
|
93
|
+
desc: 'Queries the ASN record for the IP' do |ip|
|
94
|
+
@query_method_calls << [:containing_ip, [ip]]
|
95
|
+
end
|
96
|
+
|
97
|
+
option :ipv4, short: '-4',
|
98
|
+
desc: 'Filter ASN records for only IPv4 ranges' do
|
99
|
+
@query_method_calls << [:v4]
|
100
|
+
end
|
101
|
+
|
102
|
+
option :ipv6, short: '-6',
|
103
|
+
desc: 'Filter ASN records for only IPv6 ranges' do
|
104
|
+
@query_method_calls << [:v6]
|
105
|
+
end
|
106
|
+
|
107
|
+
option :update, short: '-u',
|
108
|
+
desc: 'Updates the ASN records'
|
109
|
+
|
110
|
+
option :url, short: '-U',
|
111
|
+
value: {
|
112
|
+
type: String,
|
113
|
+
usage: 'URI',
|
114
|
+
default: Support::Network::ASN::List::URL
|
115
|
+
},
|
116
|
+
desc: 'Overrides the default ASN list URL'
|
117
|
+
|
118
|
+
option :file, short: '-f',
|
119
|
+
value: {
|
120
|
+
type: String,
|
121
|
+
usage: 'FILE',
|
122
|
+
default: Support::Network::ASN::List::PATH
|
123
|
+
},
|
124
|
+
desc: 'Overrides the default ASN list file'
|
125
|
+
|
126
|
+
description 'Queries and updates ASNs'
|
127
|
+
|
128
|
+
man_page 'ronin-db-asn.1'
|
129
|
+
|
130
|
+
#
|
131
|
+
# Runs the `ronin-db asn` command.
|
132
|
+
#
|
133
|
+
def run
|
134
|
+
connect
|
135
|
+
|
136
|
+
if options[:update]
|
137
|
+
update
|
138
|
+
else
|
139
|
+
list
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
#
|
144
|
+
# Updates the ASN file and populates the database.
|
145
|
+
#
|
146
|
+
def update
|
147
|
+
if is_list_file_stale?
|
148
|
+
log_info "Updating ASN list file ..."
|
149
|
+
update_list_file
|
150
|
+
end
|
151
|
+
|
152
|
+
# clear the table instead of trying to diff the list with the table
|
153
|
+
model.delete_all
|
154
|
+
|
155
|
+
model.transaction do
|
156
|
+
parse_list_file do |record|
|
157
|
+
log_info "Importing #{record} ..."
|
158
|
+
import_asn_record(record)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
#
|
164
|
+
# Determines if the ASN list file is stale.
|
165
|
+
#
|
166
|
+
def is_list_file_stale?
|
167
|
+
Support::Network::ASN::List.stale?(options[:file])
|
168
|
+
end
|
169
|
+
|
170
|
+
#
|
171
|
+
# Updates the ASN list file.
|
172
|
+
#
|
173
|
+
def update_list_file
|
174
|
+
Support::Network::ASN::List.update(
|
175
|
+
path: options[:file],
|
176
|
+
url: options[:url]
|
177
|
+
)
|
178
|
+
end
|
179
|
+
|
180
|
+
#
|
181
|
+
# Parses the ASN list file.
|
182
|
+
#
|
183
|
+
# @yield [record]
|
184
|
+
#
|
185
|
+
# @yieldparam [Ronin::Support::Network::ASN::Record] record
|
186
|
+
#
|
187
|
+
# @return [Enumerator]
|
188
|
+
#
|
189
|
+
def parse_list_file(&block)
|
190
|
+
Support::Network::ASN::List.parse(options[:file],&block)
|
191
|
+
end
|
192
|
+
|
193
|
+
#
|
194
|
+
# Saves a parsed ASN record.
|
195
|
+
#
|
196
|
+
# @param [Ronin::Support::Network::ASN::Record] record
|
197
|
+
#
|
198
|
+
def import_asn_record(record)
|
199
|
+
asn = model.new(
|
200
|
+
version: if record.ipv6? then 6
|
201
|
+
else 4
|
202
|
+
end,
|
203
|
+
range_start: record.range.begin,
|
204
|
+
range_end: record.range.end,
|
205
|
+
number: record.number,
|
206
|
+
country_code: record.country_code,
|
207
|
+
name: record.name
|
208
|
+
)
|
209
|
+
|
210
|
+
# bypass validations since we're importing from a known good source
|
211
|
+
asn.save(validate: false)
|
212
|
+
end
|
213
|
+
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-db - A common database library for managing and querying security data.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2006-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-db 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 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. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'ronin/db/cli/model_command'
|
22
|
+
require 'ronin/db/cli/modifiable'
|
23
|
+
|
24
|
+
module Ronin
|
25
|
+
module DB
|
26
|
+
class CLI
|
27
|
+
module Commands
|
28
|
+
#
|
29
|
+
# Queries all credentials in the database.
|
30
|
+
#
|
31
|
+
# ## Usage
|
32
|
+
#
|
33
|
+
# ronin creds [options]
|
34
|
+
#
|
35
|
+
# ## Options
|
36
|
+
#
|
37
|
+
# --db NAME The database to connect to (Default: default)
|
38
|
+
# --db-uri URI The database URI to connect to
|
39
|
+
# -v, --verbose Enables verbose output
|
40
|
+
# --add VALUE Adds a value to the database
|
41
|
+
# --import FILE Imports the values from the FILE into the database
|
42
|
+
# --delete VALUE Deletes a value from the database
|
43
|
+
# --delete-all Deletes all values from the database
|
44
|
+
# -u, --user [USER] Username to search for.
|
45
|
+
# -p, --password [PASS] Password to search for.
|
46
|
+
#
|
47
|
+
class Creds < ModelCommand
|
48
|
+
|
49
|
+
include Modifiable
|
50
|
+
|
51
|
+
model_file 'ronin/db/credential'
|
52
|
+
model_name 'Credential'
|
53
|
+
|
54
|
+
option :user, short: '-u',
|
55
|
+
value: {
|
56
|
+
type: String,
|
57
|
+
usage: 'USER'
|
58
|
+
},
|
59
|
+
desc: 'Username to search for' do |user|
|
60
|
+
@query_method_calls << [:for_user, [user]]
|
61
|
+
end
|
62
|
+
|
63
|
+
option :password, short: '-P',
|
64
|
+
value: {
|
65
|
+
type: String,
|
66
|
+
usage: 'PASSWORD'
|
67
|
+
},
|
68
|
+
desc: 'Password to search for' do |password|
|
69
|
+
@query_method_calls << [:with_password, [password]]
|
70
|
+
end
|
71
|
+
|
72
|
+
description 'Queries all credentials in the database'
|
73
|
+
|
74
|
+
man_page 'ronin-db-creds.1'
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-db - A common database library for managing and querying security data.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2006-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-db 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 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. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'ronin/db/cli/command'
|
22
|
+
require 'ronin/db/config_file'
|
23
|
+
|
24
|
+
require 'command_kit/edit'
|
25
|
+
|
26
|
+
module Ronin
|
27
|
+
module DB
|
28
|
+
class CLI
|
29
|
+
module Commands
|
30
|
+
#
|
31
|
+
# Manually edits the `~/.config/ronin-db/database.yml` configuration
|
32
|
+
# file.
|
33
|
+
#
|
34
|
+
# ## Usage
|
35
|
+
#
|
36
|
+
# ronin-db edit [options]
|
37
|
+
#
|
38
|
+
# ## Options
|
39
|
+
#
|
40
|
+
# -h, --help Print help information
|
41
|
+
#
|
42
|
+
class Edit < Command
|
43
|
+
|
44
|
+
include CommandKit::Edit
|
45
|
+
|
46
|
+
description 'Manually edits the database.yml config'
|
47
|
+
|
48
|
+
man_page 'ronin-db-edit.1'
|
49
|
+
|
50
|
+
def run
|
51
|
+
edit ConfigFile::PATH
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|