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