import sqlite3 import sys import hashlib DB_FILE = 'cb_enum.db' # # Configure the database. # conn = sqlite3.connect(DB_FILE) cur = conn.cursor() def save_email(hash, email): print hash, email cur.execute('UPDATE users SET email=? WHERE emailhash=?', (email, hash)) conn.commit() def check_hash(hash): cur.execute('SELECT username FROM users WHERE emailhash=? AND email IS NULL', (hash,)) if cur.fetchone() is None: return False else: return True def main(user_file, domain_file): count = 1 for user in open(user_file): for dom in open(domain_file): email = '{0}@{1}'.format(user.rstrip('\r\n'), dom.rstrip('\r\n')) hash = hashlib.md5(email.lower()).hexdigest() if check_hash(hash) is True: save_email(hash, email) if count % 1000 == 0: print count count += 1 if __name__ == '__main__': try: if len(sys.argv) != 3: print 'USAGE: cb_findemail.py usernames domain_names' sys.exit(1) main(sys.argv[1], sys.argv[2]) except KeyboardInterrupt: pass