Skip to content

Instantly share code, notes, and snippets.

@LMolr
Created September 22, 2013 22:14
Show Gist options
  • Save LMolr/6664386 to your computer and use it in GitHub Desktop.
Save LMolr/6664386 to your computer and use it in GitHub Desktop.
[CSAW 2013] [reverse 300]: cracking aid script.
# use rubinius!
M = 0x100000000
RESULT = 0xEF2E3558
def poly(a)
ret = a.inject(1337) do |sum, c|
sum + (32 * sum) + c
end
ret
end
def calc(a)
poly(a) % M
end
def check(a)
res = calc(a)
#puts "a: #{a}, poly(a): #{poly(a)} calc(a): #{calc(a).to_s 16}"
if (res == RESULT)
puts "SUCCESS! a: #{a}, poly(a): #{poly(a)} calc(a): #{calc(a).to_s 16}"
puts a.map{ |n| n.chr }.join
elsif ((res - RESULT).abs < 0xFF)
#puts "close .. a: #{a}, poly(a): #{poly(a)} calc(a): #{calc(a).to_s 16}"
end
end
def str_enumerator(len)
#(91..128).to_a.repeated_permutation(len)
# this is harcoded with length 6
(96..96).each do |i1|
(115..115).each do |i2|
(97..97).each do |i3|
(86..86).each do |i4|
(31..128).each do |i5|
(31..128).each do |i6|
a = [i1,i2,i3,i4,i5,i6]
#puts a.inspect
yield a
end
end
end
end
end
end
end
# Script.
N_THREADS = ARGV[0].to_i
N_CHARS = ARGV[1].to_i
queue = Queue.new
threads = N_THREADS.times.collect do |thr_idx|
Thread.new do
$stderr.print '.'
# Worker Thread Task
begin
a = queue.pop
check(a)
end while true
end
end
#master = Thread.new do
# # Master Thread Task
$stderr.puts 'Start'
last = [0] * 2
str_enumerator(N_CHARS) do |s|
if last[0..2] != s[0..2]
last = s
$stderr.puts "#{last[0..2]} ..."
end
a = s.map(&:ord).to_a
queue << a
end
$stderr.puts 'End'
threads.each { |t| Thread.kill(t) }
# end
Signal.trap('SIGINT') do
threads.each { |t| t.kill }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment