juuso/BozoCrack — Issue #9: sha1 hashes
Author: digininja
Created: 2011-12-16 22:09:32+00:00
State: open

I've not got round to working out how to use git to handle pulls so here is a diff to add SHA1 hashes and scanning of Bing and Yahoo as well:

diff --git a/bozocrack.rb b/bozocrack.rb
old mode 100644
new mode 100755
index 5a4bd6f..fe06b92
--- a/bozocrack.rb
+++ b/bozocrack.rb
@@ -1,16 +1,38 @@
+#!/usr/bin/env ruby
+
require 'digest/md5'
+require 'digest/sha1'
require 'net/http'

class BozoCrack
+ attr :hash_type

- def initialize(filename)
+ def initialize(filename, hash_type='md5')
@hashes = Array.new
@cache = Hash.new

+ @hash_type = hash_type
+ case @hash_type
+ when "md5"
+ puts "Looking for MD5 hashes"
+ when "sha1"
+ puts "Looking for SHA1 hashes"
+ else
+ puts "Unknown hash type specified - " + @hash_type
+ exit
+ end
+
File.new(filename).each_line do |line|
- if m = line.chomp.match(/\b([a-fA-F0-9]{32})\b/)
- @hashes << m[1]
- end
+ case @hash_type
+ when "md5"
+ if m = line.chomp.match(/\b([a-fA-F0-9]{32})\b/)
+ @hashes << m[1]
+ end
+ when "sha1"
+ if m = line.chomp.match(/\b([a-fA-F0-9]{40})\b/)
+ @hashes << m[1]
+ end
+ end
end
@hashes.uniq!
puts "Loaded #{@hashes.count} unique hashes"
@@ -40,14 +62,31 @@ class BozoCrack
if plaintext = dictionary_attack(hash, wordlist)
return plaintext
end
+ response = Net::HTTP.get URI("http://search.yahoo.com/search?p=#{hash}")
+ wordlist = response.split(/\s+/)
+ if plaintext = dictionary_attack(hash, wordlist)
+ return plaintext
+ end
+ response = Net::HTTP.get URI("http://www.bing.com/search?q=#{hash}")
+ wordlist = response.split(/\s+/)
+ if plaintext = dictionary_attack(hash, wordlist)
+ return plaintext
+ end
nil
end

def dictionary_attack(hash, wordlist)
wordlist.each do |word|
- if Digest::MD5.hexdigest(word) == hash.downcase
- return word
- end
+ case @hash_type
+ when "md5"
+ if Digest::MD5.hexdigest(word) == hash.downcase
+ return word
+ end
+ when "sha1"
+ if Digest::SHA1.hexdigest(word) == hash.downcase
+ return word
+ end
+ end
end
nil
end
@@ -72,6 +111,8 @@ end

if ARGV.size == 1
BozoCrack.new(ARGV[0]).crack
+elsif ARGV.size == 2
+ BozoCrack.new(ARGV[1], ARGV[0]).crack
else
- puts "Usage example: ruby bozocrack.rb file_with_md5_hashes.txt"
-end
\ No newline at end of file
+ puts "Usage example: ruby bozocrack.rb file_with_md5_hashes.txt"
+end