Workplaces may enforce TOTP 2FA to be enabled Office 365 accounts, which require the Microsoft Authenticator app to be installed.
Regular TOTP applications (such as Aegis, Authy, or LastPass) cannot be used as Microsoft uses a proprietary scheme called phonefactor. Furthermore, the application requires Google Services Framework (GSF) to be installed (likely to provide device notifications), and will refuse to work when it is not present on the device.
Forunately, after the registration is complete, the underlying mechanism the app uses to generate TOTP codes is regular otpauth, and its secrets can be exported with a little bit of effort.
-
To extract the keys, a complete registration must first be done with a rooted Android device. I used a virtual Android device created with Android Studio's Device Manager.
-
Once complete, an SQLite database storing the keys can be found on the device at:
/data/data/com.azure.authenticator/databases/PhoneFactor(accessing the
/datapartition is what requires root) -
ADB can then be used to connect to the device/emulator, using its bundled
sqlite3tool to view the database:$ adb root # Ensure we run as the root user $ adb shell # Launch a shell as the root user emu64xa:/ # whoami root emu64xa:/ # sqlite3 /data/data/com.azure.authenticator/databases/PhoneFactor # Connect to the database file sqlite> SELECT name, username, oath_secret_key from accounts; GitHub|Chowder@github.com|w0swofa8wl02vqml0pkbzphvp54zyx5xThe 32-length string in the
oath_secret_keycolumn can then be imported into any TOTP application.
My two cents:
BlueStacks & WSL instead of Android Studio & rootAVD (no rooting required)
In case you already have BlueStacks & WSL installed (IMHO much more likely than Android Studio 🙂) you can do this instead to extract the PhoneFactor database:
Now using WSL (default ubuntu distro) to mount the android instances rootfs and read the data via sqlite3:
Note that autocompletion for sqlite database path does not work for two reasons: (1) folder com.azure.authenticator is owned by a user unknown to WSL and has restrictive permissions and (2) file PhoneFactor does not end in
.dbso sqlite3's bash autocompletion pattern doesn't match.You should now see accounts.csv
Microsoft account base64 eight digit code
As mentioned in @ChrisIdema's comment, Microsoft's own account uses an eight digit TOTP that is stored not as base32 but base64 and can be converted using python:
Passwordmanagers with only a textbox for the TOTP secret might accept an URI like this to specify, that it is an 8 digit code:
I specifically know that this works for Bitwarden/Vaultwarden.