Skip to content

Instantly share code, notes, and snippets.

@joelthompson
Created December 6, 2016 04:14
Show Gist options
  • Save joelthompson/501d1201109c5f84b007468abf78e06c to your computer and use it in GitHub Desktop.
Save joelthompson/501d1201109c5f84b007468abf78e06c to your computer and use it in GitHub Desktop.
Recovery script to generate QR codes for Google Auth Accounts
#!/usr/bin/env python
#
# Note: First, pull the Google Auth database locally, which requires root access
# Then, run this, which assumes you have a databases file in the current directory
# It also assumes you have the qrencode package installed locally
import subprocess
import urllib
import sqlite3
conn = sqlite3.connect('databases')
c = conn.cursor()
urls = []
for r in c.execute('select email, secret, issuer from accounts'):
urls.append('otpauth://totp/' + urllib.quote(r[0]) + '?secret=' + urllib.quote(r[1]) + ('&issuer=' + urllib.quote(r[2]) if r[2] else ''))
for i in range(len(urls)):
subprocess.call(['qrencode', '-o', 'google-auth-%s.png' % i, '-d', '300', '-s', '10', urls[i]])
# This leaves a set of google-auth-NN.png files in your current directory, which you can scan and import as you normally would.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment