4 # :title: rbot wordlist provider
6 # Author:: Raine Virta <rane@kapsi.fi>
13 def self.wordlist_base
14 @@wordlist_base ||= Utils.bot.path 'wordlists'
17 def self.get(where, options={})
18 opts = { :spaces => false }.merge(options)
20 wordlist_path = File.join(wordlist_base, where)
21 raise "wordlist not found: #{wordlist_path}" unless File.exist?(wordlist_path)
23 # Location is a directory -> combine all lists beneath it
24 wordlist = if File.directory?(wordlist_path)
26 Find.find(wordlist_path) do |path|
27 next if path == wordlist_path
28 wordlists << path unless File.directory?(path)
31 wordlists.map { |list| File.readlines(list) }.flatten
33 File.readlines(wordlist_path)
36 # wordlists are assumed to be UTF-8, but we need to strip the BOM, if present
37 wordlist.map! { |l| l.sub("\xef\xbb\xbf",'').strip }
38 wordlist.reject do |word|
39 word =~ /\s/ && !opts[:spaces] ||
44 # Return an array with the list of available wordlists.
46 # pattern:: pattern that should be matched by the wordlist filename
47 def self.list(options={})
48 pattern = options[:pattern] || "**"
49 # refuse patterns that contain ../
50 return [] if pattern =~ /\.\.\//
51 striplen = self.wordlist_base.length+1
52 Dir.glob(File.join(self.wordlist_base, pattern)).map { |name|
59 # refuse to check outside of the wordlist base directory
60 return false if fn =~ /\.\.\//
61 File.exist?(File.join(self.wordlist_base, fn))