@@ -57,15 +57,6 @@ def puts(o = '')
|
||||
super(o)
|
||||
end
|
||||
|
||||
class File
|
||||
# @param [ String ] file_path
|
||||
#
|
||||
# @return [ String ] The charset of the file
|
||||
def self.charset(file_path)
|
||||
%x{file --mime #{file_path}}[%r{charset=([^\n]+)\n}, 1]
|
||||
end
|
||||
end
|
||||
|
||||
module Terminal
|
||||
class Table
|
||||
def render
|
||||
|
||||
@@ -126,22 +126,15 @@ class WpUser < WpItem
|
||||
# Load the passwords from the wordlist, which can be a file path or
|
||||
# an array or passwords
|
||||
#
|
||||
# File comments are ignored, but will miss passwords if they start with a hash...
|
||||
#
|
||||
# @param [ String, Array<String> ] wordlist
|
||||
#
|
||||
# @return [ Array<String> ]
|
||||
def self.passwords_from_wordlist(wordlist)
|
||||
if wordlist.is_a?(String)
|
||||
passwords = []
|
||||
charset = File.charset(wordlist).upcase
|
||||
opt = "r:#{charset}"
|
||||
# To remove warning when charset = UTF-8
|
||||
# Ignoring internal encoding UTF-8: it is identical to external encoding utf-8
|
||||
opt += ':UTF-8' if charset != 'UTF-8'
|
||||
|
||||
File.open(wordlist, opt).each do |line|
|
||||
passwords << line.strip
|
||||
File.open(wordlist).each do |line|
|
||||
passwords << line.chop
|
||||
end
|
||||
elsif wordlist.is_a?(Array)
|
||||
passwords = wordlist
|
||||
|
||||
@@ -3,4 +3,5 @@ pa55w0rd
|
||||
#comment
|
||||
admin
|
||||
root
|
||||
spaceafterandbefore
|
||||
kansei<EFBFBD><EFBFBD>
|
||||
|
||||
@@ -3,4 +3,5 @@ pa55w0rd
|
||||
#comment
|
||||
admin
|
||||
root
|
||||
spaceafterandbefore
|
||||
kansei£Ô
|
||||
|
||||
@@ -9,7 +9,7 @@ shared_examples 'WpUser::BruteForcable' do
|
||||
before { Browser.instance.max_threads = 1 }
|
||||
|
||||
describe '::passwords_from_wordlist' do
|
||||
let(:expected) { %w{password1 pa55w0rd #comment admin root kansei£Ô} }
|
||||
let(:expected) { %w{password1 pa55w0rd #comment admin root} << ' spaceafterandbefore ' }
|
||||
let(:exception) { 'Invalid wordlist, expected String or Array' }
|
||||
|
||||
after do
|
||||
@@ -25,7 +25,7 @@ shared_examples 'WpUser::BruteForcable' do
|
||||
let(:wordlist) { wordlist_iso }
|
||||
|
||||
it 'returns the expected passwords' do
|
||||
@expected = expected
|
||||
@expected = expected << "kansei\xA3\xD4"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -33,7 +33,7 @@ shared_examples 'WpUser::BruteForcable' do
|
||||
let(:wordlist) { wordlist_utf8 }
|
||||
|
||||
it 'returns the expected passwords' do
|
||||
@expected = expected
|
||||
@expected = expected << 'kansei£Ô'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user