import requests import sqlite3 import re import sys DB_FILE = 'cb_enum.db' name_re = re.compile(r'meta content="(.*?) is accepting') hash_re = re.compile(r'/avatar/(.*?)\.png') # # Configure the database. # conn = sqlite3.connect(DB_FILE) cur = conn.cursor() cur.execute("CREATE TABLE IF NOT EXISTS users (username text, realname text, emailhash text, email text)") def save_user(user, name, hash): print user, name, hash name = unicode(name, 'utf-8') cur.execute('INSERT INTO users VALUES (?, ?, ?, ?)', (user, name, hash, None)) conn.commit() def get_user(user): try: resp = requests.get('https://www.coinbase.com/{0}'.format(user)) if resp.status_code != 404: return resp.content else: return None except requests.exceptions.RequestException as e: print '{0} - {1}'.format(user, str(e)) return None def main(filename): count = 1 for line in open(filename): user = line.rstrip('\r\n') data = get_user(user) if data is not None: name = name_re.search(data) hash = hash_re.search(data) if name is not None: save_user(user, name.group(1), hash.group(1)) if count % 100 == 0: print count count += 1 if __name__ == '__main__': try: if len(sys.argv) != 2: print 'USAGE: cb_enumerate.py usernames' sys.exit(1) main(sys.argv[1]) except KeyboardInterrupt: pass