Beispiel #1
0
def main():

    adb = ADB()

    # set ADB path
    adb.set_adb_path('~/android-sdk-linux/platform-tools/adb')

    print("[+] Using PyADB version %s" % adb.pyadb_version())

    # verity ADB path
    print("[+] Verifying ADB path...",)
    if adb.check_path() is False:
        print("ERROR")
        exit(-2)
    print("OK")

    # print(ADB Version)
    print("[+] ADB Version: %s" % adb.get_version())

    print("")

    # restart server (may be other instances running)
    print("[+] Restarting ADB server...")
    adb.restart_server()
    if adb.last_failed():
        print("\t- ERROR\n")
        exit(-3)

    # get detected devices
    dev = 0
    while dev is 0:
        print("[+] Detecting devices..." ,)
        error,devices = adb.get_devices()

        if error is 1:
            # no devices connected
            print("No devices connected")
            print("[+] Waiting for devices...")
            adb.wait_for_device()
            continue
        elif error is 2:
            print("You haven't enought permissions!")
            exit(-3)

        print("OK")
        dev = 1

    # this should never be reached
    if len(devices) == 0:
        print("[+] No devices detected!")
        exit(-4)

    # show detected devices
    i = 0
    for dev in devices:
        print("\t%d: %s" % (i,dev))
        i += 1

    # if there are more than one devices, ask to the user to choose one of them
    if i > 1:
        dev = i + 1
        while dev < 0 or dev > int(i - 1):
            print("\n[+] Select target device [0-%d]: " % int(i - 1) ,)
            dev = int(stdin.readline())
    else:
        dev = 0

    # set target device
    try:
        adb.set_target_device(devices[dev])
    except Exception as e:
        print("\n[!] Error:\t- ADB: %s\t - Python: %s" % (adb.get_error(),e.args))
        exit(-5)

    print("\n[+] Using \"%s\" as target device" % devices[dev])

    # check if 'su' binary is available
    print("[+] Looking for 'su' binary: ",)
    supath = adb.find_binary("su")

    if supath is not None:
        print("%s" % supath)
    else:
        print("Error: %s" % adb.get_error())

    # 'su' binary has been found
    if supath is not None:
        print("[+] Checking if 'su' binary can give root access:")
        rootid = adb.shell_command('%s -c id' % supath)
        if adb.last_failed() is False and 'root' in rootid.replace('(',')').split(')'): # it can provide root privileges
            print("\t- Yes")
            get_whatsapp_root(adb,supath)
        else: # only have normal-user
            print("\t- No: %s" % adb.get_error())
            get_whatsapp_nonroot(adb)
    else:
        get_whatsapp_nonroot(adb)

    exit(0)
Beispiel #2
0
def main():

    adb = ADB()

    # set ADB path
    adb.set_adb_path('~/android-sdk-linux/platform-tools/adb')

    print("[+] Using PyADB version %s" % adb.pyadb_version())

    # verity ADB path
    print("[+] Verifying ADB path...", )
    if adb.check_path() is False:
        print("ERROR")
        exit(-2)
    print("OK")

    # print(ADB Version)
    print("[+] ADB Version: %s" % adb.get_version())

    print("")

    # restart server (may be other instances running)
    print("[+] Restarting ADB server...")
    adb.restart_server()
    if adb.last_failed():
        print("\t- ERROR\n")
        exit(-3)

    # get detected devices
    dev = 0
    while dev is 0:
        print("[+] Detecting devices...", )
        error, devices = adb.get_devices()

        if error is 1:
            # no devices connected
            print("No devices connected")
            print("[+] Waiting for devices...")
            adb.wait_for_device()
            continue
        elif error is 2:
            print("You haven't enought permissions!")
            exit(-3)

        print("OK")
        dev = 1

    # this should never be reached
    if len(devices) == 0:
        print("[+] No devices detected!")
        exit(-4)

    # show detected devices
    i = 0
    for dev in devices:
        print("\t%d: %s" % (i, dev))
        i += 1

    # if there are more than one devices, ask to the user to choose one of them
    if i > 1:
        dev = i + 1
        while dev < 0 or dev > int(i - 1):
            print("\n[+] Select target device [0-%d]: " % int(i - 1), )
            dev = int(stdin.readline())
    else:
        dev = 0

    # set target device
    try:
        adb.set_target_device(devices[dev])
    except Exception as e:
        print("\n[!] Error:\t- ADB: %s\t - Python: %s" %
              (adb.get_error(), e.args))
        exit(-5)

    print("\n[+] Using \"%s\" as target device" % devices[dev])

    # check if 'su' binary is available
    print("[+] Looking for 'su' binary: ", )
    supath = adb.find_binary("su")

    if supath is not None:
        print("%s" % supath)
    else:
        print("Error: %s" % adb.get_error())

    # 'su' binary has been found
    if supath is not None:
        print("[+] Checking if 'su' binary can give root access:")
        rootid = adb.shell_command('%s -c id' % supath)
        if adb.last_failed() is False and 'root' in rootid.replace(
                '(', ')').split(')'):  # it can provide root privileges
            print("\t- Yes")
            get_whatsapp_root(adb, supath)
        else:  # only have normal-user
            print("\t- No: %s" % adb.get_error())
            get_whatsapp_nonroot(adb)
    else:
        get_whatsapp_nonroot(adb)

    exit(0)