#!/usr/bin/env python #-*-coding: utf-8 -*- """ Licence : --------- Fernandez Lucas aka kasey This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ---- Source : * http://www.bigtrapeze.com/md5/source.php """ import urllib2, cookielib, urllib, hashlib import re, sys from random import choice class GoogleHash: hash = "" type = "" hash_t = {'md5':32,'sha1':40} h = re s = re def __init__(self): self.h = re.compile(r'<.*?>') self.s = re.compile(r'\s+') def remove_html_tags(self,data): return self.s.sub(' ',self.h.sub(' ',data)) def find_hash(self,hash,type="md5"): self.hash = hash self.type = type # Sanity checks if not type in self.hash_t: return (-1, "type de hash inconnu") if len(hash) != self.hash_t[self.type]: return (-2, "le hash ne semble pas correspondre au type demandé") # Web grabber init cookiejar = cookielib.CookieJar() urlOpener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar)) useragent = {'User-Agent':'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9a8) Gecko/2007100619 GranParadiso/3.0a8'} # do the google request request = urllib2.Request('http://www.google.com/search?q=%s' % self.hash, None, useragent) # grab and clean the result url = urlOpener.open(request) data = self.remove_html_tags(url.read()) # check hashtype for each word find in the google answer for word in re.findall(r'\w+',data): if len(word) <= self.hash_t[self.type]: if hashlib.md5(word).hexdigest() == self.hash: return (0, self.hash, word) # if any word match the password is not found return (-3, "hash %s not found" % self.hash) if __name__ == "__main__": h = GoogleHash() if len(sys.argv) != 2 or len(sys.argv[1]) != 32: print "Usage : gAPI.py " quit() print h.find_hash(sys.argv[1])