jtr wordlist validations started
start adding validations and exceptions for the JtR Wordlist class.bug/bundler_fix
parent
19231b7c8f
commit
466576d03f
|
@ -0,0 +1,20 @@
|
|||
module Metasploit
|
||||
module Framework
|
||||
module JtR
|
||||
|
||||
# This class is the generic Exception raised by a {Wordlist} when
|
||||
# it fails validation. It rolls up all validation errors into a
|
||||
# single exception so that all errors can be dealt with at once.
|
||||
class InvalidWordlist < StandardError
|
||||
attr_reader :model
|
||||
|
||||
def initialize(model)
|
||||
@model = model
|
||||
|
||||
errors = @model.errors.full_messages.join(', ')
|
||||
super(errors)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -6,16 +6,78 @@ module Metasploit
|
|||
class Wordlist
|
||||
include ActiveModel::Validations
|
||||
|
||||
# @!attribute appenders
|
||||
# @return [Array] an array of strings to append to each word
|
||||
attr_accessor :appenders
|
||||
|
||||
# @!attribute custom_wordlist
|
||||
# @return [String] the path to a custom wordlist file to include
|
||||
attr_accessor :custom_wordlist
|
||||
|
||||
# @!attribute mutate
|
||||
# @return [TrueClass] if you want each word mutated as it is added
|
||||
# @return [FalseClass] if you do not want each word mutated
|
||||
attr_accessor :mutate
|
||||
|
||||
# @!attribute prependers
|
||||
# @return [Array] an array of strings to prepend to each word
|
||||
attr_accessor :prependers
|
||||
|
||||
# @!attribute use_common_root
|
||||
# @return [TrueClass] if you want to use the common root words wordlist
|
||||
# @return [FalseClass] if you do not want to use the common root words wordlist
|
||||
attr_accessor :use_common_root
|
||||
|
||||
# @!attribute use_creds
|
||||
# @return [TrueClass] if you want to seed the wordlist with existing credential data from the database
|
||||
# @return [FalseClass] if you do not want to seed the wordlist with existing credential data from the database
|
||||
attr_accessor :use_creds
|
||||
|
||||
# @!attribute use_db_info
|
||||
# @return [TrueClass] if you want to seed the wordlist with looted database names and schemas
|
||||
# @return [FalseClass] if you do not want to seed the wordlist with looted database names and schemas
|
||||
attr_accessor :use_db_info
|
||||
|
||||
# @!attribute use_default_wordlist
|
||||
# @return [TrueClass] if you want to use the default wordlist
|
||||
# @return [FalseClass] if you do not want to use the default wordlist
|
||||
attr_accessor :use_default_wordlist
|
||||
|
||||
# @!attribute use_hostnames
|
||||
# @return [TrueClass] if you want to seed the wordlist with existing hostnames from the database
|
||||
# @return [FalseClass] if you do not want to seed the wordlist with existing hostnames from the database
|
||||
attr_accessor :use_hostnames
|
||||
|
||||
validates :mutate,
|
||||
inclusion: { in: [true, false] }
|
||||
|
||||
validates :use_common_root,
|
||||
inclusion: { in: [true, false] }
|
||||
|
||||
validates :use_creds,
|
||||
inclusion: { in: [true, false] }
|
||||
|
||||
validates :use_db_info,
|
||||
inclusion: { in: [true, false] }
|
||||
|
||||
validates :use_default_wordlist,
|
||||
inclusion: { in: [true, false] }
|
||||
|
||||
validates :use_hostnames,
|
||||
inclusion: { in: [true, false] }
|
||||
|
||||
|
||||
# Raise an exception if the attributes are not valid.
|
||||
#
|
||||
# @raise [Invalid] if the attributes are not valid on this scanner
|
||||
# @return [void]
|
||||
def valid!
|
||||
unless valid?
|
||||
raise Metasploit::Framework::JtR::InvalidWordlist.new(self)
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
require 'spec_helper'
|
||||
require 'metasploit/framework/jtr/invalid_wordlist'
|
||||
|
||||
describe Metasploit::Framework::JtR::InvalidWordlist do
|
||||
|
||||
subject(:invalid) do
|
||||
described_class.new(model)
|
||||
end
|
||||
|
||||
let(:model) do
|
||||
model_class.new
|
||||
end
|
||||
|
||||
let(:model_class) do
|
||||
Class.new do
|
||||
include ActiveModel::Validations
|
||||
end
|
||||
end
|
||||
|
||||
it { should be_a StandardError }
|
||||
|
||||
it 'should use ActiveModel::Errors#full_messages' do
|
||||
model.errors.should_receive(:full_messages).and_call_original
|
||||
|
||||
described_class.new(model)
|
||||
end
|
||||
|
||||
context '#model' do
|
||||
subject(:error_model) do
|
||||
invalid.model
|
||||
end
|
||||
|
||||
it 'should be the passed in model' do
|
||||
error_model.should == model
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue