Skip to content

Instantly share code, notes, and snippets.

@rapimo
Created May 8, 2012 07:19
Show Gist options
  • Save rapimo/2633267 to your computer and use it in GitHub Desktop.
Save rapimo/2633267 to your computer and use it in GitHub Desktop.
crackme solution in ruby
require "benchmark"
class Cracker
class << self
## runs the code retuning sek runtime
def run(test)
Benchmark.realtime{`./crackme #{test}`}
end
# asuming the key is shorter then 100 chars
def get_size
1000.times do |i|
test = 'a'*i
time = run(test)
if time > 0.1
return i
end
end
end
def chars
('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a
end
# we now have an array an check against each position to get the last (size -1) characters
def get_first(pass)
time = run(pass.join(''))
(pass.size-1).downto(1) do |i|
(chars.size).times do |j|
pass[i] = chars[j]
t = run(pass.join(''))
if t > (time + 0.08)
time = t
break
end
end
end
return pass[1..-1].join('')
end
# only one (the first char is left)
def get_full_pass(first_part)
chars.each do |char|
test=char+first_part
res = `./crackme #{test}`
unless res.match(/Wrong/)
return test
end
end
'could not find any password'
end
def give_me_da_fucking_password
size = get_size
seed = ['-'] * size
first = get_first(seed)
get_full_pass(first)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment