ronin-wordlists 0.1.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.document +4 -0
- data/.github/workflows/ruby.yml +43 -0
- data/.gitignore +14 -0
- data/.rspec +1 -0
- data/.rubocop.yml +18 -0
- data/.ruby-version +1 -0
- data/.yardopts +1 -0
- data/COPYING.txt +165 -0
- data/ChangeLog.md +10 -0
- data/Gemfile +37 -0
- data/README.md +180 -0
- data/Rakefile +45 -0
- data/bin/ronin-wordlists +34 -0
- data/data/completions/ronin-wordlists +107 -0
- data/data/completions/ronin-wordlists.yml +7 -0
- data/data/wordlists.yml +260 -0
- data/gemspec.yml +40 -0
- data/lib/ronin/wordlists/cache_dir.rb +257 -0
- data/lib/ronin/wordlists/cli/command.rb +40 -0
- data/lib/ronin/wordlists/cli/commands/completion.rb +61 -0
- data/lib/ronin/wordlists/cli/commands/download.rb +109 -0
- data/lib/ronin/wordlists/cli/commands/list.rb +79 -0
- data/lib/ronin/wordlists/cli/commands/purge.rb +60 -0
- data/lib/ronin/wordlists/cli/commands/remove.rb +74 -0
- data/lib/ronin/wordlists/cli/commands/search.rb +145 -0
- data/lib/ronin/wordlists/cli/commands/update.rb +98 -0
- data/lib/ronin/wordlists/cli/wordlist_dir_option.rb +64 -0
- data/lib/ronin/wordlists/cli/wordlist_index.rb +178 -0
- data/lib/ronin/wordlists/cli/wordlist_option.rb +66 -0
- data/lib/ronin/wordlists/cli.rb +56 -0
- data/lib/ronin/wordlists/exceptions.rb +47 -0
- data/lib/ronin/wordlists/mixin.rb +106 -0
- data/lib/ronin/wordlists/root.rb +28 -0
- data/lib/ronin/wordlists/search_paths.rb +153 -0
- data/lib/ronin/wordlists/version.rb +26 -0
- data/lib/ronin/wordlists/wordlist_dir.rb +194 -0
- data/lib/ronin/wordlists/wordlist_file.rb +141 -0
- data/lib/ronin/wordlists/wordlist_metadata.rb +43 -0
- data/lib/ronin/wordlists/wordlist_repo.rb +167 -0
- data/lib/ronin/wordlists.rb +96 -0
- data/man/ronin-wordlists-completion.1 +76 -0
- data/man/ronin-wordlists-completion.1.md +78 -0
- data/man/ronin-wordlists-download.1 +47 -0
- data/man/ronin-wordlists-download.1.md +48 -0
- data/man/ronin-wordlists-list.1 +42 -0
- data/man/ronin-wordlists-list.1.md +44 -0
- data/man/ronin-wordlists-purge.1 +39 -0
- data/man/ronin-wordlists-purge.1.md +39 -0
- data/man/ronin-wordlists-remove.1 +43 -0
- data/man/ronin-wordlists-remove.1.md +44 -0
- data/man/ronin-wordlists-search.1 +37 -0
- data/man/ronin-wordlists-search.1.md +37 -0
- data/man/ronin-wordlists-update.1 +43 -0
- data/man/ronin-wordlists-update.1.md +44 -0
- data/man/ronin-wordlists.1 +65 -0
- data/man/ronin-wordlists.1.md +64 -0
- data/ronin-wordlists.gemspec +62 -0
- data/scripts/setup +58 -0
- metadata +154 -0
@@ -0,0 +1,178 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-wordlists - A library and tool for managing wordlists.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-wordlists 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-wordlists 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-wordlists. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'ronin/wordlists/root'
|
22
|
+
require 'ronin/wordlists/exceptions'
|
23
|
+
|
24
|
+
require 'yaml'
|
25
|
+
require 'set'
|
26
|
+
|
27
|
+
module Ronin
|
28
|
+
module Wordlists
|
29
|
+
class CLI
|
30
|
+
#
|
31
|
+
# Represents an index of known wordlists.
|
32
|
+
#
|
33
|
+
class WordlistIndex
|
34
|
+
|
35
|
+
include Enumerable
|
36
|
+
|
37
|
+
#
|
38
|
+
# Represents an entry in the wordlist index file.
|
39
|
+
#
|
40
|
+
class Entry
|
41
|
+
|
42
|
+
# The name of the wordlist.
|
43
|
+
#
|
44
|
+
# @return [String]
|
45
|
+
attr_reader :name
|
46
|
+
|
47
|
+
# The download URL of the wordlist.
|
48
|
+
#
|
49
|
+
# @return [String]
|
50
|
+
attr_reader :url
|
51
|
+
|
52
|
+
# A brief summary of the wordlist.
|
53
|
+
#
|
54
|
+
# @return [String]
|
55
|
+
attr_reader :summary
|
56
|
+
|
57
|
+
# The categories the wordlist belongs to.
|
58
|
+
#
|
59
|
+
# @return [Set<String>]
|
60
|
+
attr_reader :categories
|
61
|
+
|
62
|
+
#
|
63
|
+
# Initializes the entry object.
|
64
|
+
#
|
65
|
+
# @param [String] name
|
66
|
+
# The name of the wordlist.
|
67
|
+
#
|
68
|
+
# @param [String] url
|
69
|
+
# The download URL of the wordlist.
|
70
|
+
#
|
71
|
+
# @param [String] summary
|
72
|
+
# A brief summary of the wordlist.
|
73
|
+
#
|
74
|
+
# @param [Array<String>] categories
|
75
|
+
# The categories the wordlist belongs to.
|
76
|
+
#
|
77
|
+
def initialize(name, url: , summary: , categories: [])
|
78
|
+
@name = name
|
79
|
+
@url = url
|
80
|
+
|
81
|
+
@summary = summary
|
82
|
+
@categories = categories.to_set
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
# The entries in the wordlist index.
|
88
|
+
#
|
89
|
+
# @return [Hash{String => Entry}]
|
90
|
+
attr_reader :entries
|
91
|
+
|
92
|
+
#
|
93
|
+
# Initializes the wordlist index.
|
94
|
+
#
|
95
|
+
# @param [Hash{String => Entry}] entries
|
96
|
+
# The entries for the wordlist index.
|
97
|
+
#
|
98
|
+
def initialize(entries)
|
99
|
+
@entries = entries
|
100
|
+
end
|
101
|
+
|
102
|
+
#
|
103
|
+
# Indicates that the wordlist index file has an invalid schema.
|
104
|
+
#
|
105
|
+
class InvalidSchema < Wordlists::Exception
|
106
|
+
end
|
107
|
+
|
108
|
+
# Path to the builtin `wordlists.yml` index file.
|
109
|
+
PATH = File.join(ROOT,'data','wordlists.yml')
|
110
|
+
|
111
|
+
#
|
112
|
+
# Loads the wordlist index file from the given path.
|
113
|
+
#
|
114
|
+
# @param [String] path
|
115
|
+
# The path of the wordlit index file.
|
116
|
+
#
|
117
|
+
# @return [WordlistIndex]
|
118
|
+
# The parsed wordlist index file.
|
119
|
+
#
|
120
|
+
# @raise [InvalidSchema]
|
121
|
+
# The wordlist index file has an invalid schema.
|
122
|
+
#
|
123
|
+
def self.load(path=PATH)
|
124
|
+
yaml = YAML.load_file(path)
|
125
|
+
|
126
|
+
unless yaml.kind_of?(Hash)
|
127
|
+
raise(InvalidSchema,"wordlist index file does not contain a Hash: #{path.inspect}")
|
128
|
+
end
|
129
|
+
|
130
|
+
entries = yaml.to_h do |name,attributes|
|
131
|
+
unless attributes[:url]
|
132
|
+
raise(InvalidSchema,"wordlist index entry does not have a URL: #{name.inspect}")
|
133
|
+
end
|
134
|
+
|
135
|
+
unless attributes[:summary]
|
136
|
+
raise(InvalidSchema,"wordlist index entry does not have a summary: #{name.inspect}")
|
137
|
+
end
|
138
|
+
|
139
|
+
[name, Entry.new(name,**attributes)]
|
140
|
+
end
|
141
|
+
|
142
|
+
return new(entries)
|
143
|
+
end
|
144
|
+
|
145
|
+
#
|
146
|
+
# Looks up the wordlist by name within the wordlist index.
|
147
|
+
#
|
148
|
+
# @param [String] name
|
149
|
+
# The wordlist name.
|
150
|
+
#
|
151
|
+
# @return [Entry, nil]
|
152
|
+
# The entry for the wordlist.
|
153
|
+
#
|
154
|
+
def [](name)
|
155
|
+
@entries[name]
|
156
|
+
end
|
157
|
+
|
158
|
+
#
|
159
|
+
# Enumerates over every entry in the wordlist index.
|
160
|
+
#
|
161
|
+
# @yield [entry]
|
162
|
+
# If a block is given, it will be passed every entry in the wordlist
|
163
|
+
# index.
|
164
|
+
#
|
165
|
+
# @yieldparam [Entry] entry
|
166
|
+
# An entry in the wordlist index.
|
167
|
+
#
|
168
|
+
# @return [Enumerator]
|
169
|
+
# If no block is given, an Enumerator object will be returned instead.
|
170
|
+
#
|
171
|
+
def each(&block)
|
172
|
+
@entries.each_value(&block)
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-wordlists - A library and tool for managing wordlists.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-wordlists 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-wordlists 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-wordlists. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'ronin/wordlists'
|
22
|
+
|
23
|
+
module Ronin
|
24
|
+
module Wordlists
|
25
|
+
class CLI
|
26
|
+
#
|
27
|
+
# Adds the `-W,--wordlist {NAME | PATH}` option to a command that includes
|
28
|
+
# {WordlistOption}.
|
29
|
+
#
|
30
|
+
# @api public
|
31
|
+
#
|
32
|
+
module WordlistOption
|
33
|
+
#
|
34
|
+
# Adds the `-W,--wordlist {NAME | PATH}` option to the command including
|
35
|
+
# {WordlistOption}.
|
36
|
+
#
|
37
|
+
# @param [Class<Command>] command
|
38
|
+
# The command class including {WordlistOption}.
|
39
|
+
#
|
40
|
+
# @api private
|
41
|
+
#
|
42
|
+
def self.included(command)
|
43
|
+
command.option :wordlist, short: '-W',
|
44
|
+
value: {
|
45
|
+
type: String,
|
46
|
+
usage: '{NAME | PATH}'
|
47
|
+
},
|
48
|
+
desc: 'The wordlist name or file' do |path_or_name|
|
49
|
+
@wordlist = if File.file?(path_or_name)
|
50
|
+
Wordlist.open(path_or_name)
|
51
|
+
else
|
52
|
+
Wordlists.open(path_or_name)
|
53
|
+
end
|
54
|
+
rescue WordlistNotFound => error
|
55
|
+
raise(OptionParser::InvalidArgument,"unknown wordlist: #{error.message}")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# The opened wordlist file.
|
60
|
+
#
|
61
|
+
# @return [::Wordlist, nil]
|
62
|
+
attr_reader :wordlist
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-wordlists - A library and tool for managing wordlists.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-wordlists 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-wordlists 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-wordlists. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'ronin/wordlists/version'
|
22
|
+
require 'ronin/core/cli/help/banner'
|
23
|
+
|
24
|
+
require 'command_kit/commands'
|
25
|
+
require 'command_kit/commands/auto_load'
|
26
|
+
require 'command_kit/options/version'
|
27
|
+
|
28
|
+
module Ronin
|
29
|
+
module Wordlists
|
30
|
+
#
|
31
|
+
# The `ronin-wordlists` command-line interface (CLI).
|
32
|
+
#
|
33
|
+
# @api private
|
34
|
+
#
|
35
|
+
class CLI
|
36
|
+
|
37
|
+
include CommandKit::Commands
|
38
|
+
include CommandKit::Commands::AutoLoad.new(
|
39
|
+
dir: "#{__dir__}/cli/commands",
|
40
|
+
namespace: "#{self}::Commands"
|
41
|
+
)
|
42
|
+
include CommandKit::Options::Version
|
43
|
+
include Core::CLI::Help::Banner
|
44
|
+
|
45
|
+
command_name 'ronin-wordlists'
|
46
|
+
version Ronin::Wordlists::VERSION
|
47
|
+
|
48
|
+
command_aliases['install'] = 'download'
|
49
|
+
|
50
|
+
command_aliases['ls'] = 'list'
|
51
|
+
command_aliases['up'] = 'update'
|
52
|
+
command_aliases['rm'] = 'remove'
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-wordlists - A library and tool for managing wordlists.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-wordlists 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-wordlists 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-wordlists. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
module Ronin
|
22
|
+
module Wordlists
|
23
|
+
#
|
24
|
+
# Base class for all `ronin-wordlists` exceptions.
|
25
|
+
#
|
26
|
+
class Exception < RuntimeError
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# Indicates that a download of a wordlist failed.
|
31
|
+
#
|
32
|
+
class DownloadFailed < Wordlists::Exception
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# Indicates that a requests wordlist does not exist.
|
37
|
+
#
|
38
|
+
class WordlistNotFound < Wordlists::Exception
|
39
|
+
end
|
40
|
+
|
41
|
+
#
|
42
|
+
# Indicates that the `manifest.yml` file is invalid or is missing data.
|
43
|
+
#
|
44
|
+
class InvalidManifestFile < Wordlists::Exception
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-wordlists - A library and tool for managing wordlists.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-wordlists 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-wordlists 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-wordlists. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'ronin/wordlists'
|
22
|
+
|
23
|
+
module Ronin
|
24
|
+
module Wordlists
|
25
|
+
#
|
26
|
+
# Wordlist helper methods.
|
27
|
+
#
|
28
|
+
module Mixin
|
29
|
+
#
|
30
|
+
# Downloads a new wordlist.
|
31
|
+
#
|
32
|
+
# @param [String, URI::HTTP] url
|
33
|
+
# The URL of the wordlist to download.
|
34
|
+
#
|
35
|
+
# @api public
|
36
|
+
#
|
37
|
+
# @see Wordlists.download
|
38
|
+
#
|
39
|
+
def wordlists_download(url)
|
40
|
+
Wordlists.download(url)
|
41
|
+
end
|
42
|
+
|
43
|
+
alias download_wordlist wordlists_download
|
44
|
+
|
45
|
+
#
|
46
|
+
# Finds a wordlist.
|
47
|
+
#
|
48
|
+
# @param [String] name
|
49
|
+
# The wordlist file name.
|
50
|
+
#
|
51
|
+
# @return [String, nil]
|
52
|
+
# The path to the wordlist file.
|
53
|
+
#
|
54
|
+
# @api public
|
55
|
+
#
|
56
|
+
# @see Wordlists.find
|
57
|
+
#
|
58
|
+
def wordlists_find(name)
|
59
|
+
Wordlists.find(name)
|
60
|
+
end
|
61
|
+
|
62
|
+
alias find_wordlist wordlists_find
|
63
|
+
|
64
|
+
#
|
65
|
+
# Lists all wordlists on the system.
|
66
|
+
#
|
67
|
+
# @param [String] pattern
|
68
|
+
# Optional glob pattern to search for within the wordlist directory.
|
69
|
+
#
|
70
|
+
# @return [Set<String>]
|
71
|
+
# The wordlist files within the wordlist directories.
|
72
|
+
#
|
73
|
+
# @api public
|
74
|
+
#
|
75
|
+
# @see Wordlists.list
|
76
|
+
#
|
77
|
+
def wordlists_list(pattern='*')
|
78
|
+
Wordlists.list(pattern)
|
79
|
+
end
|
80
|
+
|
81
|
+
alias list_wordlists wordlists_list
|
82
|
+
|
83
|
+
#
|
84
|
+
# Opens a wordlist.
|
85
|
+
#
|
86
|
+
# @param [String] name
|
87
|
+
# The wordlist file name.
|
88
|
+
#
|
89
|
+
# @return [Wordlist::File]
|
90
|
+
# The opened wordlist file.
|
91
|
+
#
|
92
|
+
# @raise [WordlistNotFound]
|
93
|
+
# No wordlist with the given name.
|
94
|
+
#
|
95
|
+
# @api public
|
96
|
+
#
|
97
|
+
# @see Wordlists.open
|
98
|
+
#
|
99
|
+
def wordlists_open(name)
|
100
|
+
Wordlists.open(name)
|
101
|
+
end
|
102
|
+
|
103
|
+
alias open_wordlist wordlists_open
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-wordlists - A library and tool for managing wordlists.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-wordlists 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-wordlists 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-wordlists. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
module Ronin
|
22
|
+
module Wordlists
|
23
|
+
# Path to `ronin-wordlists` root directory.
|
24
|
+
#
|
25
|
+
# @api private
|
26
|
+
ROOT = File.expand_path(File.join(__dir__,'..','..','..'))
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-wordlists - A library and tool for managing wordlists.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-wordlists 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-wordlists 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-wordlists. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'ronin/wordlists/wordlist_dir'
|
22
|
+
|
23
|
+
require 'set'
|
24
|
+
|
25
|
+
module Ronin
|
26
|
+
module Wordlists
|
27
|
+
#
|
28
|
+
# Represents the wordlist directories to search for wordlists within.
|
29
|
+
#
|
30
|
+
# @api private
|
31
|
+
#
|
32
|
+
class SearchPaths
|
33
|
+
|
34
|
+
include Enumerable
|
35
|
+
|
36
|
+
# The paths of the wordlist directories.
|
37
|
+
#
|
38
|
+
# @return [Array<WordlistDir>]
|
39
|
+
attr_reader :paths
|
40
|
+
|
41
|
+
#
|
42
|
+
# Initializes the wordlist search paths.
|
43
|
+
#
|
44
|
+
# @param [Array<String>] paths
|
45
|
+
# The paths to the wordlist directories to search.
|
46
|
+
#
|
47
|
+
def initialize(paths=[])
|
48
|
+
@paths = []
|
49
|
+
|
50
|
+
paths.each do |path|
|
51
|
+
self << path
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# Initializes the wordlist search paths.
|
57
|
+
#
|
58
|
+
# @param [Array<String>] paths
|
59
|
+
# The paths to the wordlist directories to search.
|
60
|
+
#
|
61
|
+
# @return [SearchPaths]
|
62
|
+
# The wordlist search paths.
|
63
|
+
#
|
64
|
+
def self.[](*paths)
|
65
|
+
new(paths)
|
66
|
+
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# Enumerates over each wordlist directory within the search paths.
|
70
|
+
#
|
71
|
+
# @yield [wordlist_dir]
|
72
|
+
# If a block is given, each wordlist directory will be yielded.
|
73
|
+
#
|
74
|
+
# @yieldparam [WordlistDir] wordlist_dir
|
75
|
+
# A wordlist directory within the search paths.
|
76
|
+
#
|
77
|
+
# @return [Enumerator]
|
78
|
+
# If no block is given, an Enumerator will be returned.
|
79
|
+
#
|
80
|
+
def each(&block)
|
81
|
+
@paths.each(&block)
|
82
|
+
end
|
83
|
+
|
84
|
+
#
|
85
|
+
# Adds a new wordlist directory to the search paths.
|
86
|
+
#
|
87
|
+
# @param [String] new_dir
|
88
|
+
# A new wordlist directory to add to the search directories.
|
89
|
+
#
|
90
|
+
# @return [self]
|
91
|
+
#
|
92
|
+
def <<(new_dir)
|
93
|
+
@paths.unshift(WordlistDir.new(new_dir))
|
94
|
+
return self
|
95
|
+
end
|
96
|
+
|
97
|
+
#
|
98
|
+
# Finds a wordlist within one of the wordlist directories.
|
99
|
+
#
|
100
|
+
# @param [String] name
|
101
|
+
# The wordlist file name.
|
102
|
+
#
|
103
|
+
# @return [String, nil]
|
104
|
+
# The path to the wordlist or `nil` if the wordlist could not be found.
|
105
|
+
#
|
106
|
+
def find(name)
|
107
|
+
@paths.each do |wordlist_dir|
|
108
|
+
if (wordlist_path = wordlist_dir.find(name))
|
109
|
+
return wordlist_path
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
return nil
|
114
|
+
end
|
115
|
+
|
116
|
+
#
|
117
|
+
# Lists all wordlists in the wordlist directories.
|
118
|
+
#
|
119
|
+
# @param [String] name
|
120
|
+
# Optional file name to search for.
|
121
|
+
#
|
122
|
+
# @return [Set<String>]
|
123
|
+
# The wordlist files within the wordlist directories.
|
124
|
+
#
|
125
|
+
def list(name='*')
|
126
|
+
each_with_object(Set.new) do |wordlist_dir,files|
|
127
|
+
files.merge(wordlist_dir.list(name))
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
#
|
132
|
+
# Opens a wordlist from one of the wordlist directories.
|
133
|
+
#
|
134
|
+
# @param [String] name
|
135
|
+
# The wordlist file name.
|
136
|
+
#
|
137
|
+
# @return [Wordlist::File]
|
138
|
+
# The opened wordlist file.
|
139
|
+
#
|
140
|
+
# @raise [WordlistNotFound]
|
141
|
+
# No wordlist with the given name.
|
142
|
+
#
|
143
|
+
def open(name)
|
144
|
+
if (path = find(name))
|
145
|
+
Wordlist.open(path)
|
146
|
+
else
|
147
|
+
raise(WordlistNotFound,"wordlist not found: #{name.inspect}")
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-wordlists - A library and tool for managing wordlists.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-wordlists 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-wordlists 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-wordlists. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
module Ronin
|
22
|
+
module Wordlists
|
23
|
+
# ronin-wordlists version
|
24
|
+
VERSION = '0.1.0.rc1'
|
25
|
+
end
|
26
|
+
end
|