Skip to content

Instantly share code, notes, and snippets.

@rxx
Forked from jbinto/howto-recover-google-authenticator-keys.txt
Last active February 2, 2018 19:47
Show Gist options
  • Save rxx/f7ff365527694a938336e187dae7ec03 to your computer and use it in GitHub Desktop.
Save rxx/f7ff365527694a938336e187dae7ec03 to your computer and use it in GitHub Desktop.
Recovering Google Authenticator keys from Android device for backup
import qrcode
import sqlite3
conn = sqlite3.connect('databases')
c = conn.cursor()
for idx, (email, secret, issuer) in enumerate(c.execute("SELECT email,secret,issuer FROM accounts").fetchall()):
url = 'otpauth://totp/{}?secret={}&issuer={}'.format(email, secret, issuer)
print url
im = qrcode.make(url)
im.save('{}.png'.format(idx))
### Device with Google Authenticator must have root.
### Computer requires Android Developer Tools and python with sqlite3 and qrcode
### Connect your device in USB debugging mode.
# Original solution with `adb root` does not work for me
$ cd /tmp
$ adb shell
# Now you're on the phone
$ su # and do any auth action your root requires
$ cp /data/data/com.google.android.apps.authenticator2/databases/databases /sdcard/Download/
$ exit
$ exit
# Now you're back on the computer
$ adb pull /sdcard/Download/databases
# Remove databases from public folder
$ adb shell
$ rm /sdcard/Download/databases
$ python gen_qrcode.py
### You can see generated qr images in the current folder. Scan them in Google Authenticator when you are ready
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment