puddly / android-otp-extractor

Extracts OTP tokens from rooted Android devices
GNU General Public License v3.0
231 stars 22 forks source link

Usage without system-wide ADB #11

Closed Madis0 closed 6 years ago

Madis0 commented 6 years ago

I am using:

Here's how I tried to use this script:

  1. Got ADB from Google (guess I could've gotten it through some AUR package but didn't want to try them all)
  2. Got this script .py file
  3. Unpacked both
  4. Ran ./adb devices in it's directory to make sure it connects to the phone
  5. Ran python extract_otp_tokens.py to see what happens, obviously FileNotFoundError: [Errno 2] No such file or directory: 'adb': 'adb'
  6. Moved adb to same folder as the script, replaced 'adb' with './adb' in the script to make it work
  7. Ran python extract_otp_tokens.py, accepted root permission on phone
  8. Got a bit confused due to lack of output, so ran python extract_otp_tokens.py --show-qr
  9. file:///tmp/tmp... opened in (where ... is a random ending string) browser with title "OTP QR Codes" and no content (source is valid HTML though)
  10. Tried python extract_otp_tokens.py --andotp-backup ANDOTP_BACKUP which produced file ANDOTP_BACKUP with contents []

The succeeded commands had the following log in terminal:

Listing directory /data/data
Reading file /data/data/com.authy.authy/shared_prefs/com.authy.storage.tokens.authenticator.xml
Reading file /data/data/com.authy.authy/shared_prefs/com.authy.storage.tokens.authy.xml
Reading file /data/data/com.duosecurity.duomobile/files/duokit/accounts.json
Reading file /data/data/org.fedorahosted.freeotp/shared_prefs/tokens.xml
Reading file /data/data/com.google.android.apps.authenticator2/databases/databases
Reading file /data/data/com.azure.authenticator/databases/PhoneFactor
Listing directory /data/data/com.valvesoftware.android.steam.community/files

Any ideas?

puddly commented 6 years ago

The location of adb should make no difference. Do any XML files exist in /data/data/com.authy.authy/shared_prefs/?

Madis0 commented 6 years ago

Yes, there are several of them.

puddly commented 6 years ago

Does running adb shell 'su -c "toybox base64 /data/data/com.authy.authy/shared_prefs/com.authy.storage.tokens.authenticator.xml"' | base64 --decode successfully read the file?

Madis0 commented 6 years ago

It writes the file to terminal, though it seems to be unescaped HTML-style, lots of "s.

puddly commented 6 years ago

That's expected, but it's strange that no accounts are being parsed from the file. I can't reproduce this issue on any of my devices with the latest version of Authy installed.

Can check to see how far read_authy_accounts actually progresses before breaking? Does adb_read_file actually produce a valid BytesIO object or does it throw an error? Is the accounts variable properly populated? You can just litter the function with print calls to see what happens.

Madis0 commented 6 years ago

Not experienced with Python, so did indeed try print statements. Apparently neither of the Authy files are found by the script.

puddly commented 6 years ago

The exact command that is run is:

adb shell 'su -c "toybox base64 /data/data/com.authy.authy/shared_prefs/com.authy.storage.tokens.authenticator.xml /3bb22bb739c29e435151cb38"'

The output should look like:

lotsofbase64lotsofbase64
lotsofbase64lotsofbase64
lotsofbase64lotsofbase64
lotsofbase64=
base64: /3bb22bb739c29e435151cb38: No such file or directory

Is this what you see? Are you using just a stock Android 8.1 ROM? If so, I will try emulating it to see if something changed.

Madis0 commented 6 years ago

I see the same indeed. I am using a custom ROM called OmniROM with it's 24 Jul patch for OnePlus 5T.

puddly commented 6 years ago

I think I see the problem. You only replaced the first instance of adb in the script with ./adb. There are four instances. A proper solution would be to fix your PATH to temporarily include the current folder so adb refers to the right binary:

PATH=.:$PATH python extract_otp_tokens.py
Madis0 commented 6 years ago

That finally worked. Thank you!