yield custom_wordlist words
parent
8ada0804bd
commit
a00ff5aeef
|
@ -77,6 +77,39 @@ module Metasploit
|
|||
end
|
||||
end
|
||||
|
||||
def each_word
|
||||
# Make sure are attributes are all valid first!
|
||||
valid!
|
||||
|
||||
# Yield the expanded form of each line of the custom wordlist if one was given
|
||||
if custom_wordlist.present?
|
||||
::File.open(custom_wordlist, "rb") do |fd|
|
||||
fd.each_line do |line|
|
||||
expanded_words(line) do |word|
|
||||
yield word
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
# This method takes a string and splits it on non-word characters
|
||||
# and the underscore. It does this to find likely distinct words
|
||||
# in the string. It then yields each 'word' found this way.
|
||||
#
|
||||
# @param word [String] the string to split apart
|
||||
# @yieldparam expanded [String] the expanded words
|
||||
# @return [void]
|
||||
def expanded_words(word='')
|
||||
word.split(/[\W_]+/).each do |expanded|
|
||||
yield expanded
|
||||
end
|
||||
end
|
||||
|
||||
# Raise an exception if the attributes are not valid.
|
||||
#
|
||||
# @raise [Invalid] if the attributes are not valid on this scanner
|
||||
|
|
|
@ -5,8 +5,8 @@ describe Metasploit::Framework::JtR::Wordlist do
|
|||
|
||||
subject(:wordlist) { described_class.new }
|
||||
|
||||
let(:custom_wordlist) { '/path/to/custom_wordlist' }
|
||||
|
||||
let(:custom_wordlist) { File.expand_path('string_list.txt',FILE_FIXTURES_PATH) }
|
||||
let(:expansion_word) { 'Foo bar_baz-bat.bam\\foo//bar' }
|
||||
|
||||
it { should respond_to :appenders }
|
||||
it { should respond_to :custom_wordlist }
|
||||
|
@ -64,4 +64,23 @@ describe Metasploit::Framework::JtR::Wordlist do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#expanded_words' do
|
||||
it 'yields all the possible component words in the string' do
|
||||
expect { |b| wordlist.expanded_words(expansion_word,&b) }.to yield_successive_args('Foo','bar','baz','bat','bam','foo','bar')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#each_word' do
|
||||
before(:each) do
|
||||
expect(wordlist).to receive(:valid!)
|
||||
end
|
||||
context 'when given a custom wordlist' do
|
||||
it 'yields each word in that wordlist' do
|
||||
wordlist.custom_wordlist = custom_wordlist
|
||||
expect{ |b| wordlist.each_word(&b) }.to yield_successive_args('foo', 'bar','baz')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
Loading…
Reference in New Issue