Posts Extracting TOTP code from Microsoft Authenticator (root required)
Post
Cancel

Extracting TOTP code from Microsoft Authenticator (root required)

Preview Image

Introduction

I wanted to flash my android phone that would mean that I will lose my OTP codes for my email because Microsoft Authenticator does not support local backups. I searched around the internet but no one has published anything helpful. So this mini post is for anyone having the same problem.

Requirements

  • The device should be rooted
  • A password manager that supports OTP (Desktop, Android)
  • SQLite3

The Process

Getting the TOTP from the device

First we need to get the OTP token from the device. We need access /data/data/com.azure.authenticator/ that is not accessible by the default user, that is why we need a rooted device. I will use termux to access that folder.

1
2
3
4
~$ sudo su -
:/data/data/com.termux/files/home # bash
home # cp /data/data/com.azure.authenticator/databases/PhoneFactor /storage/PhoneFactor
home # chmod 777 /storage/PhoneFactor

Now you can copy the file to the workstation that has SQLite3.

Extracting the OTP from the SQLite3 database

The file that we got is an SQLite3 database that stores the OTP tokens among other things. Now we can extract the required information using SQLite3.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
┌─[sarange@parrot]─[~]
└──╼ $sudo apt install sqlite3
[sudo] password for sarange:
Reading package lists... Done
Building dependency tree
Reading state information... Done
sqlite3 is already the newest version (3.27.2-3+deb10u1).
0 upgraded, 0 newly installed, 0 to remove and 40 not upgraded.
┌─[sarange@parrot]─[~]
└──╼ $sudo apt install sqlite3
┌─[sarange@parrot]─[~]
└──╼ $sqlite3 PhoneFactor
SQLite version 3.27.2 2019-02-25 16:06:06
Enter ".help" for usage hints.
sqlite> sqlite> select username, oath_secret_key from accounts;
***username 1***|***otp token 1***
***username 2***|***otp token 2***
...

We got the username and the OTP token for the accounts that where in the authenticator. The only thing that remains now is to import them into our preferred OTP manager.

This post is licensed under CC BY 4.0 by the author.