Reputation: 15
I'm writing dictionary based attack program in ruby for a CTF, but my output prints an enumeration value instead of a string. I've tried explicingly converting the variable that ouputs to a string, but that did not change anything.
require 'net/http'
def checkUsage()
if ARGV.length != 1
return false
end
return true
end
def generateUsername()
wordArray = Array.new
wordlist = File.open("words.txt", "r")
for word in wordlist
wordArray.push(word)
end
return wordArray.repeated_permutation(7).to_s
end
def generatePassword()
wordArray = Array.new
wordlist = File.open("words.txt", "r")
for word in wordlist
wordArray.push(word)
end
return wordArray.repeated_permutation(7).to_s
end
def requestAuthentication()
if(!checkUsage())
puts("Usage: frsDic <wordlist>")
return false
end
uri = URI("http://challenges.laptophackingcoffee.org:3199/secret.php")
req = Net::HTTP::Get.new(uri)
loop do
username = generateUsername()
password = generatePassword()
if req.basic_auth username, password
puts"Username found: " + username
puts"Password found: " + password
break
else
puts"Username failed: " + username
puts"Password failed: " + password
end
end
end
requestAuthentication()
Output:
#<Enumerator:0x000055a491c74ad0>
#<Enumerator:0x000055a491c74828>
#<Enumerator:0x000055a491c74ad0>
#<Enumerator:0x000055a491c74828>
I was expecting to print out the string of the usernames/passwords found by the bruteforce, but it only printed enumeration values.
Upvotes: 0
Views: 90
Reputation: 1957
The method repeated_permutation
returns an Enumerator if you don't provide a block. If you're looking to loop through all of the permutations, you can either pass a block directly to it:
wordArray.repeated_permutation(7) { |permutation| puts permutation }
Or you can pass the enumerator somewhere and call .each
on it.
word_enumerator = wordArray.repeated_permutation(7)
word_enumerator.each { |permutation| puts permutation }
Upvotes: 1