Class: Ronin::Wordlists::WordlistDir
- Inherits:
-
Object
- Object
- Ronin::Wordlists::WordlistDir
- Defined in:
- lib/ronin/wordlists/wordlist_dir.rb
Overview
Represents a directory of wordlists.
Example
wordlist_dir = Wordlists::WordlistDir.new('/path/to/wordlists')
wordlist_dir.find('passwords.txt')
# => "/path/to/wordlists/passwords.txt"
wordlist_dir.find('passwords')
# => "/path/to/wordlists/passwords.txt"
wordlist_dir.open('passwords.txt')
# => #<Wordlist::File:...>
wordlist_dir.open('passwords')
# => #<Wordlist::File:...>
Instance Attribute Summary collapse
-
#path ⇒ String
readonly
The path to the wordlist directory.
Instance Method Summary collapse
-
#delete(name) ⇒ Object
Deletes a wordlist file from the wordlist directory.
-
#download(url) ⇒ WordlistFile, WordlistRepo
Downloads a wordlist from the given URL into the wordlist directory.
-
#each {|path| ... } ⇒ Enumerator
Enumerates over every wordlist in the wordlist directory.
-
#find(name) ⇒ String?
Looks up a wordlist within the wordlist directory.
-
#initialize(path) ⇒ WordlistDir
constructor
Initializes the wordlist directory.
-
#list(name = '*') ⇒ Array<String>
Lists the wordlists in the wordlist directory.
-
#open(name) ⇒ Wordlist::File
Opens a wordlist from the wordlist directory.
Constructor Details
#initialize(path) ⇒ WordlistDir
Initializes the wordlist directory.
59 60 61 |
# File 'lib/ronin/wordlists/wordlist_dir.rb', line 59 def initialize(path) @path = path end |
Instance Attribute Details
#path ⇒ String (readonly)
The path to the wordlist directory.
51 52 53 |
# File 'lib/ronin/wordlists/wordlist_dir.rb', line 51 def path @path end |
Instance Method Details
#delete(name) ⇒ Object
Deletes a wordlist file from the wordlist directory.
182 183 184 185 186 187 188 189 190 |
# File 'lib/ronin/wordlists/wordlist_dir.rb', line 182 def delete(name) if (path = find(name)) File.unlink(path) return path else raise(WordlistNotFound,"unknown wordlist: #{name.inspect}") end end |
#download(url) ⇒ WordlistFile, WordlistRepo
Downloads a wordlist from the given URL into the wordlist directory.
160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/ronin/wordlists/wordlist_dir.rb', line 160 def download(url) uri = URI(url) wordlist_class = if uri.scheme == 'git' || uri.path.end_with?('.git') WordlistRepo else WordlistFile end FileUtils.mkdir_p(@path) return wordlist_class.download(url,@path) end |
#each {|path| ... } ⇒ Enumerator
Enumerates over every wordlist in the wordlist directory.
75 76 77 78 79 |
# File 'lib/ronin/wordlists/wordlist_dir.rb', line 75 def each(&block) return enum_for unless block Dir.glob(File.join(@path,'**','*.{txt,gz,bz2,xz}'),&block) end |
#find(name) ⇒ String?
Looks up a wordlist within the wordlist directory.
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/ronin/wordlists/wordlist_dir.rb', line 96 def find(name) path = File.join(@path,name) # check for an exact filename match first if File.file?(path) path else # fallback to search for the wordlist file by name Dir.glob(File.join(@path,'**',"#{name}.{txt,gz,bz2,xz}")).first end end |
#list(name = '*') ⇒ Array<String>
Lists the wordlists in the wordlist directory.
117 118 119 |
# File 'lib/ronin/wordlists/wordlist_dir.rb', line 117 def list(name='*') Dir.glob("{**/}#{name}.{txt,gz,bz2,xz}", base: @path) end |
#open(name) ⇒ Wordlist::File
Opens a wordlist from the wordlist directory.
139 140 141 142 143 144 145 |
# File 'lib/ronin/wordlists/wordlist_dir.rb', line 139 def open(name) if (path = find(name)) Wordlist.open(path) else raise(WordlistNotFound,"wordlist not found: #{name.inspect}") end end |